set buffer and new kit logic
This commit is contained in:
@@ -43,4 +43,5 @@ fun UserData.toHemoCubeTestData() = HemoCubeTestData(
|
||||
birthYear = birthYear,
|
||||
userImageURL = userImageURL,
|
||||
testStatus = testStatus,
|
||||
location = location,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.example.hpostesting.presentation.hemocube
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.hardware.usb.UsbDevice
|
||||
import android.hardware.usb.UsbDeviceConnection
|
||||
@@ -13,11 +14,14 @@ import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.Constants
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.model.patient.DeviceData
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.example.hpostesting.presentation.KitScanActivity
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||
import com.example.hpostesting.presentation.utils.UIUtils
|
||||
@@ -35,19 +39,9 @@ class HemoCubeFragment : Fragment() {
|
||||
private val hemoCubeViewModel: HemoCubeViewModel by activityViewModels()
|
||||
private lateinit var sharedPreference: SharedPreferences
|
||||
private var isOnline = false
|
||||
private val ACTION_USB_PERMISSION = "com.example.usbpermission"
|
||||
private val TIMEOUT = 0
|
||||
|
||||
private var deviceData: DeviceData? = null
|
||||
|
||||
private val usbManager: UsbManager by lazy {
|
||||
requireContext().getSystemService(Context.USB_SERVICE) as UsbManager
|
||||
}
|
||||
|
||||
private var usbDevice: UsbDevice? = null
|
||||
private var usbConnection: UsbDeviceConnection? = null
|
||||
private var usbConnection1: UsbDeviceConnection? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View {
|
||||
@@ -76,7 +70,7 @@ class HemoCubeFragment : Fragment() {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
}
|
||||
|
||||
hemoCubeViewModel.getDeviceData("DEVICE1")
|
||||
hemoCubeViewModel.getDeviceData("DEVICE1") // TODO
|
||||
|
||||
// hemoCubeViewModel.getDeviceData(sharedPreference.getString(Constants.USER_ID, "").toString())
|
||||
|
||||
@@ -96,10 +90,6 @@ class HemoCubeFragment : Fragment() {
|
||||
}
|
||||
|
||||
if (checkBufferValue()) {
|
||||
// with(sharedPreference.edit()) {
|
||||
// putInt(Constants.BUFFER_VALUE_1, 2000)
|
||||
// apply()
|
||||
// }
|
||||
UIUtils.createAlertDialog(requireContext(),
|
||||
"WARNING",
|
||||
"Do you want to continue with existing buffer",
|
||||
@@ -139,6 +129,15 @@ class HemoCubeFragment : Fragment() {
|
||||
binding.btnBuffer.setOnClickListener {
|
||||
startBuffer()
|
||||
}
|
||||
|
||||
binding.btnKit.setOnClickListener() {
|
||||
with(sharedPreference.edit()) {
|
||||
putInt(Constants.KIT_COUNT, 1)
|
||||
apply()
|
||||
}
|
||||
val i = Intent(context, KitScanActivity::class.java)
|
||||
startActivity(i)
|
||||
}
|
||||
}
|
||||
|
||||
private fun listenToHemoCube() {
|
||||
@@ -166,7 +165,8 @@ class HemoCubeFragment : Fragment() {
|
||||
hemoCubeViewModel.progressBar.postValue(false)
|
||||
|
||||
if (resultData.contains("RESULT")) {
|
||||
// val response: String = "RESULT SN 18291 1937.23 2828.11 28211.20 121829.12"
|
||||
// DEVICE RESPONSE FORMAT: RESULT SN <DEVICE_SERIAL_NUMBER> <GREEN_BUFFER_INTENSITY> <BLUE_BUFFER_INTENSITY> <GREEN_SAMPLE_INTENSITY> <BLUE_SAMPLE_INTENSITY>
|
||||
// // For example, "RESULT SN 18291 1937.23 2828.11 28211.20 121829.12"
|
||||
val results = resultData.split("\n")
|
||||
val validStringFound = checkAndFindResults(results)
|
||||
if (!validStringFound.isNullOrEmpty()) {
|
||||
@@ -176,6 +176,7 @@ class HemoCubeFragment : Fragment() {
|
||||
val deviceSerialNo = result[2]
|
||||
val led1Buffer = result[3].toDoubleOrNull()
|
||||
val led2Buffer = result[4].toDoubleOrNull()
|
||||
// TODO: Check old buffer
|
||||
val led1Sample = result[5].toDoubleOrNull()
|
||||
val led2Sample = result[6].toDoubleOrNull()
|
||||
val led1Average = log10(led1Buffer?.div(led1Sample!!) ?: 0.0)
|
||||
@@ -191,6 +192,14 @@ class HemoCubeFragment : Fragment() {
|
||||
DataHolder.hemoCubeTestData?.deviceRatio = deviceRatio
|
||||
DataHolder.hemoCubeTestData?.calculatedRatio =
|
||||
calculateRatio(deviceRatio)
|
||||
|
||||
if (!checkBufferValue()) {
|
||||
with(sharedPreference.edit()) {
|
||||
putString(Constants.BUFFER_VALUE_1, led1Buffer.toString())
|
||||
putString(Constants.BUFFER_VALUE_2, led2Buffer.toString())
|
||||
apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
hemoCubeViewModel.progressBar.postValue(false)
|
||||
|
||||
@@ -69,7 +69,7 @@ class HemoCubeViewModel @Inject constructor(
|
||||
private fun addResultTestToDb() {
|
||||
testDetails?.deviceRatio = DataHolder.hemocubeResult
|
||||
testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()
|
||||
testDetails?.location = DataHolder.location
|
||||
testDetails?.location = DataHolder.hemoCubeTestData?.location
|
||||
testDetails?.testTime = SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss", Locale.getDefault()
|
||||
).format(Calendar.getInstance().time)
|
||||
|
||||
Reference in New Issue
Block a user