merge
This commit is contained in:
@@ -14,6 +14,7 @@ import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.example.hpostesting.data.DataHolder
|
||||
import com.example.hpostesting.data.constant.HemoCubeCommands
|
||||
import com.example.hpostesting.data.model.patient.toHemoCubeTestData
|
||||
import com.example.hpostesting.presentation.UsbServiceListener
|
||||
import com.example.hpostesting.presentation.utils.MyDialogListener
|
||||
@@ -96,11 +97,11 @@ class HemoCubeFragment : Fragment() {
|
||||
override fun onClickNegativeButton() {}
|
||||
override fun onClickPositiveButton() {
|
||||
fetchHemoCubeResult()
|
||||
sendCommandToHemoCube()
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
@@ -194,7 +195,7 @@ class HemoCubeFragment : Fragment() {
|
||||
|
||||
hemoCubeViewModel.progressBar.postValue(true)
|
||||
val fullReadOutput = StringBuilder()
|
||||
(activity as HemocubeActivity).mService.eventDrivenWriteHemoCube(object :
|
||||
(activity as HemocubeActivity).mService.listenToHemoCube(object :
|
||||
UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {
|
||||
data?.let {
|
||||
@@ -216,4 +217,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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +95,7 @@ class TestRightExpReference : Fragment() {
|
||||
private fun startTakingReference() {
|
||||
sendCmdToSetLed()
|
||||
}
|
||||
|
||||
private fun sendCmdToFetchDeviceConstant() {
|
||||
Log.d(TAG, "sendCmdToFetchDeviceConstant() called")
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
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.presentation.UsbServiceListener
|
||||
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
|
||||
try {
|
||||
|
||||
@@ -72,4 +73,13 @@ class UsbService : Service() {
|
||||
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