calibration calculation done
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
package com.example.hpostesting.data.model.patient
|
package com.example.hpostesting.data.model.patient
|
||||||
|
|
||||||
data class DeviceData (
|
import com.google.firebase.firestore.PropertyName
|
||||||
val deviceId: String? = "",
|
|
||||||
val deviceType: String? = "",
|
|
||||||
val coefficients: List<Double>? = null,
|
data class DeviceData(
|
||||||
val calibratedAt: String
|
@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 = ""
|
||||||
)
|
)
|
||||||
@@ -37,7 +37,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
private val ACTION_USB_PERMISSION = "com.example.usbpermission"
|
private val ACTION_USB_PERMISSION = "com.example.usbpermission"
|
||||||
private val TIMEOUT = 0
|
private val TIMEOUT = 0
|
||||||
|
|
||||||
private var deviceData = listOf<DeviceData>()
|
private var deviceData: DeviceData? = null
|
||||||
|
|
||||||
private val usbManager: UsbManager by lazy {
|
private val usbManager: UsbManager by lazy {
|
||||||
requireContext().getSystemService(Context.USB_SERVICE) as UsbManager
|
requireContext().getSystemService(Context.USB_SERVICE) as UsbManager
|
||||||
@@ -72,11 +72,12 @@ class HemoCubeFragment : Fragment() {
|
|||||||
binding.progressBar.visibility = View.GONE
|
binding.progressBar.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.getDeviceData()
|
hemoCubeViewModel.getDeviceData("DEVICE1")
|
||||||
|
|
||||||
|
|
||||||
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
hemoCubeViewModel.deviceData.observe(viewLifecycleOwner) {
|
||||||
deviceData = it
|
deviceData = it
|
||||||
|
Toast.makeText(requireContext(), calculateRatio(0.17).toString(), Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
|
||||||
@@ -87,16 +88,16 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkBufferValue()) {
|
// if (checkBufferValue()) {
|
||||||
TODO("Call S command")
|
// TODO("Call S command")
|
||||||
//We have to store the buffer value like this
|
// //We have to store the buffer value like this
|
||||||
with(sharedPreference.edit()) {
|
// with(sharedPreference.edit()) {
|
||||||
putInt(Constants.BUFFER_VALUE, 2000)
|
// putInt(Constants.BUFFER_VALUE, 2000)
|
||||||
apply()
|
// apply()
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
TODO("Call B command")
|
// TODO("Call B command")
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkBufferValue(): Boolean {
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.hpostesting.presentation.hemocube
|
package com.example.hpostesting.presentation.hemocube
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.lifecycle.LiveData
|
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)
|
// 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)
|
private val _networkStatusLiveData = NetworkStatusLiveData(context)
|
||||||
val deviceData = MutableLiveData<List<DeviceData>>()
|
val deviceData = MutableLiveData<DeviceData?>()
|
||||||
val deviceIdToRetrieve = deviceData.value?.firstOrNull()?.deviceId
|
|
||||||
val networkStatusLiveData: LiveData<Boolean>
|
val networkStatusLiveData: LiveData<Boolean>
|
||||||
get() = _networkStatusLiveData
|
get() = _networkStatusLiveData
|
||||||
val fireBaseUpload = MutableLiveData<String>()
|
val fireBaseUpload = MutableLiveData<String>()
|
||||||
@@ -68,20 +68,10 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDeviceData(deviceId: String) = viewModelScope.launch {
|
||||||
|
deviceData.postValue(repository.getDeviceDataById(deviceId))
|
||||||
|
|
||||||
fun getDeviceData() = viewModelScope.launch {
|
|
||||||
deviceIdToRetrieve?.let { deviceId ->
|
|
||||||
val deviceIdinfo = repository.getDeviceDataById(deviceId)
|
|
||||||
deviceData.postValue(listOf(deviceIdinfo!!))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun addResultTestToDb() {
|
private fun addResultTestToDb() {
|
||||||
testDetails?.deviceRatio = DataHolder.hemocubeResult
|
testDetails?.deviceRatio = DataHolder.hemocubeResult
|
||||||
testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()
|
testDetails?.resultData = DataHolder.hemoCubeTestData?.resultData.toString()
|
||||||
|
|||||||
Reference in New Issue
Block a user