aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/arslaancodes/zwznfreefit/DeviceActivity.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/arslaancodes/zwznfreefit/DeviceActivity.kt')
-rw-r--r--app/src/main/java/com/arslaancodes/zwznfreefit/DeviceActivity.kt73
1 files changed, 73 insertions, 0 deletions
diff --git a/app/src/main/java/com/arslaancodes/zwznfreefit/DeviceActivity.kt b/app/src/main/java/com/arslaancodes/zwznfreefit/DeviceActivity.kt
new file mode 100644
index 0000000..38862bd
--- /dev/null
+++ b/app/src/main/java/com/arslaancodes/zwznfreefit/DeviceActivity.kt
@@ -0,0 +1,73 @@
+package com.arslaancodes.zwznfreefit
+
+import android.bluetooth.BluetoothAdapter
+import android.os.Bundle
+import android.widget.TextView
+import android.widget.Button
+import androidx.appcompat.app.AppCompatActivity
+
+class DeviceActivity : AppCompatActivity() {
+ private lateinit var statusText: TextView
+ private val handler = android.os.Handler(android.os.Looper.getMainLooper())
+ private val syncRunnable = object : Runnable {
+ override fun run() {
+ BleManager.instance.syncTime()
+ handler.postDelayed(this, 5 * 60 * 1000)
+ }
+ }
+
+ override fun onResume() {
+ super.onResume()
+ handler.post(syncRunnable)
+ }
+
+ override fun onPause() {
+ super.onPause()
+ handler.removeCallbacks(syncRunnable)
+ }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_device)
+ window.decorView.systemUiVisibility = (
+ android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ or android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
+ )
+
+ val address = intent.getStringExtra("device_address")
+ val device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(address)
+
+ statusText = findViewById(R.id.deviceStatusText)
+ statusText.text = "Connected to: ${device.name ?: device.address}"
+ BleManager.instance.syncTime();
+ findViewById<Button>(R.id.syncTimeButton).setOnClickListener {
+ BleManager.instance.syncTime()
+ }
+
+ findViewById<Button>(R.id.findBandButton).setOnClickListener {
+ BleManager.instance.switchFindBand(0x01)
+ }
+
+ findViewById<Button>(R.id.stopFindBandButton).setOnClickListener {
+ BleManager.instance.switchFindBand(0x00)
+ }
+
+ findViewById<Button>(R.id.configRealTimeMeasureHeartRateButton).setOnClickListener {
+ BleManager.instance.configRealTimeMeasure(0x00, true, { data ->
+ runOnUiThread {
+ if (data[0] == 0x94.toByte()) {
+ val heartRate = data[1].toInt() and 0xFF
+ statusText.text = "Got generic measurement ${heartRate}"
+ }
+ if (data[0] == 0xE1.toByte()) {
+ val rate1 = data[1].toInt() and 0xFF
+ val rate2 = data[5].toInt() and 0xFF
+ val rate3 = data[6].toInt() and 0xFF
+ val rate4 = data[7].toInt() and 0xFF
+ statusText.text = "Got aggregate rates ${rate1}, ${rate2}, ${rate3}, ${rate4}"
+ }
+ }
+ })
+ }
+ }
+}