diff --git a/app/src/main/java/com/example/hpos/presentation/testRight/TestRightExpReference.kt b/app/src/main/java/com/example/hpos/presentation/testRight/TestRightExpReference.kt index d013bf8..74698f7 100644 --- a/app/src/main/java/com/example/hpos/presentation/testRight/TestRightExpReference.kt +++ b/app/src/main/java/com/example/hpos/presentation/testRight/TestRightExpReference.kt @@ -265,7 +265,8 @@ class TestRightExpReference : Fragment() { // Log.d(TAG, stringData) // if (stringData.contains("OK", true)) { - if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) { +// if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) { + if (stringData.trim().isNotEmpty() && fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK [0]", true)) { Log.d(TAG, "onUsbRead() called in sendCmdToFetchLightIntensities()") // Log.d(TAG, fullReadOutput.toString()) diff --git a/app/src/main/java/com/example/hpos/presentation/testRight/TestRightExpSample.kt b/app/src/main/java/com/example/hpos/presentation/testRight/TestRightExpSample.kt index 77165b7..15da226 100644 --- a/app/src/main/java/com/example/hpos/presentation/testRight/TestRightExpSample.kt +++ b/app/src/main/java/com/example/hpos/presentation/testRight/TestRightExpSample.kt @@ -65,6 +65,9 @@ class TestRightExpSample : Fragment() { viewModel.errorTriggered.observe(viewLifecycleOwner) { if (it != null){ UIUtils.onShowErrorToast(requireContext(), it.message) + if (it.code == Constants.ERROR_CRITICAL){ + activity?.onBackPressed() + } } } @@ -138,7 +141,8 @@ class TestRightExpSample : Fragment() { Log.d(TAG, stringData) // if (stringData.contains("OK", true)) { // if (stringData.contains("OK", true) || fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) { - if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) { +// if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) { + if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK [0]", true)) { Log.d(TAG, "onUsbRead() called in sendCmdToRun()") Handler(Looper.getMainLooper()).postDelayed( Runnable { @@ -173,14 +177,21 @@ class TestRightExpSample : Fragment() { // if (stringData.contains("OK", true)) { // if (stringData.contains("OK", true) || stringData.contains("O", true) || stringData.contains("K", true)) { // if (stringData.contains("OK", true) || fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) { - if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) { +// if (fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK", true)) { + if (stringData.trim().isNotEmpty() && fullReadOutput.substring(Math.max(fullReadOutput.length - 15, 0)).contains("OK [0]", true)) { Log.d(TAG, "onUsbRead() called in sendCmdToFetchLightIntensities()") viewModel.mapIntensityValues(fullReadOutput.toString(), false) // viewModel.saveLogTest(requireContext().applicationContext, false, fullReadOutput.toString()) // showResultsAfterAcquiring() - checkIfToRunAgain() + Handler(Looper.getMainLooper()).postDelayed( + { + checkIfToRunAgain() + }, + Constants.DELAY_BETWEEN_COMMANDS + ) + } } } diff --git a/app/src/main/java/com/example/hpos/presentation/testRight/TestRightViewModel.kt b/app/src/main/java/com/example/hpos/presentation/testRight/TestRightViewModel.kt index d35304f..5765b94 100644 --- a/app/src/main/java/com/example/hpos/presentation/testRight/TestRightViewModel.kt +++ b/app/src/main/java/com/example/hpos/presentation/testRight/TestRightViewModel.kt @@ -153,7 +153,7 @@ class TestRightViewModel : ViewModel() { fun mapWavelengthToAbsorbance() { if (DataHolder.intensityReferenceArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != intensitySampleArray.size || DataHolder.wavelengthToPixelArray.size != DataHolder.intensityReferenceArray.size) { - errorTriggered.postValue(ErrorMessage("Error 205: Unable to fetch data from device, please try again by reopening the app", Constants.ERROR_NORMAL)) + errorTriggered.postValue(ErrorMessage("Error 205: Unable to fetch data from device, please try again by reopening the app", Constants.ERROR_CRITICAL)) throw Exception("Inconsistency in the data, size of arrays are not same. \nintensityReferenceArray.size = ${DataHolder.intensityReferenceArray.size} ; intensitySampleArray.size = ${intensitySampleArray.size} ; wavelengthToPixelArray.size = ${DataHolder.wavelengthToPixelArray.size}") }