diff --git a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/ble/BleBridge.kt b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/ble/BleBridge.kt index 87ac63b5..b6be1fd6 100644 --- a/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/ble/BleBridge.kt +++ b/android/app/src/main/kotlin/com/cloud/diplomaticquarterapp/ble/BleBridge.kt @@ -1,5 +1,6 @@ package com.ejada.hmg.utils +import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.content.Intent.getIntent @@ -26,6 +27,7 @@ import com.lepu.blepro.event.EventMsgConst import com.lepu.blepro.event.EventMsgConst.Ble.* import com.lepu.blepro.event.InterfaceEvent import com.lepu.blepro.ext.BleServiceHelper +import com.lepu.blepro.ext.er2.DeviceInfo import com.lepu.blepro.ext.pc60fw.RtParam import com.lepu.blepro.objs.Bluetooth import com.lepu.blepro.objs.BluetoothController @@ -45,6 +47,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 SCAN_DEVICE_EKG = "scan_ekg" private const val DISCONNECT_DEVICE = "disconnect_device" } @@ -126,6 +129,7 @@ class BleBridge( } } + @SuppressLint("NewApi") fun create() { channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL) Echannel = EventChannel(flutterEngine.dartExecutor.binaryMessenger, EVENTCHANNEL) @@ -135,6 +139,8 @@ class BleBridge( scanDevice(methodCall, result) } else if (methodCall.method == DISCONNECT_DEVICE) { disconnectDevice(methodCall, result) + } else if (methodCall.method == SCAN_DEVICE_EKG) { + scanDeviceEKG(methodCall, result) } else { result.notImplemented() } @@ -175,7 +181,7 @@ class BleBridge( if (b.name.contains("POD-1_SN8187", true) || b.name.contains( "O2M 1670", true - ) + ) || b.name.contains("DuoEK", true) ) { model = b.model deviceName = b.name @@ -201,6 +207,30 @@ class BleBridge( } } + if (deviceName.contains("DuoEK", ignoreCase = true)) { + LiveEventBus.get(InterfaceEvent.ER2.EventEr2Info) + .observe(this.mainActivity) { + val data = it.data as DeviceInfo + println("DuoEK INFO DATA: $data") + } + LiveEventBus.get(InterfaceEvent.ER2.EventEr2FileList) + .observe(this.mainActivity) { + val fileNames = it.data as ArrayList + println("DuoEK FileNames List: $fileNames") + eventSink?.success(fileNames.toString()) + } + + LiveEventBus.get(InterfaceEvent.ER2.EventEr2SetTime) + .observe(this.mainActivity) { + println("EventEr2SetTime") + // Get Device Info + BleServiceHelper.BleServiceHelper.er2GetInfo(model) + + //Get EKG File List + BleServiceHelper.BleServiceHelper.er2GetFileList(model) + } + } + if (deviceName == "O2M 1670") { rtHandler.removeCallbacks(rtTask) rtHandler.post(rtTask) @@ -232,4 +262,65 @@ class BleBridge( } } + fun scanDeviceEKG(methodCall: MethodCall, result: MethodChannel.Result) { + println("This is Test of Scanning EKG Device") + + LiveEventBus.get(EventMsgConst.Ble.EventServiceConnectedAndInterfaceInit) + .observe(this.mainActivity) { + // BleService init success + println("EventServiceConnectedAndInterfaceInit---------") + BleServiceHelper.BleServiceHelper.startScan(models) + println("EventServiceConnectedAndInterfaceInit") + } + + LiveEventBus.get(EventMsgConst.Discovery.EventDeviceFound) + .observe(this.mainActivity) { + var deviceName: String = "" + + for (b in BluetoothController.getDevices()) { + if (b.name.contains("DuoEK", true) + ) { + model = b.model + deviceName = b.name + BleServiceHelper.BleServiceHelper.setInterfaces(b.model) + BleServiceHelper.BleServiceHelper.stopScan() + BleServiceHelper.BleServiceHelper.connect( + this.mainActivity.applicationContext, + b.model, + b.device + ) + } + } + println("EventDeviceFound") + println(deviceName) + + if (deviceName.contains("DuoEK", ignoreCase = true)) { + LiveEventBus.get(InterfaceEvent.ER2.EventEr2Info) + .observe(this.mainActivity) { + val data = it.data as DeviceInfo + println("DuoEK INFO DATA: $data") + } + LiveEventBus.get(InterfaceEvent.ER2.EventEr2FileList) + .observe(this.mainActivity) { + val fileNames = it.data as ArrayList + println("DuoEK FileNames List: $fileNames") + eventSink?.success(fileNames.toString()) + } + + LiveEventBus.get(InterfaceEvent.ER2.EventEr2SetTime) + .observe(this.mainActivity) { + println("EventEr2SetTime") + // Get Device Info + BleServiceHelper.BleServiceHelper.er2GetInfo(model) + + //Get EKG File List + BleServiceHelper.BleServiceHelper.er2GetFileList(model) + } + } + + } + + + } + } \ No newline at end of file diff --git a/lib/pages/landing/landing_page.dart b/lib/pages/landing/landing_page.dart index c2e2111a..0b478007 100644 --- a/lib/pages/landing/landing_page.dart +++ b/lib/pages/landing/landing_page.dart @@ -570,8 +570,8 @@ class _LandingPageState extends State with WidgetsBindingObserver { changeCurrentTab(1); }, onLoginClick: () { - // login(); - Navigator.push(context, FadePage(page: Oxymeter_BLE())); + login(); + // Navigator.push(context, FadePage(page: Oxymeter_BLE())); }, onMedicalFileClick: () { changeCurrentTab(1); diff --git a/lib/pages/medical/my_trackers/my_trackers.dart b/lib/pages/medical/my_trackers/my_trackers.dart index 3d16b18a..7f37a0fd 100644 --- a/lib/pages/medical/my_trackers/my_trackers.dart +++ b/lib/pages/medical/my_trackers/my_trackers.dart @@ -6,6 +6,7 @@ import 'package:diplomaticquarterapp/pages/medical/my_trackers/blood_suger/blood import 'package:diplomaticquarterapp/pages/medical/my_trackers/ecg_ble.dart'; import 'package:diplomaticquarterapp/pages/medical/my_trackers/spirometer.dart'; import 'package:diplomaticquarterapp/pages/medical/my_trackers/temperature.dart'; +import 'package:diplomaticquarterapp/pages/medical/my_trackers/viatom_devices/ekg_tracker_ble.dart'; import 'package:diplomaticquarterapp/pages/medical/my_trackers/viatom_devices/oxymeter_ble.dart'; import 'package:diplomaticquarterapp/pages/medical/my_trackers/weight_scale_ble.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; @@ -168,6 +169,19 @@ class MyTrackers extends StatelessWidget { height: 45.0, ), ), + InkWell( + onTap: () { + Navigator.push(context, FadePage(page: EKG_BLE())); + }, + child: MedicalProfileItem( + title: "EKG BLE", + imagePath: 'assets/tracker/weight.png', + subTitle: null, + isPngImage: true, + width: 45.0, + height: 45.0, + ), + ), ], ), ), diff --git a/lib/pages/medical/my_trackers/viatom_devices/ekg_tracker_ble.dart b/lib/pages/medical/my_trackers/viatom_devices/ekg_tracker_ble.dart new file mode 100644 index 00000000..6f05e108 --- /dev/null +++ b/lib/pages/medical/my_trackers/viatom_devices/ekg_tracker_ble.dart @@ -0,0 +1,115 @@ +import 'package:diplomaticquarterapp/uitl/utils_new.dart'; +import 'package:diplomaticquarterapp/viatom_ble/ble_connect.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class EKG_BLE extends StatefulWidget { + const EKG_BLE(); + + @override + State createState() => _EKG_BLEState(); +} + +class _EKG_BLEState extends State { + EventChannel eventChannel = EventChannel('BLE-Platform-Bridge-Event'); + String receivedData = ''; + + final ekgValueNotifier = ValueNotifier("start"); + + @override + void dispose() { + ekgValueNotifier.dispose(); + super.dispose(); + BleChannel.disconnect(); + } + + @override + void initState() { + // TODO: implement initState + super.initState(); + + eventChannel.receiveBroadcastStream().listen((event) { + print('Received event---: $event'); + ekgValueNotifier.value = event; + }); + + } + + @override + Widget build(BuildContext context) { + return AppScaffold( + appBarTitle: "EKG Tracker", + showNewAppBar: true, + isShowDecPage: false, + showNewAppBarTitle: true, + backgroundColor: Color(0xffF8F8F8), + body: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(24.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Expanded( + child: DefaultButton( + "Get Info", + () async { + await BleChannel.getScanningResultEKG(["oximeter", "ekg"]); + }, + textColor: Colors.white, + ), + ), + mWidth(16.0), + Expanded( + child: DefaultButton( + "Get Files List", + () {}, + textColor: Colors.white, + ), + ), + ], + ), + mHeight(50.0), + ValueListenableBuilder( + valueListenable: ekgValueNotifier, + builder: (context, value, _) { + return Text(value); + // ? Platform.isAndroid + // ? Column( + // children: [ + // Text( + // getSPO2( + // value.toString().replaceAll("RtParam", ""), + // ), + // ), + // Text( + // getPR( + // value.toString().replaceAll("RtParam", ""), + // ), + // ), + // // Text( + // // getPI( + // // value.toString().replaceAll("RtParam", ""), + // // ), + // // ), + // ], + // ) + // : Column( + // children: [ + // Text(getSPO2iOS(value.toString())), + // Text(getPRiOS(value.toString())), + // ], + // ) + // : Text(value); + }, + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/viatom_ble/ble_connect.dart b/lib/viatom_ble/ble_connect.dart index d25b59c5..60f0902f 100644 --- a/lib/viatom_ble/ble_connect.dart +++ b/lib/viatom_ble/ble_connect.dart @@ -17,6 +17,18 @@ class BleChannel { } } + static Future getScanningResultEKG(List deviceType) async { + try { + print("----------Flutter Init -------"); + final String result = await platform.invokeMethod('scan_ekg', deviceType); + print("----------Flutter Result -------"); + print(result); + return result; + } catch (e) { + return "Error: $e"; + } + } + static Future disconnect() async { try { print("----------Flutter Init -------");