new arduino code Result work for molbio is pending
This commit is contained in:
@@ -56,7 +56,7 @@ class HemoCubeFragment : Fragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
initViews()
|
||||
observeViewModel()
|
||||
checkAndStartProcess()
|
||||
// checkAndStartProcess()
|
||||
}
|
||||
|
||||
private fun initViews() {
|
||||
@@ -85,6 +85,29 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
||||
Log.e("nametext", binding.tvName.text.toString())
|
||||
|
||||
|
||||
binding.btnSamplestart.setOnClickListener {
|
||||
activity?.runOnUiThread {
|
||||
binding.tvSubtitle4.visibility = View.VISIBLE
|
||||
binding.tvSubtitle4.text = "Place Sample"
|
||||
}
|
||||
if(binding.tvSubtitle4.text.toString().contains("Place Sample") ){
|
||||
startSampleProcess()
|
||||
it.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnPlacebuffer.setOnClickListener {
|
||||
activity?.runOnUiThread {
|
||||
binding.tvSubtitle4.visibility = View.VISIBLE
|
||||
binding.tvSubtitle4.text = "Place Buffer"
|
||||
}
|
||||
checkAndStartProcess()
|
||||
it.visibility = View.GONE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun observeViewModel() {
|
||||
@@ -150,12 +173,8 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkAndStartProcess() {
|
||||
if (isBufferValueAvailable()) {
|
||||
showBufferAlertDialog()
|
||||
} else {
|
||||
listenToHemoCube()
|
||||
startBufferProcess()
|
||||
}
|
||||
listenToHemoCube()
|
||||
startBufferProcess()
|
||||
}
|
||||
|
||||
private fun isBufferValueAvailable(): Boolean {
|
||||
@@ -226,42 +245,6 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
// private fun handleUsbData(stringData: String, fullReadOutput: StringBuilder) {
|
||||
// if (stringData.contains("#")) {
|
||||
// hemoCubeViewModel.messages.postValue(stringData)
|
||||
// isTestOngoing = true
|
||||
// }
|
||||
//
|
||||
// resultData += stringData
|
||||
//
|
||||
// when {
|
||||
// stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
||||
// stringData.contains("#Sample Completed") -> {
|
||||
// fetchResult()
|
||||
// testingTrace.stop()
|
||||
// }
|
||||
//
|
||||
// stringData.contains("RESULT") || resultData.contains("REND") -> {
|
||||
// var validString: String
|
||||
// val results: List<String>
|
||||
// if (stringData.contains("RESULT")) {
|
||||
// validString = isValidResult(stringData)
|
||||
// if (validString.isEmpty()) {
|
||||
// results = resultData.split("\n")
|
||||
// validString = parseResult(results)
|
||||
// }
|
||||
// } else {
|
||||
// results = resultData.split("\n")
|
||||
// validString = parseResult(results)
|
||||
// }
|
||||
// if (validString.isNotEmpty()) {
|
||||
// handleValidResult(validString, resultData)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
private fun handleUsbData(stringData: String, fullReadOutput: StringBuilder) {
|
||||
if (stringData.contains("#")) {
|
||||
hemoCubeViewModel.messages.postValue(stringData)
|
||||
@@ -269,10 +252,15 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
resultData += stringData
|
||||
Log.e("nametext", stringData)
|
||||
|
||||
when {
|
||||
stringData.contains("#Buffer Completed") -> showStartSampleDialog()
|
||||
stringData.contains("#Sample Completed") -> {
|
||||
stringData.contains("#BC") -> {
|
||||
activity?.runOnUiThread {
|
||||
binding.btnSamplestart.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
stringData.contains("#SC") -> {
|
||||
fetchResult()
|
||||
testingTrace.stop()
|
||||
}
|
||||
@@ -291,16 +279,7 @@ class HemoCubeFragment : Fragment() {
|
||||
validString = parseResult(results)
|
||||
}
|
||||
if (validString.isNotEmpty()) {
|
||||
// Extract labels and corresponding values
|
||||
val resultLines = validString.split("\n")
|
||||
val formattedResult = StringBuilder()
|
||||
for (line in resultLines) {
|
||||
val parts = line.split(" ")
|
||||
if (parts.size == 2) {
|
||||
formattedResult.append("${parts[0]}\n${parts[1]}\n")
|
||||
}
|
||||
}
|
||||
handleValidResult(formattedResult.toString().trim(), resultData)
|
||||
handleValidResult(validString, resultData)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,7 +289,13 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
|
||||
|
||||
|
||||
private fun isValidResult(line: String): String {
|
||||
return if (line.contains("RESULT") && line.split(" ").size == 8) {
|
||||
line
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
private fun showError() {
|
||||
activity?.runOnUiThread {
|
||||
@@ -361,37 +346,40 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
private fun handleValidResult(validString: String, fullReadOutput: String) {
|
||||
try {
|
||||
val result = validString.split(" ")
|
||||
val deviceLog = resultData
|
||||
if (result.size == 8) {
|
||||
val deviceSerialNo = result[2]
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(Constants.DEVICE_ID, deviceSerialNo)
|
||||
apply()
|
||||
}
|
||||
val loginId = sharedPreferences.getString(Constants.USER_ID, "").toString()
|
||||
if (checkDeviceIdMismatch(deviceSerialNo, loginId)) {
|
||||
activity?.runOnUiThread {
|
||||
binding.errorMessage.text = "Warning: Login Id is different"
|
||||
binding.errorMessage.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
val led1BufferForDevice = if (isUsingExistingBuffer) {
|
||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
||||
} else {
|
||||
result[3].toDoubleOrNull()
|
||||
}
|
||||
val led2BufferForDevice = if (isUsingExistingBuffer) {
|
||||
sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()
|
||||
} else {
|
||||
result[4].toDoubleOrNull()
|
||||
}
|
||||
val resultLines = validString.split("\n")
|
||||
if (resultLines.size == 9) {
|
||||
val deviceLog = fullReadOutput
|
||||
val led1BufferForDevice = resultLines.find { it.startsWith("LB1") }?.substring(4)
|
||||
?.toDoubleOrNull()
|
||||
?: 0.0
|
||||
val led2BufferForDevice = resultLines.find { it.startsWith("LB2") }?.substring(4)
|
||||
?.toDoubleOrNull()
|
||||
?: 0.0
|
||||
val led3BufferForDevice = resultLines.find { it.startsWith("LB3") }?.substring(4)
|
||||
?.toDoubleOrNull()
|
||||
?: 0.0
|
||||
val led4BufferForDevice = resultLines.find { it.startsWith("LB4") }?.substring(4)
|
||||
?.toDoubleOrNull()
|
||||
?: 0.0
|
||||
|
||||
val pInfo = requireActivity().packageManager.getPackageInfo(
|
||||
requireActivity().packageName, 0
|
||||
)
|
||||
val version = pInfo.versionName
|
||||
val led1Sample = result[5].toDoubleOrNull()
|
||||
val led2Sample = result[6].toDoubleOrNull()
|
||||
|
||||
val led1Sample = resultLines.find { it.startsWith("LS1") }?.substring(4)
|
||||
?.toDoubleOrNull()
|
||||
?: 0.0
|
||||
val led2Sample = resultLines.find { it.startsWith("LS2") }?.substring(4)
|
||||
?.toDoubleOrNull()
|
||||
?: 0.0
|
||||
val led3Sample = resultLines.find { it.startsWith("LS3") }?.substring(4)
|
||||
?.toDoubleOrNull()
|
||||
?: 0.0
|
||||
val led4Sample = resultLines.find { it.startsWith("LS4") }?.substring(4)
|
||||
?.toDoubleOrNull()
|
||||
?: 0.0
|
||||
|
||||
val led1Average = log10(led1BufferForDevice?.div(led1Sample!!) ?: 0.0)
|
||||
val led2Average = log10(led2BufferForDevice?.div(led2Sample!!) ?: 0.0)
|
||||
val deviceRatio = led1Average / led2Average
|
||||
@@ -413,7 +401,7 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
DataHolder.hemoCubeTestData?.apply {
|
||||
deviceId = deviceSerialNo
|
||||
// deviceId = deviceSerialNo
|
||||
led1Buffer = led1BufferForDevice
|
||||
led2Buffer = led2BufferForDevice
|
||||
appVersion = version
|
||||
@@ -545,13 +533,7 @@ class HemoCubeFragment : Fragment() {
|
||||
return ""
|
||||
}
|
||||
|
||||
private fun isValidResult(line: String): String {
|
||||
return if (line.contains("RESULT") && line.split(" ").size == 8) {
|
||||
line
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun checkDeviceIdMismatch(deviceId: String, loginId: String): Boolean {
|
||||
if (!deviceId.isNullOrEmpty() && !loginId.isNullOrEmpty() && deviceId.last() != loginId.last())
|
||||
|
||||
Reference in New Issue
Block a user