|
|
|
|
@ -6,6 +6,7 @@ import android.content.Intent.getIntent
|
|
|
|
|
import android.net.Uri
|
|
|
|
|
import android.os.Build
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.os.Handler
|
|
|
|
|
import android.provider.Settings
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.core.app.ActivityCompat.startActivityForResult
|
|
|
|
|
@ -15,6 +16,7 @@ import io.flutter.plugin.common.MethodCall
|
|
|
|
|
import io.flutter.plugin.common.MethodChannel
|
|
|
|
|
import io.flutter.plugin.common.EventChannel
|
|
|
|
|
import android.util.SparseArray
|
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Ble
|
|
|
|
|
@ -43,6 +45,7 @@ class BleBridge(
|
|
|
|
|
private const val CHANNEL = "BLE-Platform-Bridge"
|
|
|
|
|
private const val EVENTCHANNEL = "BLE-Platform-Bridge-Event"
|
|
|
|
|
private const val SCAN_DEVICE = "scan"
|
|
|
|
|
private const val DISCONNECT_DEVICE = "disconnect_device"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -107,6 +110,22 @@ class BleBridge(
|
|
|
|
|
|
|
|
|
|
private var list = arrayListOf<Bluetooth>()
|
|
|
|
|
|
|
|
|
|
private var model = Bluetooth.MODEL_O2RING
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* PS: O2 devices do not support processing multiple commands.
|
|
|
|
|
* If you want to use other command and start rtTask, you must stop rtTask.
|
|
|
|
|
*/
|
|
|
|
|
private var rtHandler = Handler()
|
|
|
|
|
private var rtTask = RtTask()
|
|
|
|
|
|
|
|
|
|
inner class RtTask : Runnable {
|
|
|
|
|
override fun run() {
|
|
|
|
|
rtHandler.postDelayed(rtTask, 1000)
|
|
|
|
|
BleServiceHelper.BleServiceHelper.oxyGetRtParam(model)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun create() {
|
|
|
|
|
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
|
|
|
|
|
Echannel = EventChannel(flutterEngine.dartExecutor.binaryMessenger, EVENTCHANNEL)
|
|
|
|
|
@ -114,6 +133,8 @@ class BleBridge(
|
|
|
|
|
|
|
|
|
|
if (methodCall.method == SCAN_DEVICE) {
|
|
|
|
|
scanDevice(methodCall, result)
|
|
|
|
|
} else if (methodCall.method == DISCONNECT_DEVICE) {
|
|
|
|
|
disconnectDevice(methodCall, result)
|
|
|
|
|
} else {
|
|
|
|
|
result.notImplemented()
|
|
|
|
|
}
|
|
|
|
|
@ -130,6 +151,12 @@ class BleBridge(
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequiresApi(Build.VERSION_CODES.Q)
|
|
|
|
|
fun disconnectDevice(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
|
if (rtHandler.hasCallbacks(rtTask)) rtHandler.removeCallbacks(rtTask)
|
|
|
|
|
BleServiceHelper.BleServiceHelper.disconnect(false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun scanDevice(methodCall: MethodCall, result: MethodChannel.Result) {
|
|
|
|
|
|
|
|
|
|
println("This is Test of Scanning")
|
|
|
|
|
@ -145,7 +172,12 @@ class BleBridge(
|
|
|
|
|
var deviceName: String = ""
|
|
|
|
|
for (b in BluetoothController.getDevices()) {
|
|
|
|
|
// println(b.name)
|
|
|
|
|
if (b.name.contains("POD-1_SN8187", true)) {
|
|
|
|
|
if (b.name.contains("POD-1_SN8187", true) || b.name.contains(
|
|
|
|
|
"O2M 1670",
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
model = b.model
|
|
|
|
|
deviceName = b.name
|
|
|
|
|
BleServiceHelper.BleServiceHelper.setInterfaces(b.model)
|
|
|
|
|
BleServiceHelper.BleServiceHelper.stopScan()
|
|
|
|
|
@ -159,13 +191,34 @@ class BleBridge(
|
|
|
|
|
|
|
|
|
|
println("EventDeviceFound")
|
|
|
|
|
println(deviceName)
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.PC60Fw.EventPC60FwRtParam)
|
|
|
|
|
.observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as RtParam
|
|
|
|
|
println("OXY DATA: $data")
|
|
|
|
|
eventSink?.success(data.toString())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deviceName == "POD-1_SN8187") {
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.PC60Fw.EventPC60FwRtParam)
|
|
|
|
|
.observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as RtParam
|
|
|
|
|
println("OXY DATA POD-1W: $data")
|
|
|
|
|
eventSink?.success(data.toString())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deviceName == "O2M 1670") {
|
|
|
|
|
rtHandler.removeCallbacks(rtTask)
|
|
|
|
|
rtHandler.post(rtTask)
|
|
|
|
|
|
|
|
|
|
LiveEventBus.get<InterfaceEvent>(InterfaceEvent.Oxy.EventOxyRtParamData)
|
|
|
|
|
.observe(this.mainActivity) {
|
|
|
|
|
val data = it.data as com.lepu.blepro.ext.oxy.RtParam
|
|
|
|
|
println("OXY DATA O2M: $data")
|
|
|
|
|
eventSink?.success(data.toString())
|
|
|
|
|
// tv_oxy.text = data.spo2.toString()
|
|
|
|
|
// tv_pr.text = data.pr.toString()
|
|
|
|
|
// tv_pi.text = data.pi.toString()
|
|
|
|
|
// data_log.text = "$data"
|
|
|
|
|
// data.battery:0-100
|
|
|
|
|
// data.batteryState:0(no charge),1(charging),2(charging complete)
|
|
|
|
|
// data.state:0(lead off),1(lead on),other(error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|