run deviceid command and store deviceid in spref
This commit is contained in:
@@ -5,4 +5,5 @@ enum class HemoCubeCommands(val command: String) {
|
||||
getBuffer("D\r"),
|
||||
startSample("S\r"),
|
||||
getSample("P\r"),
|
||||
getDeviceId("I\r"),
|
||||
}
|
||||
@@ -59,6 +59,7 @@ class DiagnosticsFragment : Fragment() {
|
||||
|
||||
private fun initViews() {
|
||||
listenToHemoCube()
|
||||
getDeviceId()
|
||||
binding.btnSubmit.setOnClickListener {
|
||||
binding.btnSubmit.visibility = View.GONE
|
||||
getBufferdiagnostics()
|
||||
@@ -95,6 +96,32 @@ class DiagnosticsFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDeviceId() {
|
||||
diagnosticsViewModel.progressBar.postValue(true)
|
||||
(activity as DiagnosticsActivity).mService.sendAndListenToHemoCube(
|
||||
HemoCubeCommands.getDeviceId,
|
||||
object : UsbServiceListener {
|
||||
override fun onUsbRead(data: ByteArray?) {
|
||||
data?.let {
|
||||
val stringData = String(it)
|
||||
diagnosticsViewModel.messages.postValue(stringData)
|
||||
val pattern = Regex("([A-Z]+)\\s(\\d+)")
|
||||
val matchResult = pattern.find(stringData)
|
||||
if (matchResult != null) {
|
||||
val (sn, hardwareId) = matchResult.destructured
|
||||
with(sharedPreferences.edit()) {
|
||||
putString(com.example.hpostesting.data.constant.Constants.DEVICE_ID, hardwareId)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
binding.tvSubtitle4.text = stringData
|
||||
}
|
||||
}
|
||||
override fun onUsbError(e: Exception?) {
|
||||
diagnosticsViewModel.progressBar.postValue(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun getBufferdiagnostics() {
|
||||
diagnosticsViewModel.progressBar.postValue(true)
|
||||
|
||||
Reference in New Issue
Block a user