diff --git a/app/src/main/java/fr/mobdev/lpcprog/fragment/FlashFragment.java b/app/src/main/java/fr/mobdev/lpcprog/fragment/FlashFragment.java index 081ca1b..c4beff2 100644 --- a/app/src/main/java/fr/mobdev/lpcprog/fragment/FlashFragment.java +++ b/app/src/main/java/fr/mobdev/lpcprog/fragment/FlashFragment.java @@ -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(); diff --git a/app/src/main/java/fr/mobdev/lpcprog/managers/IspManager.java b/app/src/main/java/fr/mobdev/lpcprog/managers/IspManager.java index 711d25c..2dc5c5a 100644 --- a/app/src/main/java/fr/mobdev/lpcprog/managers/IspManager.java +++ b/app/src/main/java/fr/mobdev/lpcprog/managers/IspManager.java @@ -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()) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5f39764..14c2e1c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -88,6 +88,7 @@ Download Binary Informations No Device Pluggued, please plug one to be able to flash a binary on it. + Please try to reset your device in ISP Mode again Yes No