Buffer error resolved

This commit is contained in:
mohamedkaif356
2023-08-04 19:54:10 +05:30
parent e049e6ede3
commit c1c6c7cce4
4 changed files with 33 additions and 34 deletions

View File

@@ -60,8 +60,8 @@ class KitScanActivity : AppCompatActivity() {
with(sharedPreference.edit()) { with(sharedPreference.edit()) {
putString(Constants.KIT_NUMBER, "") putString(Constants.KIT_NUMBER, "")
putInt(Constants.KIT_COUNT, 0) putInt(Constants.KIT_COUNT, 0)
putInt(Constants.BUFFER_VALUE_1, 0) putString(Constants.BUFFER_VALUE_1, "")
putInt(Constants.BUFFER_VALUE_2, 0) putString(Constants.BUFFER_VALUE_2, "")
apply() apply()
} }
} }
@@ -94,8 +94,8 @@ class KitScanActivity : AppCompatActivity() {
private fun checkHemoCubeKitData(): Boolean { private fun checkHemoCubeKitData(): Boolean {
return sharedPreference.getString(Constants.KIT_NUMBER, "") return sharedPreference.getString(Constants.KIT_NUMBER, "")
?.isNotBlank() == true || sharedPreference.getInt(Constants.KIT_COUNT, 0) > 0 ?.isNotBlank() == true && sharedPreference.getInt(Constants.KIT_COUNT, 0) > 0
|| sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35 && sharedPreference.getInt(Constants.KIT_COUNT, 0) < 35
} }
private fun isSerialValid(s: String): Boolean { private fun isSerialValid(s: String): Boolean {

View File

@@ -54,7 +54,7 @@ class MainActivity : AppCompatActivity() {
locationCallback = object : LocationCallback() { locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult) { override fun onLocationResult(locationResult: LocationResult) {
locationResult.lastLocation?.let { location -> locationResult.lastLocation?.let { location ->
DataHolder.selectedTest!!.location = DataHolder.location =
UserData.Location(location.latitude, location.longitude) UserData.Location(location.latitude, location.longitude)
Log.i("Location", DataHolder.location.toString()) Log.i("Location", DataHolder.location.toString())
} }
@@ -222,6 +222,8 @@ class MainActivity : AppCompatActivity() {
location?.let { location?.let {
DataHolder.selectedTest!!.location = DataHolder.selectedTest!!.location =
UserData.Location(location.latitude, location.longitude) UserData.Location(location.latitude, location.longitude)
DataHolder.location =
UserData.Location(location.latitude, location.longitude)
} ?: run { } ?: run {
requestLocationUpdates() requestLocationUpdates()
} }

View File

@@ -3,9 +3,6 @@ package com.example.hpostesting.presentation.hemocube
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbDeviceConnection
import android.hardware.usb.UsbManager
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
@@ -15,7 +12,6 @@ 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 androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.NavHostFragment.Companion.findNavController
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.Constants
import com.example.hpostesting.data.constant.HemoCubeCommands import com.example.hpostesting.data.constant.HemoCubeCommands
@@ -23,8 +19,6 @@ 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.KitScanActivity import com.example.hpostesting.presentation.KitScanActivity
import com.example.hpostesting.presentation.UsbServiceListener import com.example.hpostesting.presentation.UsbServiceListener
import com.example.hpostesting.presentation.dashboard.HomeFragment
import com.example.hpostesting.presentation.testRight.TestRightExpSample
import com.example.hpostesting.presentation.utils.MyDialogListener import com.example.hpostesting.presentation.utils.MyDialogListener
import com.example.hpostesting.presentation.utils.UIUtils import com.example.hpostesting.presentation.utils.UIUtils
import `in`.sminnovations.hpostesting.R import `in`.sminnovations.hpostesting.R
@@ -110,8 +104,7 @@ class HemoCubeFragment : Fragment() {
listenToHemoCube() listenToHemoCube()
startSample() startSample()
} }
} })
)
} else { } else {
listenToHemoCube() listenToHemoCube()
startBuffer() startBuffer()
@@ -119,8 +112,16 @@ class HemoCubeFragment : Fragment() {
} }
private fun checkBufferValue(): Boolean { private fun checkBufferValue(): Boolean {
return sharedPreference.getInt(Constants.BUFFER_VALUE_1, 0) > 0 return if (sharedPreference.getString(Constants.BUFFER_VALUE_1, "") != ""
|| sharedPreference.getInt(Constants.BUFFER_VALUE_2, 0) > 0 && sharedPreference.getString(Constants.BUFFER_VALUE_2, "") != ""
) {
sharedPreference.getString(Constants.BUFFER_VALUE_1, "")
?.toInt()!! > 0 && sharedPreference.getString(Constants.BUFFER_VALUE_2, "")
?.toInt()!! > 0
} else {
false
}
} }
private fun setupButtonClickListeners() { private fun setupButtonClickListeners() {
@@ -136,7 +137,7 @@ class HemoCubeFragment : Fragment() {
startBuffer() startBuffer()
} }
binding.btnKit.setOnClickListener() { binding.btnKit.setOnClickListener {
with(sharedPreference.edit()) { with(sharedPreference.edit()) {
putInt(Constants.KIT_COUNT, 1) putInt(Constants.KIT_COUNT, 1)
apply() apply()
@@ -213,13 +214,16 @@ class HemoCubeFragment : Fragment() {
if (isOnline) { if (isOnline) {
resultRatio?.let { ratio -> resultRatio?.let { ratio ->
Log.e("Testdb", "upload") Log.e("Testdb", "upload")
hemoCubeViewModel.uploadHemoCubeResultToDatabase(isOnline, true, kitSerial hemoCubeViewModel.uploadHemoCubeResultToDatabase(
isOnline, true, kitSerial
) )
} }
binding.progressBar.visibility = View.VISIBLE binding.progressBar.visibility = View.VISIBLE
} else { } else {
resultRatio?.let { ratio -> resultRatio?.let { ratio ->
hemoCubeViewModel.uploadHemoCubeResultToDatabase(isOnline, true, kitSerial) hemoCubeViewModel.uploadHemoCubeResultToDatabase(
isOnline, true, kitSerial
)
} }
Toast.makeText( Toast.makeText(
requireContext(), requireContext(),
@@ -241,45 +245,39 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.progressBar.postValue(true) hemoCubeViewModel.progressBar.postValue(true)
val fullReadOutput = StringBuilder() val fullReadOutput = StringBuilder()
(activity as HemocubeActivity).mService.sendAndListenToHemoCube( (activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startBuffer,
HemoCubeCommands.startBuffer,
object : UsbServiceListener { object : UsbServiceListener {
override fun onUsbRead(data: ByteArray?) {} override fun onUsbRead(data: ByteArray?) {}
override fun onUsbError(e: Exception?) { override fun onUsbError(e: Exception?) {
hemoCubeViewModel.progressBar.postValue(false) hemoCubeViewModel.progressBar.postValue(false)
} }
} })
)
} }
private fun startSample() { private fun startSample() {
hemoCubeViewModel.progressBar.postValue(true) hemoCubeViewModel.progressBar.postValue(true)
val fullReadOutput = StringBuilder() val fullReadOutput = StringBuilder()
(activity as HemocubeActivity).mService.sendAndListenToHemoCube( (activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.startSample,
HemoCubeCommands.startSample,
object : UsbServiceListener { object : UsbServiceListener {
override fun onUsbRead(data: ByteArray?) {} override fun onUsbRead(data: ByteArray?) {}
override fun onUsbError(e: Exception?) { override fun onUsbError(e: Exception?) {
hemoCubeViewModel.progressBar.postValue(false) hemoCubeViewModel.progressBar.postValue(false)
} }
} })
)
} }
private fun getResult() { private fun getResult() {
hemoCubeViewModel.progressBar.postValue(true) hemoCubeViewModel.progressBar.postValue(true)
(activity as HemocubeActivity).mService.sendAndListenToHemoCube( (activity as HemocubeActivity).mService.sendAndListenToHemoCube(HemoCubeCommands.getSample,
HemoCubeCommands.getSample,
object : UsbServiceListener { object : UsbServiceListener {
override fun onUsbRead(data: ByteArray?) {} override fun onUsbRead(data: ByteArray?) {}
override fun onUsbError(e: Exception?) { override fun onUsbError(e: Exception?) {
hemoCubeViewModel.progressBar.postValue(false) hemoCubeViewModel.progressBar.postValue(false)
} }
} })
)
} }
private fun calculateRatio(ratio: Double): Double { private fun calculateRatio(ratio: Double): Double {
@@ -293,8 +291,7 @@ class HemoCubeFragment : Fragment() {
private fun checkAndFindResults(results: List<String>): String { private fun checkAndFindResults(results: List<String>): String {
val reversedResults = results.reversed() val reversedResults = results.reversed()
for (line in reversedResults) { for (line in reversedResults) {
if (isValidFormat(line)) if (isValidFormat(line)) return line
return line
} }
return "" return ""
} }

View File

@@ -29,7 +29,7 @@ class HemoCubeViewModel @Inject constructor(
) : ViewModel() { ) : ViewModel() {
var isServiceConnected = false var isServiceConnected = false
val progressBar = MutableLiveData(false) val progressBar = MutableLiveData(false)
val testDetails = DataHolder.selectedTest?.toHemoCubeTestData() private val testDetails = DataHolder.selectedTest?.toHemoCubeTestData()
// 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)
@@ -69,7 +69,7 @@ class HemoCubeViewModel @Inject constructor(
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()
testDetails?.location = DataHolder.hemoCubeTestData?.location testDetails?.location = DataHolder.location
testDetails?.testTime = SimpleDateFormat( testDetails?.testTime = SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss", Locale.getDefault() "yyyy-MM-dd HH:mm:ss", Locale.getDefault()
).format(Calendar.getInstance().time) ).format(Calendar.getInstance().time)