This commit is contained in:
smileomi18@gmail.com
2023-07-31 17:05:36 +05:30
parent e0a4008966
commit f8f8f140a9
6 changed files with 44 additions and 38 deletions

View File

@@ -15,9 +15,6 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<uses-permission android:name="android.permission.USB_PERMISSION" />
<application
android:name="com.example.hpostesting.HPOSTestingApplication"
android:allowBackup="true"

View File

@@ -22,7 +22,7 @@ object DataHolder {
val wavelengthToPixelArray = ArrayList<Double>()
val intensityReferenceArray = ArrayList<Double>()
var selectedTest: UserData? = null
var SelectTestType: HemoCubeTestData? = null
var HomocubeTestType: HemoCubeTestData? = null
var kitSerial: String = ""

View File

@@ -18,5 +18,7 @@ data class HemoCubeTestData(
var deviceSerialNumber: String = "",
var kitSerial: String = "",
var reportPath: String = "",
var resultRatio: Double? = null
var resultRatio: Double? = null,
var led1: Double? = null,
var led2: Double? = null
)

View File

@@ -68,8 +68,8 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.networkStatusLiveData.observe(viewLifecycleOwner) { isNetworkAvailable ->
apply {
kitSerial = DataHolder.SelectTestType?.kitSerial
testTime = DataHolder.SelectTestType?.testTime
kitSerial = DataHolder.HomocubeTestType?.kitSerial
testTime = DataHolder.HomocubeTestType?.testTime
isOnline = isNetworkAvailable
}
}
@@ -122,38 +122,46 @@ class HemoCubeFragment : Fragment() {
}
}
fun parseUsbData(data: String) {
val bufferPattern = """ok (Green|Blue) B Intensity: (\d+\.\d+)""".toRegex()
val samplePattern = """ok (Green|Blue) Intensity: (\d+\.\d+)""".toRegex()
val avgPattern = """ok Avg (Green|Blue): (\d+\.\d+)""".toRegex()
val resultPattern = """ok Result: (\d+\.\d+)""".toRegex()
private fun readUsbData() {
// Perform USB data reading and parsing here
val buffer = ByteArray(256) // Adjust the buffer size as per your data
val endpoint = usbDevice?.getInterface(0)?.getEndpoint(0)
var greenBIntensity: Double? = null
var blueBIntensity: Double? = null
var greenIntensity: Double? = null
var blueIntensity: Double? = null
var avgGreen: Double? = null
var avgBlue: Double? = null
var result: Double? = null
endpoint?.let {
val bytesRead = usbConnection?.bulkTransfer(it, buffer, buffer.size, TIMEOUT)
if (bytesRead != null && bytesRead > 0) {
val usbData = String(buffer, 0, bytesRead, Charsets.UTF_8)
val parsedData = parseUsbData(usbData)
displayValuesOnTextView(parsedData)
} else {
// Handle USB data read error
}
}
}
private fun parseUsbData(data: String): Map<String, String> {
val lines = data.split("\n")
val parsedData = mutableMapOf<String, String>()
for (line in lines) {
val labelAndValue = line.split(":")
if (labelAndValue.size == 2) {
val label = labelAndValue[0].trim()
val value = labelAndValue[1].trim()
parsedData[label] = value
for (line in data.split("\n")) {
when {
bufferPattern.matches(line) -> {
val (color, intensity) = bufferPattern.find(line)!!.destructured
if (color == "Green") greenBIntensity = intensity.toDouble()
else blueBIntensity = intensity.toDouble()
}
samplePattern.matches(line) -> {
val (color, intensity) = samplePattern.find(line)!!.destructured
if (color == "Green") greenIntensity = intensity.toDouble()
else blueIntensity = intensity.toDouble()
}
avgPattern.matches(line) -> {
val (color, avg) = avgPattern.find(line)!!.destructured
if (color == "Green") avgGreen = avg.toDouble()
else avgBlue = avg.toDouble()
}
resultPattern.matches(line) -> {
result = resultPattern.find(line)!!.destructured.component1().toDouble()
}
}
}
return parsedData
Log.d("greenBuffer", greenBIntensity.toString())
Log.d("greenBuffer", blueIntensity.toString())
Log.d("greenBuffer", blueBIntensity.toString())
}
@@ -166,8 +174,6 @@ class HemoCubeFragment : Fragment() {
append("$label: $value\n")
}
}
// Display the complete data accumulated so far
fullReadOutput.append(resultText)
textView.text = fullReadOutput.toString()
}
@@ -181,6 +187,7 @@ class HemoCubeFragment : Fragment() {
data?.let {
val stringData = String(it)
fullReadOutput.append(stringData)
binding.tvSubtitle4.text = fullReadOutput
resultRatio = fullReadOutput.toString()
val data = parseUsbData(fullReadOutput.toString())

View File

@@ -27,7 +27,7 @@ class HemoCubeViewModel @Inject constructor(
) : ViewModel() {
var isServiceConnected = false
val progressBar = MutableLiveData(false)
val testDetails = DataHolder.SelectTestType
val testDetails = DataHolder.HomocubeTestType
val testDetailuser = DataHolder.selectedTest
private val _networkStatusLiveData = NetworkStatusLiveData(context)
val networkStatusLiveData: LiveData<Boolean>

View File

@@ -51,7 +51,7 @@
android:id="@+id/tv_subtitle4"
style="@style/title2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="70dp"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="16dp"
android:hint="Result"