Making delay value a global constant.
This commit is contained in:
@@ -5,6 +5,7 @@ object Constants {
|
|||||||
|
|
||||||
const val WRITE_TIMEOUT_MILLIS = 30000 // 30 sec
|
const val WRITE_TIMEOUT_MILLIS = 30000 // 30 sec
|
||||||
const val READ_TIMEOUT_MILLIS = 60000 // 1 min
|
const val READ_TIMEOUT_MILLIS = 60000 // 1 min
|
||||||
|
const val DELAY_BETWEEN_COMMANDS: Long = 1000
|
||||||
|
|
||||||
const val TEST_RIGHT_TOTAL_PIXEL = 3694
|
const val TEST_RIGHT_TOTAL_PIXEL = 3694
|
||||||
// const val TEST_RIGHT_TOTAL_PIXEL = 12
|
// const val TEST_RIGHT_TOTAL_PIXEL = 12
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.example.hpos.R
|
import com.example.hpos.R
|
||||||
import com.example.hpos.data.DataHolder
|
import com.example.hpos.data.DataHolder
|
||||||
|
import com.example.hpos.data.constant.Constants
|
||||||
import com.example.hpos.data.constant.TestRightCommands
|
import com.example.hpos.data.constant.TestRightCommands
|
||||||
import com.example.hpos.databinding.FragmentTestRightExpReferenceBinding
|
import com.example.hpos.databinding.FragmentTestRightExpReferenceBinding
|
||||||
import com.example.hpos.presentation.UsbServiceListener
|
import com.example.hpos.presentation.UsbServiceListener
|
||||||
@@ -46,7 +47,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
|
|
||||||
if (DataHolder.deviceConstant == null) {
|
if (DataHolder.deviceConstant == null) {
|
||||||
viewModel.progressBar.postValue(true)
|
viewModel.progressBar.postValue(true)
|
||||||
Handler(Looper.getMainLooper()).postDelayed({ sendCmdToFetchDeviceConstant() }, 1000)
|
Handler(Looper.getMainLooper()).postDelayed({ sendCmdToFetchDeviceConstant() }, Constants.DELAY_BETWEEN_COMMANDS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,32 +150,22 @@ class TestRightExpReference : Fragment() {
|
|||||||
(activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.led2Set50,
|
(activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.led2Set50,
|
||||||
object : UsbServiceListener {
|
object : UsbServiceListener {
|
||||||
override fun onUsbRead(data: ByteArray?) {
|
override fun onUsbRead(data: ByteArray?) {
|
||||||
// requireActivity().runOnUiThread {
|
|
||||||
data?.let {
|
data?.let {
|
||||||
val stringData = String(it)
|
val stringData = String(it)
|
||||||
fullReadOutput.append(stringData)
|
fullReadOutput.append(stringData)
|
||||||
|
|
||||||
if (stringData.contains("OK", true)) {
|
if (stringData.contains("OK", true)) {
|
||||||
Log.d(TAG, "onUsbRead() called in sendCmdToSetLed()")
|
Log.d(TAG, "onUsbRead() called in sendCmdToSetLed()")
|
||||||
// viewModel.progressBar.postValue(false)
|
|
||||||
// requireActivity().runOnUiThread {
|
|
||||||
// Thread.sleep(2000)
|
|
||||||
// sendCmdToAutoset()
|
|
||||||
// }
|
|
||||||
|
|
||||||
Handler(Looper.getMainLooper()).postDelayed(
|
Handler(Looper.getMainLooper()).postDelayed(
|
||||||
Runnable {
|
Runnable {
|
||||||
viewModel.progressBar.postValue(false)
|
viewModel.progressBar.postValue(false)
|
||||||
sendCmdToAutoset()
|
sendCmdToAutoset()
|
||||||
},
|
},
|
||||||
2000
|
Constants.DELAY_BETWEEN_COMMANDS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// sendCmdToAutoset()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUsbError(e: Exception?) {
|
override fun onUsbError(e: Exception?) {
|
||||||
@@ -205,7 +196,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
viewModel.progressBar.postValue(false)
|
viewModel.progressBar.postValue(false)
|
||||||
sendCmdToRun()
|
sendCmdToRun()
|
||||||
},
|
},
|
||||||
2000
|
Constants.DELAY_BETWEEN_COMMANDS
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -221,6 +212,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun sendCmdToRun() {
|
private fun sendCmdToRun() {
|
||||||
|
Log.d(TAG, "sendCmdToRun() called")
|
||||||
viewModel.progressBar.postValue(true)
|
viewModel.progressBar.postValue(true)
|
||||||
val fullReadOutput = StringBuilder()
|
val fullReadOutput = StringBuilder()
|
||||||
(activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.run,
|
(activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.run,
|
||||||
@@ -241,7 +233,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
viewModel.progressBar.postValue(false)
|
viewModel.progressBar.postValue(false)
|
||||||
sendCmdToFetchLightIntensities()
|
sendCmdToFetchLightIntensities()
|
||||||
},
|
},
|
||||||
2000
|
Constants.DELAY_BETWEEN_COMMANDS
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,6 +248,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun sendCmdToFetchLightIntensities() {
|
private fun sendCmdToFetchLightIntensities() {
|
||||||
|
Log.d(TAG, "sendCmdToFetchLightIntensities() called")
|
||||||
viewModel.progressBar.postValue(true)
|
viewModel.progressBar.postValue(true)
|
||||||
val fullReadOutput = StringBuilder()
|
val fullReadOutput = StringBuilder()
|
||||||
(activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.printAll,
|
(activity as TestRightActivity).mService.eventDrivenWrite(TestRightCommands.printAll,
|
||||||
@@ -277,7 +270,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
viewModel.progressBar.postValue(false)
|
viewModel.progressBar.postValue(false)
|
||||||
moveToSamplePage()
|
moveToSamplePage()
|
||||||
},
|
},
|
||||||
2000
|
Constants.DELAY_BETWEEN_COMMANDS
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,7 +305,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
// Runnable {
|
// Runnable {
|
||||||
// sendCmdToFetchDeviceConstant()
|
// sendCmdToFetchDeviceConstant()
|
||||||
// },
|
// },
|
||||||
// 2000
|
// Constants.DELAY_BETWEEN_COMMANDS
|
||||||
// )
|
// )
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@@ -366,7 +359,7 @@ class TestRightExpReference : Fragment() {
|
|||||||
// val handler = Handler()
|
// val handler = Handler()
|
||||||
// handler.postDelayed(Runnable { // Do something after 5s = 5000ms
|
// handler.postDelayed(Runnable { // Do something after 5s = 5000ms
|
||||||
// mService.read()
|
// mService.read()
|
||||||
// }, 10000)
|
// }, Constants.DELAY_BETWEEN_COMMANDS)
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import android.view.ViewGroup
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import com.example.hpos.R
|
import com.example.hpos.R
|
||||||
|
import com.example.hpos.data.constant.Constants
|
||||||
import com.example.hpos.data.constant.TestRightCommands
|
import com.example.hpos.data.constant.TestRightCommands
|
||||||
import com.example.hpos.data.model.PatientData
|
import com.example.hpos.data.model.PatientData
|
||||||
import com.example.hpos.data.model.TestRightResultType
|
import com.example.hpos.data.model.TestRightResultType
|
||||||
@@ -121,7 +122,7 @@ class TestRightExpSample : Fragment() {
|
|||||||
viewModel.progressBar.postValue(false)
|
viewModel.progressBar.postValue(false)
|
||||||
sendCmdToFetchLightIntensities()
|
sendCmdToFetchLightIntensities()
|
||||||
},
|
},
|
||||||
2000
|
Constants.DELAY_BETWEEN_COMMANDS
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user