Add flushing before sync to be sure the buffer is empty
This commit is contained in:
parent
9e50901664
commit
1c5c369ebf
3 changed files with 15 additions and 3 deletions
|
@ -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();
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue