Add flushing before sync to be sure the buffer is empty

This commit is contained in:
Schoumi 2017-08-08 16:09:08 +02:00
parent 9e50901664
commit 1c5c369ebf
3 ha cambiato i file con 15 aggiunte e 3 eliminazioni

Vedi File

@ -261,6 +261,7 @@ public class FlashFragment extends Fragment{
Button bt = v.findViewById(R.id.retry_isp_mode);
bt.setVisibility(View.VISIBLE);
flash_infoStr += getString(R.string.fail) + "\n";
flash_infoStr += getString(R.string.try_isp_again)+"\n";
flash_info.setText(flash_infoStr);
} else {
View v = getView();

Vedi File

@ -113,12 +113,13 @@ public class IspManager {
return true;
}
private void clearBuffer(int size) {
private int clearBuffer(int size) {
if (serialPort == null)
return;
return -1;
byte[] buf = new byte[size];
read(buf, size, 500);
int ret = read(buf, size, 1000);
return ret;
}
public String[] readUid() {
@ -299,8 +300,16 @@ public class IspManager {
private boolean synchronize(int crystal_freq) {
if (serialPort == null)
return false;
int cpt = 0;
while(clearBuffer(1000) > 0 && cpt < 20)
{
cpt++;
}
serialPort.purge(D2xxManager.FT_PURGE_RX);
serialPort.purge(D2xxManager.FT_PURGE_TX);
if(cpt == 20) {
return false;
}
byte[] buf;
if (serialPort.write(SYNC_START) != SYNC_START.length) {
return false;
@ -500,6 +509,7 @@ public class IspManager {
private int parseRetCode(byte[] data) {
String str = new String(data,0,2);
str.replace(" ","");
str = str.replace("\r", "");
str = str.replace("\n", "");
if (!str.matches("[0-9 -+]*")||str.isEmpty())

Vedi File

@ -88,6 +88,7 @@
<string name="download_binary">Download Binary</string>
<string name="informations">Informations</string>
<string name="no_device">No Device Pluggued, please plug one to be able to flash a binary on it.</string>
<string name="try_isp_again">Please try to reset your device in ISP Mode again</string>
<array name="uuencode_array">
<item>Yes</item>
<item>No</item>