Oxymeter integration completed
parent
c3ce151a79
commit
0a700270f4
@ -0,0 +1,33 @@
|
||||
class SP20RTParamModel {
|
||||
int battery;
|
||||
bool isCheckProbe;
|
||||
bool isProbeOff;
|
||||
bool isPulseSearching;
|
||||
double pi;
|
||||
int pr;
|
||||
int spo2;
|
||||
|
||||
SP20RTParamModel({this.battery, this.isCheckProbe, this.isProbeOff, this.isPulseSearching, this.pi, this.pr, this.spo2});
|
||||
|
||||
SP20RTParamModel.fromJson(Map<String, dynamic> json) {
|
||||
battery = json['battery'];
|
||||
isCheckProbe = json['isCheckProbe'];
|
||||
isProbeOff = json['isProbeOff'];
|
||||
isPulseSearching = json['isPulseSearching'];
|
||||
pi = json['pi'];
|
||||
pr = json['pr'];
|
||||
spo2 = json['spo2'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['battery'] = this.battery;
|
||||
data['isCheckProbe'] = this.isCheckProbe;
|
||||
data['isProbeOff'] = this.isProbeOff;
|
||||
data['isPulseSearching'] = this.isPulseSearching;
|
||||
data['pi'] = this.pi;
|
||||
data['pr'] = this.pr;
|
||||
data['spo2'] = this.spo2;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
import 'dart:convert';
|
||||
import 'package:diplomaticquarterapp/models/ble_devices/viatom_devices/oxy_sp20_rt_param_model.dart';
|
||||
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';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class SP20PulseTracker extends StatefulWidget {
|
||||
@override
|
||||
State<SP20PulseTracker> createState() => _SP20PulseTrackerState();
|
||||
}
|
||||
|
||||
class _SP20PulseTrackerState extends State<SP20PulseTracker> {
|
||||
EventChannel eventChannel = EventChannel('BLE-Platform-Bridge-Event');
|
||||
|
||||
// final bpDataNotifierMeasuring = ValueNotifier<BpRtDataMeasuringModel>(BpRtDataMeasuringModel());
|
||||
final sp20RtParamNotifier = ValueNotifier<SP20RTParamModel>(SP20RTParamModel());
|
||||
final sp20StatusNotifier = ValueNotifier<String>("");
|
||||
final bpDeviceDataNotifier = ValueNotifier<String>("");
|
||||
String deviceName = "SP20";
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
// bpDataNotifierMeasuring.dispose();
|
||||
sp20RtParamNotifier.dispose();
|
||||
sp20StatusNotifier.dispose();
|
||||
super.dispose();
|
||||
BleChannel.disconnect();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AppScaffold(
|
||||
appBarTitle: "Pulse Tracker",
|
||||
showNewAppBar: true,
|
||||
isShowDecPage: false,
|
||||
showNewAppBarTitle: true,
|
||||
backgroundColor: Color(0xffF8F8F8),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
ValueListenableBuilder(
|
||||
valueListenable: bpDeviceDataNotifier,
|
||||
builder: (context, value, _) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Text(
|
||||
value == null || value.isEmpty ? "" : "Connected",
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
Text(
|
||||
"$value",
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: sp20StatusNotifier,
|
||||
builder: (context, value, _) {
|
||||
if (value == "EventSp20RtParam") {
|
||||
return ValueListenableBuilder(
|
||||
valueListenable: sp20RtParamNotifier,
|
||||
builder: (context, SP20RTParamModel sp20RtModel, _) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
mHeight(24.0),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
if (sp20RtModel.isProbeOff) ...[
|
||||
Text("Check Probe", style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold)),
|
||||
] else ...[
|
||||
Column(
|
||||
children: [
|
||||
Text("SPO₂", style: TextStyle(fontSize: 20)),
|
||||
Text(sp20RtModel.spo2.toString(), style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold)),
|
||||
Text("%", style: TextStyle(fontSize: 10)),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Text("Pulse", style: TextStyle(fontSize: 20)),
|
||||
Text(sp20RtModel.pr.toString(), style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold)),
|
||||
Text("bpm", style: TextStyle(fontSize: 10)),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
Text("PI", style: TextStyle(fontSize: 20)),
|
||||
Text(sp20RtModel.pi.toString(), style: TextStyle(fontSize: 50, fontWeight: FontWeight.bold)),
|
||||
Text("%", style: TextStyle(fontSize: 10)),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
mHeight(24.0),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"Some animation with the instruction",
|
||||
style: TextStyle(fontSize: 9.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: sp20StatusNotifier,
|
||||
builder: (context, value, _) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DefaultButton(
|
||||
"Start Scan",
|
||||
() async {
|
||||
checkBLEPermissions();
|
||||
},
|
||||
textColor: Colors.white,
|
||||
color: Colors.green,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: DefaultButton(
|
||||
"Disconnect with $deviceName",
|
||||
() async {
|
||||
sp20RtParamNotifier.dispose();
|
||||
sp20StatusNotifier.dispose();
|
||||
|
||||
BleChannel.disconnect();
|
||||
},
|
||||
textColor: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void checkBLEPermissions() async {
|
||||
[Permission.location, Permission.storage, Permission.bluetooth, Permission.bluetoothConnect, Permission.bluetoothScan].request().then((status) async {
|
||||
// startBLEConnection();
|
||||
|
||||
eventChannel.receiveBroadcastStream().listen((event) {
|
||||
print('Received event---: $event');
|
||||
print(event['type']);
|
||||
if (event['type'] == "infoData") {
|
||||
sp20StatusNotifier.value = "infoData";
|
||||
bpDeviceDataNotifier.value = event['deviceName'];
|
||||
}
|
||||
|
||||
if (event['type'] == "EventSp20RtParam") {
|
||||
sp20RtParamNotifier.value = SP20RTParamModel.fromJson(json.decode(event['data']));
|
||||
sp20StatusNotifier.value = "EventSp20RtParam";
|
||||
}
|
||||
});
|
||||
await BleChannel.getScanningResult(["Pulse Oxymeter", "SP-20"]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue