Merge remote-tracking branch 'origin/preprod' into preprod
# Conflicts: # app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt
This commit is contained in:
@@ -69,5 +69,7 @@ object Constants {
|
|||||||
const val KIT_COUNT = "KitCount"
|
const val KIT_COUNT = "KitCount"
|
||||||
const val BUFFER_VALUE_1 = "BufferValue1"
|
const val BUFFER_VALUE_1 = "BufferValue1"
|
||||||
const val BUFFER_VALUE_2 = "BufferValue2"
|
const val BUFFER_VALUE_2 = "BufferValue2"
|
||||||
|
const val BUFFER_VALUE_3 = "BufferValue3"
|
||||||
|
const val BUFFER_VALUE_4 = "BufferValue4"
|
||||||
const val DEVICE_ID = "DEVICE_ID"
|
const val DEVICE_ID = "DEVICE_ID"
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,7 @@ import com.example.hpostesting.data.model.patient.DeviceData
|
|||||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||||
import com.example.hpostesting.presentation.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
import com.example.hpostesting.presentation.dashboard.DashboardActivity
|
||||||
|
import com.example.hpostesting.presentation.diagnostics.DiagnosticsActivity
|
||||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||||
import com.example.hpostesting.presentation.utils.UIUtils
|
import com.example.hpostesting.presentation.utils.UIUtils
|
||||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||||
@@ -41,7 +42,15 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private var isUsingExistingBuffer = false
|
private var isUsingExistingBuffer = false
|
||||||
private var isTestOngoing = false
|
private var isTestOngoing = false
|
||||||
private var startListening = MutableLiveData<Boolean>(false)
|
private var startListening = MutableLiveData<Boolean>(false)
|
||||||
val testingTrace = Firebase.performance.newTrace("testing_trace")
|
private val testingTrace = Firebase.performance.newTrace("testing_trace")
|
||||||
|
private var led1BufferForDevice = 0.0
|
||||||
|
private var led2BufferForDevice = 0.0
|
||||||
|
private var led3BufferForDevice = 0.0
|
||||||
|
private var led4BufferForDevice = 0.0
|
||||||
|
private var led1SampleForDevice = 0.0
|
||||||
|
private var led2SampleForDevice = 0.0
|
||||||
|
private var led3SampleForDevice = 0.0
|
||||||
|
private var led4SampleForDevice = 0.0
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?,
|
||||||
@@ -55,8 +64,9 @@ class HemoCubeFragment : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
initViews()
|
initViews()
|
||||||
|
listenToHemoCube()
|
||||||
|
getDeviceInfo()
|
||||||
observeViewModel()
|
observeViewModel()
|
||||||
// checkAndStartProcess()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initViews() {
|
private fun initViews() {
|
||||||
@@ -68,41 +78,37 @@ class HemoCubeFragment : Fragment() {
|
|||||||
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
isOnline, true, sharedPreferences.getString(Constants.KIT_NUMBER, "")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (isTestOngoing) {
|
|
||||||
// binding.btnKit.visibility = View.GONE
|
|
||||||
// binding.btnKit.isEnabled = false
|
|
||||||
// binding.btnKit.isClickable = false
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.tvTitle2.visibility = View.GONE
|
binding.tvTitle2.visibility = View.GONE
|
||||||
binding.etAbhaId.visibility = View.GONE
|
binding.etAbhaId.visibility = View.GONE
|
||||||
binding.nameEditText.visibility = View.GONE
|
binding.nameEditText.visibility = View.GONE
|
||||||
binding.tvTitle.visibility = View.GONE
|
binding.tvTitle.visibility = View.GONE
|
||||||
binding.btnGo.visibility = View.GONE
|
binding.btnGo.visibility = View.GONE
|
||||||
binding.btnSubmit.isEnabled = true
|
binding.btnSubmit.isEnabled = false
|
||||||
binding.btnSubmit.isClickable = true
|
binding.btnSubmit.isClickable = false
|
||||||
|
binding.btnPlacebuffer.visibility = View.GONE
|
||||||
|
|
||||||
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
binding.tvName.text = "Name: ${testDetails?.name}\n ID: ${testDetails?._id}"
|
||||||
Log.e("nametext", binding.tvName.text.toString())
|
binding.tvSubtitle4.text = "Config"
|
||||||
|
|
||||||
|
|
||||||
binding.btnSamplestart.setOnClickListener {
|
binding.btnSamplestart.setOnClickListener {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.tvSubtitle4.visibility = View.VISIBLE
|
binding.tvSubtitle4.visibility = View.VISIBLE
|
||||||
binding.tvSubtitle4.text = "Place Sample"
|
binding.tvSubtitle4.text = "Sample Started"
|
||||||
}
|
}
|
||||||
startSampleProcess()
|
startSampleProcess()
|
||||||
it.visibility = View.GONE
|
it.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.btnPlacebuffer.setOnClickListener {
|
binding.btnPlacebuffer.setOnClickListener {
|
||||||
if (isBufferValueAvailable()){
|
if (isBufferValueAvailable()) {
|
||||||
showBufferAlertDialog()
|
showBufferAlertDialog()
|
||||||
}else{
|
} else {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.tvSubtitle4.visibility = View.VISIBLE
|
binding.tvSubtitle4.visibility = View.VISIBLE
|
||||||
binding.tvSubtitle4.text = "Place Buffer"
|
// binding.tvSubtitle4.text = "Buffer Started"
|
||||||
}
|
}
|
||||||
|
|
||||||
checkAndStartProcess()
|
checkAndStartProcess()
|
||||||
it.visibility = View.GONE
|
it.visibility = View.GONE
|
||||||
}
|
}
|
||||||
@@ -155,40 +161,41 @@ class HemoCubeFragment : Fragment() {
|
|||||||
hemoCubeViewModel.messages.observe(viewLifecycleOwner) {
|
hemoCubeViewModel.messages.observe(viewLifecycleOwner) {
|
||||||
binding.tvSubtitle4.text = it
|
binding.tvSubtitle4.text = it
|
||||||
}
|
}
|
||||||
// startListening.observe(viewLifecycleOwner) {
|
|
||||||
// if (it) {
|
|
||||||
// lifecycleScope.launch {
|
|
||||||
// delay(1000)
|
|
||||||
// if (binding.tvSubtitle4.text.toString().isEmpty()) {
|
|
||||||
// (activity as HemocubeActivity).reconnectDevice()
|
|
||||||
// if (isBufferValueAvailable()) {
|
|
||||||
// showBufferAlertDialog()
|
|
||||||
// } else {
|
|
||||||
// listenToHemoCube()
|
|
||||||
// startBufferProcess()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkAndStartProcess() {
|
private fun checkAndStartProcess() {
|
||||||
listenToHemoCube()
|
|
||||||
startBufferProcess()
|
startBufferProcess()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isBufferValueAvailable(): Boolean {
|
private fun isBufferValueAvailable(): Boolean {
|
||||||
return if (sharedPreferences.getString(
|
return try {
|
||||||
|
if (sharedPreferences.getString(
|
||||||
Constants.BUFFER_VALUE_1, ""
|
Constants.BUFFER_VALUE_1, ""
|
||||||
) != "" && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "") != ""
|
) != "" && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "") != ""
|
||||||
|
&& sharedPreferences.getString(Constants.BUFFER_VALUE_3, "") != ""
|
||||||
|
&& sharedPreferences.getString(Constants.BUFFER_VALUE_4, "") != ""
|
||||||
) {
|
) {
|
||||||
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")
|
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")
|
||||||
?.toDouble()!! > 0.0 && sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")
|
?.toDouble()!! > 0.0 && sharedPreferences.getString(
|
||||||
|
Constants.BUFFER_VALUE_2,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
?.toDouble()!! > 0.0 && sharedPreferences.getString(
|
||||||
|
Constants.BUFFER_VALUE_3,
|
||||||
|
""
|
||||||
|
)
|
||||||
|
?.toDouble()!! > 0.0 && sharedPreferences.getString(
|
||||||
|
Constants.BUFFER_VALUE_4,
|
||||||
|
""
|
||||||
|
)
|
||||||
?.toDouble()!! > 0.0
|
?.toDouble()!! > 0.0
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
showToast("error while getting existing buffer")
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showBufferAlertDialog() {
|
private fun showBufferAlertDialog() {
|
||||||
@@ -204,13 +211,15 @@ class HemoCubeFragment : Fragment() {
|
|||||||
positiveText,
|
positiveText,
|
||||||
object : MyDialogListener {
|
object : MyDialogListener {
|
||||||
override fun onClickNegativeButton() {
|
override fun onClickNegativeButton() {
|
||||||
listenToHemoCube()
|
|
||||||
startBufferProcess()
|
startBufferProcess()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
override fun onClickPositiveButton() {
|
||||||
listenToHemoCube()
|
activity?.runOnUiThread {
|
||||||
startSampleProcess()
|
binding.btnPlacebuffer.visibility = View.GONE
|
||||||
|
binding.btnSamplestart.visibility = View.VISIBLE
|
||||||
|
binding.tvSubtitle4.text = "Place Sample"
|
||||||
|
}
|
||||||
isUsingExistingBuffer = true
|
isUsingExistingBuffer = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -246,58 +255,111 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getDeviceInfo() {
|
||||||
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(
|
||||||
|
HemoCubeCommands.getDeviceId,
|
||||||
|
object : UsbServiceListener {
|
||||||
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
|
data?.let {
|
||||||
|
val stringData = String(it)
|
||||||
|
hemoCubeViewModel.messages.postValue(stringData)
|
||||||
|
binding.tvSubtitle4.text = stringData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUsbError(e: Exception?) {
|
||||||
|
hemoCubeViewModel.progressBar.postValue(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleUsbData(stringData: String, fullReadOutput: StringBuilder) {
|
private fun handleUsbData(stringData: String, fullReadOutput: StringBuilder) {
|
||||||
if (stringData.contains("#")) {
|
if (stringData.contains("#")) {
|
||||||
hemoCubeViewModel.messages.postValue(stringData)
|
|
||||||
isTestOngoing = true
|
isTestOngoing = true
|
||||||
}
|
}
|
||||||
|
|
||||||
resultData += stringData
|
resultData += stringData
|
||||||
Log.e("nametext", stringData)
|
|
||||||
|
|
||||||
when {
|
when {
|
||||||
|
stringData.contains("SN") -> {
|
||||||
|
val slData = stringData.split(" ")
|
||||||
|
if (slData.size > 1) {
|
||||||
|
val hardwareId = slData[1].trim()
|
||||||
|
with(sharedPreferences.edit()) {
|
||||||
|
putString(Constants.DEVICE_ID, hardwareId)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
binding.btnPlacebuffer.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
hemoCubeViewModel.messages.postValue("Start Buffer")
|
||||||
|
}
|
||||||
|
|
||||||
|
stringData.contains("#BS") -> {
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
binding.tvSubtitle4.text = "Buffer Started"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stringData.contains("#BC") -> {
|
stringData.contains("#BC") -> {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
|
binding.tvSubtitle4.text = "Buffer Completed"
|
||||||
binding.btnSamplestart.visibility = View.VISIBLE
|
binding.btnSamplestart.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stringData.contains("#SC") -> {
|
|
||||||
|
stringData.contains("#SS") -> {
|
||||||
activity?.runOnUiThread {
|
activity?.runOnUiThread {
|
||||||
binding.btnSubmit.visibility = View.VISIBLE
|
binding.tvSubtitle4.text = "Sample Started"
|
||||||
|
binding.btnSamplestart.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stringData.contains("#SC") -> {
|
||||||
|
binding.tvSubtitle4.text = "Sample Completed"
|
||||||
fetchResult()
|
fetchResult()
|
||||||
testingTrace.stop()
|
testingTrace.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
stringData.contains("RESULT") || resultData.contains("REND") -> {
|
resultData.contains("REND") -> {
|
||||||
var validString: String
|
val resultLines = resultData.split("\\s+(?=LB|LS)".toRegex())
|
||||||
val results: List<String>
|
var bufferIntensity = resultLines[1].split(' ')[1].trim()
|
||||||
if (stringData.contains("RESULT")) {
|
led1BufferForDevice = if (isUsingExistingBuffer) {
|
||||||
validString = isValidResult(stringData)
|
sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()!!
|
||||||
if (validString.isEmpty()) {
|
|
||||||
results = resultData.split("\n")
|
|
||||||
validString = parseResult(results)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
results = resultData.split("\n")
|
bufferIntensity.toDoubleOrNull()!!
|
||||||
validString = parseResult(results)
|
|
||||||
}
|
}
|
||||||
if (validString.isNotEmpty()) {
|
bufferIntensity = resultLines[2].split(' ')[1].trim()
|
||||||
handleValidResult(validString, resultData)
|
led2BufferForDevice = if (isUsingExistingBuffer) {
|
||||||
}
|
sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()!!
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun isValidResult(line: String): String {
|
|
||||||
return if (line.contains("RESULT") && line.split(" ").size == 8) {
|
|
||||||
line
|
|
||||||
} else {
|
} else {
|
||||||
""
|
bufferIntensity.toDoubleOrNull()!!
|
||||||
|
}
|
||||||
|
bufferIntensity = resultLines[3].split(' ')[1].trim()
|
||||||
|
led3BufferForDevice = if (isUsingExistingBuffer) {
|
||||||
|
sharedPreferences.getString(Constants.BUFFER_VALUE_3, "")?.toDoubleOrNull()!!
|
||||||
|
} else {
|
||||||
|
bufferIntensity.toDoubleOrNull()!!
|
||||||
|
}
|
||||||
|
bufferIntensity = resultLines[4].split(' ')[1].trim()
|
||||||
|
led4BufferForDevice = if (isUsingExistingBuffer) {
|
||||||
|
sharedPreferences.getString(Constants.BUFFER_VALUE_4, "")?.toDoubleOrNull()!!
|
||||||
|
} else {
|
||||||
|
bufferIntensity.toDoubleOrNull()!!
|
||||||
|
}
|
||||||
|
|
||||||
|
var sampleIntensity = resultLines[5].split(' ')[1].trim()
|
||||||
|
led1SampleForDevice = resultLines[5].split(' ')[1].trim().toDoubleOrNull()!!
|
||||||
|
sampleIntensity = resultLines[6].split(' ')[1].trim()
|
||||||
|
led2SampleForDevice = resultLines[6].split(' ')[1].trim().toDoubleOrNull()!!
|
||||||
|
sampleIntensity = resultLines[7].split(' ')[1].trim()
|
||||||
|
led3SampleForDevice = resultLines[7].split(' ')[1].trim().toDoubleOrNull()!!
|
||||||
|
sampleIntensity = resultLines[8].split(' ')[1].split('\r')[0].trim()
|
||||||
|
led4SampleForDevice = resultLines[8].split(' ')[1].split('\r')[0].trim().toDoubleOrNull()!!
|
||||||
|
processResult()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,131 +392,56 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showStartSampleDialog() {
|
private fun processResult() {
|
||||||
activity?.runOnUiThread {
|
|
||||||
UIUtils.createAlertDialog(requireContext(),
|
|
||||||
"Start Sample",
|
|
||||||
"Do you want to start sample reading?",
|
|
||||||
getString(R.string.no),
|
|
||||||
"Yes",
|
|
||||||
object : MyDialogListener {
|
|
||||||
override fun onClickNegativeButton() {}
|
|
||||||
|
|
||||||
override fun onClickPositiveButton() {
|
|
||||||
listenToHemoCube()
|
|
||||||
startSampleProcess()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleValidResult(validString: String, fullReadOutput: String) {
|
|
||||||
try {
|
try {
|
||||||
val resultLines = validString.split("\n")
|
val deviceLog = resultData
|
||||||
// if (resultLines.size == 9) {
|
|
||||||
val deviceLog = fullReadOutput
|
|
||||||
// val led1BufferForDevice = if (isUsingExistingBuffer) {
|
|
||||||
// sharedPreferences.getString(Constants.BUFFER_VALUE_1, "")?.toDoubleOrNull()
|
|
||||||
// } else {
|
|
||||||
// resultLines.find { it.startsWith("LB1") }?.substring(4)
|
|
||||||
// ?.toDoubleOrNull()
|
|
||||||
// ?: 0.0
|
|
||||||
// }
|
|
||||||
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 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 led1BufferForDevice = resultLines.find { it.startsWith("LB1") }?.let {
|
|
||||||
// try {
|
|
||||||
// it.substring(4).toDoubleOrNull() ?: 0.0
|
|
||||||
// } catch (e: NumberFormatException) {
|
|
||||||
// // Handle invalid number format, log an error, or set a default value
|
|
||||||
// Log.e("Parsing Error", "Invalid format for LB1: $it")
|
|
||||||
// 0.0
|
|
||||||
// }
|
|
||||||
// } ?: 0.0
|
|
||||||
//
|
|
||||||
// val led2BufferForDevice = if (isUsingExistingBuffer) {
|
|
||||||
// sharedPreferences.getString(Constants.BUFFER_VALUE_2, "")?.toDoubleOrNull()
|
|
||||||
// } else {
|
|
||||||
// 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(
|
val pInfo = requireActivity().packageManager.getPackageInfo(
|
||||||
requireActivity().packageName, 0
|
requireActivity().packageName, 0
|
||||||
)
|
)
|
||||||
val version = pInfo.versionName
|
val version = pInfo.versionName
|
||||||
|
|
||||||
// val led1Sample = resultLines.find { it.startsWith("LS1") }?.substring(4)
|
val led1Average = log10(led1BufferForDevice?.div(led1SampleForDevice!!) ?: 0.0)
|
||||||
// ?.toDoubleOrNull()
|
val led2Average = log10(led2BufferForDevice?.div(led2SampleForDevice!!) ?: 0.0)
|
||||||
// ?: 0.0
|
val led3Average = log10(led3BufferForDevice?.div(led3SampleForDevice!!) ?: 0.0)
|
||||||
// val led2Sample = resultLines.find { it.startsWith("LS2") }?.substring(4)
|
val led4Average = log10(led4BufferForDevice?.div(led4SampleForDevice!!) ?: 0.0)
|
||||||
// ?.toDoubleOrNull()
|
val deviceRatio = led1Average / led3Average
|
||||||
// ?: 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 led3Average = log10(led3BufferForDevice?.div(led3Sample!!) ?: 0.0)
|
|
||||||
val deviceRatio = led1Average / led2Average
|
|
||||||
// if (led1BufferForDevice!! > 20000 && led1BufferForDevice < 24000 && led2BufferForDevice!! > 20000 && led2BufferForDevice < 24000) {
|
|
||||||
// if (led1Sample!! < led1BufferForDevice && led1Sample < 24000 && led2Sample!! < led2BufferForDevice && led2Sample < 24000) {
|
|
||||||
// if (deviceRatio < 0.08) {
|
|
||||||
// if (deviceRatio > 1.07) {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (led1Average < 0 || led2Average < 0) {
|
if (led1Average < 0 || led2Average < 0) {
|
||||||
activity?.runOnUiThread{
|
activity?.runOnUiThread {
|
||||||
binding.errorMessage.text = "Warning: Negative Abs. Retake Blank Reading"
|
binding.errorMessage.text = "Warning: Negative Abs. Retake Blank Reading"
|
||||||
binding.errorMessage.visibility = View.VISIBLE
|
binding.errorMessage.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DataHolder.hemoCubeTestData?.apply {
|
DataHolder.hemoCubeTestData?.apply {
|
||||||
// deviceId = deviceSerialNo
|
deviceId = sharedPreferences.getString(Constants.DEVICE_ID, "").toString()
|
||||||
led1Buffer = led1BufferForDevice
|
led1Buffer = led1BufferForDevice
|
||||||
led2Buffer = led2BufferForDevice
|
led2Buffer = led2BufferForDevice
|
||||||
led3Buffer = led3BufferForDevice
|
led3Buffer = led3BufferForDevice
|
||||||
led4Buffer = led4BufferForDevice
|
led4Buffer = led4BufferForDevice
|
||||||
appVersion = version
|
appVersion = version
|
||||||
this.led1Sample = led1Sample
|
this.led1Sample = led1SampleForDevice
|
||||||
this.led2Sample = led2Sample
|
this.led2Sample = led2SampleForDevice
|
||||||
this.led3Sample = led3Sample
|
this.led3Sample = led3SampleForDevice
|
||||||
this.led4Sample = led4Sample
|
this.led4Sample = led4SampleForDevice
|
||||||
this.led1Average = led1Average
|
this.led1Average = led1Average
|
||||||
this.led2Average = led2Average
|
this.led2Average = led2Average
|
||||||
|
this.led3Average = led3Average
|
||||||
|
this.led4Average = led4Average
|
||||||
this.deviceRatio = deviceRatio
|
this.deviceRatio = deviceRatio
|
||||||
this.calculatedRatio = calculateRatio(deviceRatio)
|
this.calculatedRatio = calculateRatio(deviceRatio)
|
||||||
this.coefficients = currentDeviceData?.coefficients?.get(0).toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
this.coefficients = currentDeviceData?.coefficients?.get(0)
|
||||||
|
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
|
||||||
this.classificationResult = findResult(calculatedRatio)
|
this.classificationResult = findResult(calculatedRatio)
|
||||||
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
hemoCubeViewModel.messages.postValue(this.classificationResult)
|
||||||
this.resultData = deviceLog
|
this.resultData = deviceLog
|
||||||
if (!isUsingExistingBuffer) {
|
if (!isUsingExistingBuffer) {
|
||||||
with(sharedPreferences.edit()) {
|
with(sharedPreferences.edit()) {
|
||||||
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
|
putString(Constants.BUFFER_VALUE_1, led1BufferForDevice.toString())
|
||||||
putString(Constants.BUFFER_VALUE_2, led2Buffer.toString())
|
putString(Constants.BUFFER_VALUE_2, led2BufferForDevice.toString())
|
||||||
|
putString(Constants.BUFFER_VALUE_3, led3BufferForDevice.toString())
|
||||||
|
putString(Constants.BUFFER_VALUE_4, led4BufferForDevice.toString())
|
||||||
apply()
|
apply()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -465,7 +452,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
|
binding.clParent.setBackgroundColor(Color.parseColor("#edfffd"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
requireContext(),
|
requireContext(),
|
||||||
@@ -511,6 +497,10 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private fun startBufferProcess() {
|
private fun startBufferProcess() {
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
binding.btnPlacebuffer.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
(activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
|
||||||
object : UsbServiceListener {
|
object : UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {}
|
override fun onUsbRead(data: ByteArray?) {}
|
||||||
@@ -554,23 +544,6 @@ class HemoCubeFragment : Fragment() {
|
|||||||
return coefficient1 * ratio + coefficient2
|
return coefficient1 * ratio + coefficient2
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseResult(frames: List<String>): String {
|
|
||||||
val lines = mutableListOf<String>()
|
|
||||||
for (frame in frames.reversed()) {
|
|
||||||
if (frame.contains("REND") || frame.contains("RESULT")) lines += frame
|
|
||||||
if (frame.contains("RESULT")) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val line = lines.reversed().joinToString("").trim()
|
|
||||||
if (line.contains("RESULT") && line.split(" ").size == 8) {
|
|
||||||
return line
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun checkDeviceIdMismatch(deviceId: String, loginId: String): Boolean {
|
private fun checkDeviceIdMismatch(deviceId: String, loginId: String): Boolean {
|
||||||
if (!deviceId.isNullOrEmpty() && !loginId.isNullOrEmpty() && deviceId.last() != loginId.last())
|
if (!deviceId.isNullOrEmpty() && !loginId.isNullOrEmpty() && deviceId.last() != loginId.last())
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user