calibration calculation done

This commit is contained in:
smileomi18@gmail.com
2023-08-03 15:41:57 +05:30
parent 36799ea81e
commit 750fb67ff9
3 changed files with 38 additions and 32 deletions

View File

@@ -1,8 +1,15 @@
package com.example.hpostesting.data.model.patient
data class DeviceData (
val deviceId: String? = "",
val deviceType: String? = "",
val coefficients: List<Double>? = null,
val calibratedAt: String
import com.google.firebase.firestore.PropertyName
data class DeviceData(
@get:PropertyName("deviceId") @set:PropertyName("deviceId")
var deviceId: String = "",
@get:PropertyName("deviceType") @set:PropertyName("deviceType")
var deviceType: String = "",
@get:PropertyName("coefficients") @set:PropertyName("coefficients")
var coefficients: List<Double> = emptyList(),
@get:PropertyName("calibratedAt") @set:PropertyName("calibratedAt")
var calibratedAt: String = ""
)

View File

@@ -37,7 +37,7 @@ class HemoCubeFragment : Fragment() {
private val ACTION_USB_PERMISSION = "com.example.usbpermission"
private val TIMEOUT = 0
private var deviceData = listOf<DeviceData>()
private var deviceData: DeviceData? = null
private val usbManager: UsbManager by lazy {
requireContext().getSystemService(Context.USB_SERVICE) as UsbManager
@@ -72,11 +72,12 @@ class HemoCubeFragment : Fragment() {
binding.progressBar.visibility = View.GONE
}
hemoCubeViewModel.getDeviceData()
hemoCubeViewModel.getDeviceData("DEVICE1")
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
deviceData = it
Toast.makeText(requireContext(), calculateRatio(0.17).toString(), Toast.LENGTH_SHORT).show()
}
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
@@ -87,16 +88,16 @@ class HemoCubeFragment : Fragment() {
}
}
if (checkBufferValue()) {
TODO("Call S command")
//We have to store the buffer value like this
with(sharedPreference.edit()) {
putInt(Constants.BUFFER_VALUE, 2000)
apply()
}
} else {
TODO("Call B command")
}
// if (checkBufferValue()) {
// TODO("Call S command")
// //We have to store the buffer value like this
// with(sharedPreference.edit()) {
// putInt(Constants.BUFFER_VALUE, 2000)
// apply()
// }
// } else {
// TODO("Call B command")
// }
}
private fun checkBufferValue(): Boolean {
@@ -311,4 +312,12 @@ class HemoCubeFragment : Fragment() {
}
})
}
private fun calculateRatio(ratio: Double): Double {
// val c1 = deviceData?.coefficients?.get(0)!!
// val c2 = deviceData?.coefficients?.get(1)!!
val c1 = deviceData?.coefficients?.get(0)!!
val c2 = deviceData?.coefficients?.get(1)!!
return c1 * ratio - c2
}
}

View File

@@ -1,5 +1,6 @@
package com.example.hpostesting.presentation.hemocube
import android.annotation.SuppressLint
import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
@@ -34,8 +35,7 @@ class HemoCubeViewModel @Inject constructor(
// Get the device ID of the device you want to retrieve data for (e.g., the first device in the list)
private val _networkStatusLiveData = NetworkStatusLiveData(context)
val deviceData = MutableLiveData<List<DeviceData>>()
val deviceIdToRetrieve = deviceData.value?.firstOrNull()?.deviceId
val deviceData = MutableLiveData<DeviceData?>()
val networkStatusLiveData: LiveData<Boolean>
get() = _networkStatusLiveData
val fireBaseUpload = MutableLiveData<String>()
@@ -68,20 +68,10 @@ class HemoCubeViewModel @Inject constructor(
}
}
fun getDeviceData() = viewModelScope.launch {
deviceIdToRetrieve?.let { deviceId ->
val deviceIdinfo = repository.getDeviceDataById(deviceId)
deviceData.postValue(listOf(deviceIdinfo!!))
}
fun getDeviceData(deviceId: String) = viewModelScope.launch {
deviceData.postValue(repository.getDeviceDataById(deviceId))
}
private fun addResultTestToDb() {
testDetails?.deviceRatio = DataHolder.hemocubeResult
testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()