diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 16ad1da..71c60c2 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -13,7 +13,9 @@
+
+
+
+ android:noHistory="true"
+ android:theme="@style/Theme.HPOS.NoActionBar" />
+ android:theme="@style/Theme.HPOS.NoActionBar"
+ android:windowSoftInputMode="adjustPan">
@@ -91,7 +96,6 @@
android:screenOrientation="portrait"
android:stateNotNeeded="true"
tools:replace="android:screenOrientation" />
-
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt
index 30d7d17..433ac7b 100644
--- a/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt
+++ b/app/src/main/java/com/example/hpostesting/presentation/KitScanActivity.kt
@@ -8,6 +8,7 @@ import androidx.appcompat.app.AppCompatActivity
import com.example.hpostesting.data.DataHolder
import com.example.hpostesting.data.constant.Constants
import com.example.hpostesting.presentation.dashboard.DashboardActivity
+import com.example.hpostesting.presentation.hemocube.HemocubeActivity
import com.example.hpostesting.presentation.testRight.TestRightActivity
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanIntentResult
@@ -72,8 +73,13 @@ class KitScanActivity : AppCompatActivity() {
}
private fun moveToNext() {
- val i = Intent(applicationContext, TestRightActivity::class.java)
- startActivity(i)
+ if (DataHolder.deviceType.equals(Constants.DEVICE_TYPE_HOMOCUBE)) {
+ val i = Intent(applicationContext, HemocubeActivity::class.java)
+ startActivity(i)
+ } else {
+ val i = Intent(applicationContext, TestRightActivity::class.java)
+ startActivity(i)
+ }
}
private fun startScanningNow() {
diff --git a/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt
index c968ccd..d9e89fc 100644
--- a/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt
+++ b/app/src/main/java/com/example/hpostesting/presentation/MainActivity.kt
@@ -76,22 +76,22 @@ class MainActivity : AppCompatActivity() {
addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
}
registerReceiver(mUsbReceiver, filter)
-// DataHolder.deviceType.observe(this) { deviceType ->
-// when (deviceType) {
-// Constants.DEVICE_TYPE_HOMOCUBE -> {
-// binding.cvItem1.visibility = View.VISIBLE
-// binding.cvItem3.visibility = View.VISIBLE
-// binding.cvItem2.visibility = View.GONE
-// binding.cvItem4.visibility = View.GONE
-// Toast.makeText(this, "HomoCube Connected", Toast.LENGTH_SHORT).show()
-// DataHolder.usbConnected.value = true
-// DataHolder.deviceType.postValue(Constants.DEVICE_TYPE_HOMOCUBE)
-// }
-// "Test" -> {
-//
-// }
-// }
-// }
+ DataHolder.deviceType.observe(this) { deviceType ->
+ when (deviceType) {
+ Constants.DEVICE_TYPE_HOMOCUBE -> {
+ binding.cvItem1.visibility = View.VISIBLE
+ binding.cvItem3.visibility = View.VISIBLE
+ binding.cvItem2.visibility = View.GONE
+ binding.cvItem4.visibility = View.GONE
+ Toast.makeText(this, "HomoCube Connected", Toast.LENGTH_SHORT).show()
+ DataHolder.usbConnected.value = true
+ DataHolder.deviceType.postValue(Constants.DEVICE_TYPE_HOMOCUBE)
+ }
+ "Test" -> {
+
+ }
+ }
+ }
}
private fun checkAndUpdateUsbConnection() {
diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt
new file mode 100644
index 0000000..72a8de8
--- /dev/null
+++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeFragment.kt
@@ -0,0 +1,118 @@
+package com.example.hpostesting.presentation.hemocube
+
+import android.os.Bundle
+import android.util.Log
+import androidx.fragment.app.Fragment
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.activityViewModels
+import com.example.hpostesting.data.DataHolder
+import com.example.hpostesting.data.constant.Constants
+import com.example.hpostesting.data.constant.TestRightCommands
+import com.example.hpostesting.data.model.ErrorMessage
+import com.example.hpostesting.presentation.UsbServiceListener
+import com.example.hpostesting.presentation.testRight.TestRightActivity
+import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
+
+
+// TODO: Rename parameter arguments, choose names that match
+// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
+private const val ARG_PARAM1 = "param1"
+private const val ARG_PARAM2 = "param2"
+
+/**
+ * A simple [Fragment] subclass.
+ * Use the [HemoCubeFragment.newInstance] factory method to
+ * create an instance of this fragment.
+ */
+class HemoCubeFragment : Fragment() {
+ private lateinit var binding: FragmentHemoCubeReferenceBinding
+ private val viewModel: HemoCubeViewModel by activityViewModels()
+
+ private val TAG = "TestRightExpReference"
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ arguments?.let {
+// param1 = it.getString(ARG_PARAM1)
+// param2 = it.getString(ARG_PARAM2)
+ }
+ }
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ // Inflate the layout for this fragment
+ binding = FragmentHemoCubeReferenceBinding.inflate(inflater, container, false)
+ return binding.root
+
+ Log.e("mariya", "onViewCreated 1")
+ if (DataHolder.deviceType.equals(Constants.DEVICE_TYPE_HOMOCUBE) ) {
+ Log.e("mariya", "onViewCreated if")
+ fetchHemoCubeResult()
+ }
+
+
+ }
+
+ private fun fetchHemoCubeResult() {
+ Log.d("mariya", "fetchHemoCubeResult() called")
+
+ viewModel.progressBar.postValue(true)
+ val fullReadOutput = StringBuilder()
+
+ (activity as TestRightActivity).mService.eventDrivenWriteHemoCube(
+ object : UsbServiceListener {
+ override fun onUsbRead(data: ByteArray?) {
+ Log.d("mariya", data.toString())
+ data?.let {
+ val stringData = String(it)
+ fullReadOutput.append(stringData)
+ Log.d(TAG, "fullReadOutput = $fullReadOutput")
+ binding.tvSubtitle4.text = fullReadOutput
+
+ if (stringData.contains("OK", true)) {
+ Log.d(
+ TAG,
+ "onUsbRead() called in sendCmdToFetchDeviceConstant() found OK"
+ )
+
+ viewModel.progressBar.postValue(false)
+ } else if (stringData.contains("FINE", true)) {
+ Log.d(TAG, "results = FINE")
+ viewModel.progressBar.postValue(false)
+ }
+ }
+ }
+
+ override fun onUsbError(e: Exception?) {
+ Log.e(TAG, "onUsbIoError() called in sendCmdToFetchDeviceConstant() -> $e")
+// viewModel.errorTriggered.postValue(ErrorMessage("Please Try Again this step", Constants.ERROR_NORMAL))
+
+ viewModel.progressBar.postValue(false)
+ }
+ })
+ }
+
+
+ companion object {
+ /**
+ * Use this factory method to create a new instance of
+ * this fragment using the provided parameters.
+ *
+ * @param param1 Parameter 1.
+ * @param param2 Parameter 2.
+ * @return A new instance of fragment HemoCubeReference.
+ */
+ // TODO: Rename and change types and number of parameters
+ @JvmStatic
+ fun newInstance(param1: String, param2: String) =
+ HemoCubeFragment().apply {
+ arguments = Bundle().apply {
+ putString(ARG_PARAM1, param1)
+ putString(ARG_PARAM2, param2)
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt
new file mode 100644
index 0000000..a42bbf7
--- /dev/null
+++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemoCubeViewModel.kt
@@ -0,0 +1,19 @@
+package com.example.hpostesting.presentation.hemocube
+
+import android.content.Context
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import com.example.hpostesting.data.DataHolder
+import com.example.hpostesting.data.dao.UserDao
+import dagger.hilt.android.lifecycle.HiltViewModel
+import javax.inject.Inject
+
+@HiltViewModel
+class HemoCubeViewModel@Inject constructor(
+ private val userDao: UserDao,
+ context: Context
+) : ViewModel() {
+ var isServiceConnected = false
+ val progressBar = MutableLiveData(false)
+ val testDetails = DataHolder.selectedTest
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemocubeActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemocubeActivity.kt
new file mode 100644
index 0000000..2b791ed
--- /dev/null
+++ b/app/src/main/java/com/example/hpostesting/presentation/hemocube/HemocubeActivity.kt
@@ -0,0 +1,207 @@
+package com.example.hpostesting.presentation.hemocube
+
+import android.app.PendingIntent
+import android.content.BroadcastReceiver
+import android.content.ComponentName
+import android.content.ContentValues.TAG
+import android.content.Context
+import android.content.Intent
+import android.content.IntentFilter
+import android.content.ServiceConnection
+import android.hardware.usb.UsbDevice
+import android.hardware.usb.UsbDeviceConnection
+import android.hardware.usb.UsbManager
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import android.os.IBinder
+import android.util.Log
+import android.view.Menu
+import android.widget.Toast
+import androidx.activity.viewModels
+import androidx.core.content.ContextCompat
+import androidx.core.view.get
+import com.example.hpostesting.data.DataHolder
+import com.example.hpostesting.data.constant.Constants
+import com.example.hpostesting.presentation.testRight.TestRightExpReference
+import com.example.hpostesting.presentation.testRight.TestRightExpSample
+import com.example.hpostesting.presentation.testRight.TestRightViewModel
+import com.example.hpostesting.presentation.testRight.UsbService
+import com.google.android.gms.location.FusedLocationProviderClient
+import com.google.android.gms.location.LocationCallback
+import com.hoho.android.usbserial.driver.UsbSerialDriver
+import com.hoho.android.usbserial.driver.UsbSerialProber
+import dagger.hilt.android.AndroidEntryPoint
+import `in`.sminnovations.hpostesting.R
+import `in`.sminnovations.hpostesting.databinding.ActivityHemocubeBinding
+import `in`.sminnovations.hpostesting.databinding.ActivityMainBinding
+
+@AndroidEntryPoint
+class HemocubeActivity : AppCompatActivity() {
+ private lateinit var binding: ActivityHemocubeBinding
+ private val viewModel by viewModels()
+ private var myMenu: Menu? = null
+
+ private lateinit var mDriver: UsbSerialDriver
+ private var mConnection: UsbDeviceConnection? = null
+ lateinit var mService: UsbService
+
+ private val TAG = "HemoCube"
+
+ private val broadcastReceiver = object : BroadcastReceiver() {
+ override fun onReceive(context: Context, intent: Intent) {
+
+ synchronized(this) {
+ val device: UsbDevice? = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE)
+
+ if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
+ device?.apply {
+ connectUsb(true)
+ }
+ } else {
+ onErrorReported("permission denied for device")
+ }
+ }
+
+ }
+ }
+
+ private val connection = object : ServiceConnection {
+ override fun onServiceConnected(className: ComponentName, service: IBinder) {
+ val binder = service as UsbService.UsbServiceBinder
+ mService = binder.getService()
+ viewModel.isServiceConnected = true
+
+ // Todo: Uncomment this
+ mConnection.let { mService.connect(mDriver, mConnection!!) }
+ moveToNext()
+ }
+
+ override fun onServiceDisconnected(arg0: ComponentName) {
+ viewModel.isServiceConnected = false
+ }
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ binding = ActivityHemocubeBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ setSupportActionBar(binding.myToolbar)
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+
+ setupListener()
+
+ connectUsb(false)
+ }
+
+ private fun setupListener() {
+ DataHolder.usbConnected.observe(this){
+ Log.d("USB OBSERVE", "HemoCube called -> $it")
+ if (it){
+ myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_24)
+// binding.clParent.setAllEnabled(true)
+ } else {
+ myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
+// val myToast = Toast.makeText(this, "USB is Detached", Toast.LENGTH_SHORT)
+ Toast.makeText(this, "Device is Disconnected", Toast.LENGTH_SHORT).show()
+// binding.clParent.setAllEnabled(false)
+ }
+ }
+ }
+
+ private fun connectUsb(permissionGranted: Boolean) {
+ Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
+ val manager = getSystemService(Context.USB_SERVICE) as UsbManager
+ val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager)
+
+ if (availableDrivers.isEmpty()) {
+ onErrorReported("No Device is Connected")
+ } else {
+ mDriver = availableDrivers[0]
+
+ viewModel.testDetails?.deviceId = mDriver.device.serialNumber.toString()
+ DataHolder.deviceSerialNumber = mDriver.device.serialNumber.toString()
+ mConnection = manager.openDevice(mDriver.device)
+
+ if (mConnection == null) {
+ requestUserPermission(manager, mDriver.device)
+ } else {
+ setupService()
+ }
+ }
+ }
+
+
+ private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
+// Log.d(TAG, "requestUserPermissions() called -> vendor id = ${device.vendorId} & product id = ${device.productId}")
+
+ val mPendingIntent: PendingIntent
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
+ mPendingIntent = PendingIntent.getBroadcast(
+ this,
+ 0,
+ Intent(Constants.ACTION_USB_PERMISSION),
+ PendingIntent.FLAG_MUTABLE
+ )
+ } else {
+ mPendingIntent = PendingIntent.getBroadcast(
+ this,
+ 0,
+ Intent(Constants.ACTION_USB_PERMISSION),
+ PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
+ )
+ }
+
+ val filter = IntentFilter(Constants.ACTION_USB_PERMISSION)
+ registerReceiver(broadcastReceiver, filter)
+ manager.requestPermission(device, mPendingIntent)
+ }
+
+ private fun setupService() {
+ val intent = Intent(this, UsbService::class.java)
+// startService(intent)
+ bindService(intent, connection, Context.BIND_AUTO_CREATE)
+ }
+
+ private fun moveToNext() {
+ if (supportFragmentManager.isDestroyed)
+ return
+
+ supportFragmentManager.beginTransaction()
+ .replace(binding.flMain.id, HemoCubeFragment()).commit()
+ }
+
+ fun onErrorReported(msg: String) {
+ Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
+// Snackbar.make(binding.clParent, msg, Snackbar.LENGTH_LONG)
+// .setAction("CLOSE") { Toast.makeText(this, "Will soon", Toast.LENGTH_SHORT).show() }
+// .setActionTextColor(resources.getColor(R.color.white))
+// .show()
+
+ if (!isFinishing)
+ onBackPressed()
+ }
+
+ override fun onCreateOptionsMenu(menu: Menu?): Boolean {
+ menuInflater.inflate(R.menu.my_menu, menu)
+// myMenu = menu
+ return true
+ }
+
+// override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
+// R.id.action_usb -> {
+//// Toast.makeText(this, "USB Connected", Toast.LENGTH_SHORT).show()
+//// myMenu?.get(0)?.icon = ContextCompat.getDrawable(this, R.drawable.ic_baseline_usb_off_24)
+// true
+// }
+// else -> {super.onOptionsItemSelected(item)}
+// }
+
+ override fun onDestroy() {
+ super.onDestroy()
+ if (viewModel.isServiceConnected) {
+ mService.disconnect()
+ unbindService(connection)
+ viewModel.isServiceConnected = false
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightActivity.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightActivity.kt
index 5d8e022..d59cf5f 100644
--- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightActivity.kt
+++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightActivity.kt
@@ -131,8 +131,8 @@ class TestRightActivity : AppCompatActivity() {
// return
// }
- viewModel.testDetails?.deviceId = "someslno" //mDriver.device.serialNumber.toString()
- DataHolder.deviceSerialNumber = "someslno" //mDriver.device.serialNumber.toString()
+ viewModel.testDetails?.deviceId = mDriver.device.serialNumber.toString()
+ DataHolder.deviceSerialNumber = mDriver.device.serialNumber.toString()
mConnection = manager.openDevice(mDriver.device)
if (mConnection == null) {
diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpReference.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpReference.kt
index 4c20c6d..00c1605 100644
--- a/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpReference.kt
+++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/TestRightExpReference.kt
@@ -18,6 +18,7 @@ import com.example.hpostesting.presentation.UsbServiceListener
import com.example.hpostesting.presentation.utils.MyDialogListener
import com.example.hpostesting.presentation.utils.UIUtils
import dagger.hilt.android.AndroidEntryPoint
+import dagger.hilt.android.qualifiers.ApplicationContext
import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.FragmentTestRightExpReferenceBinding
diff --git a/app/src/main/java/com/example/hpostesting/presentation/testRight/UsbService.kt b/app/src/main/java/com/example/hpostesting/presentation/testRight/UsbService.kt
index b7aeb54..1189e5d 100644
--- a/app/src/main/java/com/example/hpostesting/presentation/testRight/UsbService.kt
+++ b/app/src/main/java/com/example/hpostesting/presentation/testRight/UsbService.kt
@@ -38,7 +38,8 @@ class UsbService : Service() {
// Todo: Uncomment this
mPort = driver.ports[0] // Most devices have just one port (port 0)
mPort.open(connection)
- mPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
+// mPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
+ mPort.setParameters(9600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
//
isUsbConnected = true
Log.d(TAG, "My Usb Connected ${mPort.driver}")
@@ -113,6 +114,15 @@ class UsbService : Service() {
}
}
+ fun eventDrivenWriteHemoCube(listener: UsbServiceListener) {
+ this.listener = listener
+ try {
+
+ } catch (e: IOException) {
+ listener.onUsbError(e)
+ }
+ }
+
// fun write(command: TestRightCommands){
// mPort.write(command.command.toByteArray(), Constants.WRITE_TIMEOUT_MILLIS)
// }
diff --git a/app/src/main/res/layout/activity_hemocube.xml b/app/src/main/res/layout/activity_hemocube.xml
new file mode 100644
index 0000000..7c1188a
--- /dev/null
+++ b/app/src/main/res/layout/activity_hemocube.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_hemo_cube_reference.xml b/app/src/main/res/layout/fragment_hemo_cube_reference.xml
new file mode 100644
index 0000000..9ca06fe
--- /dev/null
+++ b/app/src/main/res/layout/fragment_hemo_cube_reference.xml
@@ -0,0 +1,134 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 346b4fa..3ade490 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -142,6 +142,7 @@
Settings
Home
+ Show Result
Gallery
Settings
Profile