Merge remote-tracking branch 'origin/Homocube' into Homocube
This commit is contained in:
@@ -44,4 +44,8 @@ object Constants {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const val password = "SMI@12345"
|
const val password = "SMI@12345"
|
||||||
|
|
||||||
|
const val KIT_NUMBER = "KitNumber"
|
||||||
|
const val KIT_COUNT = "KitCount"
|
||||||
|
const val BUFFER_VALUE = "BufferValue"
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.hpostesting.data.constant
|
||||||
|
|
||||||
|
enum class HemoCubeCommands(val command: String) {
|
||||||
|
run("R\r"),
|
||||||
|
}
|
||||||
@@ -22,8 +22,8 @@ data class HemoCubeTestData(
|
|||||||
var led2Buffer: Double? = null,
|
var led2Buffer: Double? = null,
|
||||||
var led1Sample: Double? = null,
|
var led1Sample: Double? = null,
|
||||||
var led2Sample: Double? = null,
|
var led2Sample: Double? = null,
|
||||||
var led1Avarage: Double? = null,
|
var led1Average: Double? = null,
|
||||||
var led2Avarage: Double? = null,
|
var led2Average: Double? = null,
|
||||||
var deviceRatio: Double? = null,
|
var deviceRatio: Double? = null,
|
||||||
var calculatedRatio: Double? = null
|
var calculatedRatio: Double? = null
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.example.hpostesting.presentation
|
package com.example.hpostesting.presentation
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@@ -21,6 +23,8 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
private val TAG = "KitScanActivity"
|
private val TAG = "KitScanActivity"
|
||||||
private lateinit var binding: ActivityKitScanBinding
|
private lateinit var binding: ActivityKitScanBinding
|
||||||
|
|
||||||
|
private lateinit var sharedPreference: SharedPreferences
|
||||||
|
|
||||||
private val barcodeLauncher = registerForActivityResult(
|
private val barcodeLauncher = registerForActivityResult(
|
||||||
ScanContract()
|
ScanContract()
|
||||||
) { result: ScanIntentResult ->
|
) { result: ScanIntentResult ->
|
||||||
@@ -40,13 +44,27 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
binding = ActivityKitScanBinding.inflate(layoutInflater)
|
binding = ActivityKitScanBinding.inflate(layoutInflater)
|
||||||
|
sharedPreference = this.getSharedPreferences("PREFERENCE_NAME", Context.MODE_PRIVATE)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
if (DataHolder.sampleReadCounter <= Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE && DataHolder.isReferenceTaken){
|
if (DataHolder.sampleReadCounter <= Constants.MAXIMUM_TEST_ALLOWED_BEFORE_REFERENCE && DataHolder.isReferenceTaken) {
|
||||||
DataHolder.selectedTest!!.kitSerial = DataHolder.kitSerial
|
DataHolder.selectedTest!!.kitSerial = DataHolder.kitSerial
|
||||||
moveToNext()
|
moveToNext()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (checkHemoCubeKitData()) {
|
||||||
|
DataHolder.selectedTest!!.kitSerial =
|
||||||
|
sharedPreference.getString(Constants.KIT_NUMBER, "").toString()
|
||||||
|
moveToNext()
|
||||||
|
} else {
|
||||||
|
with(sharedPreference.edit()) {
|
||||||
|
putString(Constants.KIT_NUMBER, "")
|
||||||
|
putInt(Constants.KIT_COUNT, 0)
|
||||||
|
putInt(Constants.BUFFER_VALUE, 0)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
binding.nameEditText.setText("SMI/SC/")
|
binding.nameEditText.setText("SMI/SC/")
|
||||||
|
|
||||||
setSupportActionBar(binding.toolbar)
|
setSupportActionBar(binding.toolbar)
|
||||||
@@ -61,6 +79,11 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
if (serialNumber.isNotEmpty() && checkDataNotNull() && isSerialValid(serialNumber)) {
|
if (serialNumber.isNotEmpty() && checkDataNotNull() && isSerialValid(serialNumber)) {
|
||||||
DataHolder.kitSerial = binding.nameEditText.text.toString()
|
DataHolder.kitSerial = binding.nameEditText.text.toString()
|
||||||
DataHolder.selectedTest?.kitSerial = binding.nameEditText.text.toString()
|
DataHolder.selectedTest?.kitSerial = binding.nameEditText.text.toString()
|
||||||
|
with(sharedPreference.edit()) {
|
||||||
|
putString(Constants.KIT_NUMBER, binding.nameEditText.text.toString())
|
||||||
|
putInt(Constants.KIT_COUNT, 1)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
moveToNext()
|
moveToNext()
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(this, "Invalid KIT Number", Toast.LENGTH_LONG).show()
|
Toast.makeText(this, "Invalid KIT Number", Toast.LENGTH_LONG).show()
|
||||||
@@ -68,8 +91,14 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkHemoCubeKitData(): Boolean {
|
||||||
|
return sharedPreference.getString(Constants.KIT_NUMBER, "")
|
||||||
|
?.isNotBlank() == true || sharedPreference.getInt(Constants.KIT_COUNT, 0) > 0
|
||||||
|
|| sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35
|
||||||
|
}
|
||||||
|
|
||||||
private fun isSerialValid(s: String): Boolean {
|
private fun isSerialValid(s: String): Boolean {
|
||||||
if (s.length != 17){
|
if (s.length != 17) {
|
||||||
binding.nameEditText.error = getString(R.string.invalid_kit)
|
binding.nameEditText.error = getString(R.string.invalid_kit)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -84,6 +113,7 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
val i = Intent(applicationContext, HemocubeActivity::class.java)
|
val i = Intent(applicationContext, HemocubeActivity::class.java)
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
Constants.DEVICE_TYPE_TEST_RIGHT -> {
|
Constants.DEVICE_TYPE_TEST_RIGHT -> {
|
||||||
val i = Intent(applicationContext, TestRightActivity::class.java)
|
val i = Intent(applicationContext, TestRightActivity::class.java)
|
||||||
startActivity(i)
|
startActivity(i)
|
||||||
@@ -111,9 +141,7 @@ class KitScanActivity : AppCompatActivity() {
|
|||||||
private fun checkDataNotNull(): Boolean {
|
private fun checkDataNotNull(): Boolean {
|
||||||
return if (DataHolder.selectedTest?._id == null) {
|
return if (DataHolder.selectedTest?._id == null) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
applicationContext,
|
applicationContext, "Please Select patient before starting test", Toast.LENGTH_SHORT
|
||||||
"Please Select patient before starting test",
|
|
||||||
Toast.LENGTH_SHORT
|
|
||||||
).show()
|
).show()
|
||||||
|
|
||||||
val i = Intent(applicationContext, DashboardActivity::class.java)
|
val i = Intent(applicationContext, DashboardActivity::class.java)
|
||||||
|
|||||||
@@ -70,10 +70,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
DataHolder.deviceType.observe(this) { deviceType ->
|
DataHolder.deviceType.observe(this) { deviceType ->
|
||||||
with(binding) {
|
with(binding) {
|
||||||
if (deviceType == Constants.DEVICE_TYPE_HOMOCUBE) {
|
if (deviceType == Constants.DEVICE_TYPE_HOMOCUBE) {
|
||||||
binding.cvItem1.visibility = View.VISIBLE
|
cvItem1.visibility = View.VISIBLE
|
||||||
binding.cvItem3.visibility = View.VISIBLE
|
cvItem3.visibility = View.VISIBLE
|
||||||
binding.cvItem2.visibility = View.GONE
|
cvItem2.visibility = View.GONE
|
||||||
binding.cvItem4.visibility = View.GONE
|
cvItem4.visibility = View.GONE
|
||||||
}
|
}
|
||||||
DataHolder.usbConnected.value = true
|
DataHolder.usbConnected.value = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import android.widget.Toast
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.example.hpostesting.data.DataHolder
|
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.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
|
||||||
@@ -84,6 +86,21 @@ class HemoCubeFragment : Fragment() {
|
|||||||
isOnline = isNetworkAvailable
|
isOnline = isNetworkAvailable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
return sharedPreference.getInt(Constants.BUFFER_VALUE, 0) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupButtonClickListeners() {
|
private fun setupButtonClickListeners() {
|
||||||
@@ -107,11 +124,11 @@ class HemoCubeFragment : Fragment() {
|
|||||||
override fun onClickNegativeButton() {}
|
override fun onClickNegativeButton() {}
|
||||||
override fun onClickPositiveButton() {
|
override fun onClickPositiveButton() {
|
||||||
fetchHemoCubeResult()
|
fetchHemoCubeResult()
|
||||||
|
sendCommandToHemoCube()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.btnSubmit.setOnClickListener {
|
binding.btnSubmit.setOnClickListener {
|
||||||
@@ -209,7 +226,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
|
|
||||||
hemoCubeViewModel.progressBar.postValue(true)
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
val fullReadOutput = StringBuilder()
|
val fullReadOutput = StringBuilder()
|
||||||
(activity as HemocubeActivity).mService.eventDrivenWriteHemoCube(object :
|
(activity as HemocubeActivity).mService.listenToHemoCube(object :
|
||||||
UsbServiceListener {
|
UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
data?.let {
|
data?.let {
|
||||||
@@ -231,4 +248,67 @@ class HemoCubeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fetchHemoCubeResultNew() {
|
||||||
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
val fullReadOutput = StringBuilder()
|
||||||
|
(activity as HemocubeActivity).mService.listenToHemoCube(object :
|
||||||
|
UsbServiceListener {
|
||||||
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
|
data?.let {
|
||||||
|
val stringData = String(it)
|
||||||
|
fullReadOutput.append(stringData)
|
||||||
|
|
||||||
|
// Split the data into lines
|
||||||
|
val lines = fullReadOutput.toString().split("\n")
|
||||||
|
|
||||||
|
// Filter and get only the lines starting with "#"
|
||||||
|
val bufferLines = lines.filter { it.startsWith("#") }
|
||||||
|
|
||||||
|
// Create a new text with the filtered lines and join them with line breaks
|
||||||
|
val newText = bufferLines.joinToString("\n")
|
||||||
|
|
||||||
|
// Update the TextView with the new text
|
||||||
|
binding.tvSubtitle4.text = newText
|
||||||
|
|
||||||
|
// Get the result data
|
||||||
|
val data = parseUsbData(fullReadOutput.toString())
|
||||||
|
Log.d("Result", data.toString())
|
||||||
|
|
||||||
|
// Update the view model with progress bar state
|
||||||
|
hemoCubeViewModel.progressBar.postValue(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUsbError(e: Exception?) {
|
||||||
|
hemoCubeViewModel.progressBar.postValue(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sendCommandToHemoCube() {
|
||||||
|
hemoCubeViewModel.progressBar.postValue(true)
|
||||||
|
val fullReadOutput = StringBuilder()
|
||||||
|
|
||||||
|
(activity as HemocubeActivity).mService.eventDrivenWriteHemoCube(HemoCubeCommands.run,
|
||||||
|
object : UsbServiceListener {
|
||||||
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
|
data?.let {
|
||||||
|
val stringData = String(it)
|
||||||
|
fullReadOutput.append(stringData)
|
||||||
|
|
||||||
|
if (stringData.contains("RESULT", true)) {
|
||||||
|
// hemoCubeViewModel.mapDeviceConstants(fullReadOutput.toString())
|
||||||
|
hemoCubeViewModel.progressBar.postValue(false)
|
||||||
|
} else if (stringData.contains("FINE", true)) {
|
||||||
|
hemoCubeViewModel.progressBar.postValue(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUsbError(e: Exception?) {
|
||||||
|
hemoCubeViewModel.progressBar.postValue(false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,6 @@ class TestRightExpReference : Fragment() {
|
|||||||
binding.btnSetReference.isEnabled = true
|
binding.btnSetReference.isEnabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,6 +95,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
private fun startTakingReference() {
|
private fun startTakingReference() {
|
||||||
sendCmdToSetLed()
|
sendCmdToSetLed()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendCmdToFetchDeviceConstant() {
|
private fun sendCmdToFetchDeviceConstant() {
|
||||||
Log.d(TAG, "sendCmdToFetchDeviceConstant() called")
|
Log.d(TAG, "sendCmdToFetchDeviceConstant() called")
|
||||||
|
|
||||||
|
|||||||
@@ -532,6 +532,4 @@ class TestRightViewModel @Inject constructor(
|
|||||||
fun deleteById(userId: String) = viewModelScope.launch {
|
fun deleteById(userId: String) = viewModelScope.launch {
|
||||||
userDao.deleteById(id = userId)
|
userDao.deleteById(id = userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import android.os.Binder
|
|||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.example.hpostesting.data.constant.Constants
|
import com.example.hpostesting.data.constant.Constants
|
||||||
|
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||||
import com.example.hpostesting.data.constant.TestRightCommands
|
import com.example.hpostesting.data.constant.TestRightCommands
|
||||||
import com.example.hpostesting.presentation.UsbServiceListener
|
import com.example.hpostesting.presentation.UsbServiceListener
|
||||||
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
import com.hoho.android.usbserial.driver.UsbSerialDriver
|
||||||
@@ -64,7 +65,7 @@ class UsbService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun eventDrivenWriteHemoCube(listener: UsbServiceListener) {
|
fun listenToHemoCube(listener: UsbServiceListener) {
|
||||||
this.listener = listener
|
this.listener = listener
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@@ -72,4 +73,13 @@ class UsbService : Service() {
|
|||||||
listener.onUsbError(e)
|
listener.onUsbError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun eventDrivenWriteHemoCube(command: HemoCubeCommands, listener: UsbServiceListener) {
|
||||||
|
try {
|
||||||
|
this.listener = listener
|
||||||
|
mPort.write(command.command.toByteArray(), Constants.WRITE_TIMEOUT_MILLIS)
|
||||||
|
} catch (e: IOException) {
|
||||||
|
listener.onUsbError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user