|
@@ -6,6 +6,7 @@ import 'package:get/get.dart';
|
|
|
import 'package:vitalapp/managers/interfaces/models/device.dart';
|
|
|
import 'package:vitalapp/pages/medical/controllers/heart.dart';
|
|
|
import 'package:vitalapp/pages/medical/widgets/device_status.dart';
|
|
|
+import 'package:vitalapp/pages/medical/widgets/device_status_position.dart';
|
|
|
import 'package:vitalapp/pages/medical/widgets/ecg_view/index.dart';
|
|
|
import 'package:vnote_device_plugin/consts/types.dart';
|
|
|
import 'package:vnote_device_plugin/devices/heart.dart';
|
|
@@ -35,10 +36,11 @@ class _HeartRateState extends State<HeartRate> {
|
|
|
|
|
|
WorkerStatus _connectStatus = WorkerStatus.connecting;
|
|
|
List<int> ecgPoint = [];
|
|
|
+ int errorCount = 0; //设备重连失败次数
|
|
|
|
|
|
- late String _heart = controller.diagnosisDataValue['Heart']?['HEART'] ?? '';
|
|
|
- late final String _assess =
|
|
|
- controller.diagnosisDataValue['Heart']?['ASSESS'] ?? '';
|
|
|
+ late String _heart =
|
|
|
+ controller.diagnosisDataValue['Heart']?['HEART'].toString() ?? '';
|
|
|
+ late String _assess = controller.diagnosisDataValue['Heart']?['ASSESS'] ?? '';
|
|
|
late final String _ecg = controller.diagnosisDataValue['Heart']?['ECG'] ?? '';
|
|
|
late final String _ecgPoint =
|
|
|
controller.diagnosisDataValue['Heart']?['ECG_POINT'] ?? '';
|
|
@@ -68,6 +70,7 @@ class _HeartRateState extends State<HeartRate> {
|
|
|
worker.hrValueUpdateEvent.removeListener(_onHrValueUpdate);
|
|
|
worker.ecgValueUpdateEvent.removeListener(_onEcgValueUpdate);
|
|
|
worker.resultReceivedEvent.removeListener(_onRCesultReceived);
|
|
|
+ worker.errorEvent.removeListener(_onError);
|
|
|
}
|
|
|
|
|
|
@override
|
|
@@ -84,6 +87,7 @@ class _HeartRateState extends State<HeartRate> {
|
|
|
worker.hrValueUpdateEvent.addListener(_onHrValueUpdate);
|
|
|
worker.ecgValueUpdateEvent.addListener(_onEcgValueUpdate);
|
|
|
worker.resultReceivedEvent.addListener(_onRCesultReceived);
|
|
|
+ worker.errorEvent.addListener(_onError);
|
|
|
worker.connect();
|
|
|
}
|
|
|
|
|
@@ -127,16 +131,35 @@ class _HeartRateState extends State<HeartRate> {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ void _onError(_, String e) {
|
|
|
+ _assess = e;
|
|
|
+ ecgPoint = [];
|
|
|
+ try {
|
|
|
+ EcgViewController ecgViewController = Get.find<EcgViewController>();
|
|
|
+ ecgPoint = [];
|
|
|
+ ecgViewController.reset();
|
|
|
+ } catch (e) {}
|
|
|
+ setState(() {});
|
|
|
+ }
|
|
|
+
|
|
|
void _onRCesultReceived(_, HeartExamResult e) {
|
|
|
setState(() async {
|
|
|
print(ecgPoint.toString());
|
|
|
// _heart = e.toString();
|
|
|
+ _assess = e.analysis.first;
|
|
|
controller.diagnosisDataValue['Heart']?['HEART'] = e.heartRate;
|
|
|
controller.diagnosisDataValue['Heart']?['ASSESS'] = e.analysis.first;
|
|
|
- controller.diagnosisDataValue['Heart']?['ECG'] =
|
|
|
- await createEcgImageBase64(ecgPoint);
|
|
|
- controller.diagnosisDataValue['Heart']?['ECG_POINT'] =
|
|
|
- ecgPoint.toString();
|
|
|
+
|
|
|
+ try {
|
|
|
+ EcgViewController ecgViewController = Get.find<EcgViewController>();
|
|
|
+ controller.diagnosisDataValue['Heart']?['ECG_POINT'] =
|
|
|
+ ecgViewController.allPoints.toString();
|
|
|
+ controller.diagnosisDataValue['Heart']?['ECG'] =
|
|
|
+ await ecgViewController.getFullDataImageBase64();
|
|
|
+ } catch (e) {
|
|
|
+ print(e);
|
|
|
+ }
|
|
|
+ controller.saveCachedRecord();
|
|
|
print(controller.diagnosisDataValue);
|
|
|
// late final String _assess =
|
|
|
// controller.diagnosisDataValue['Heart']?['ASSESS'] ?? '';
|
|
@@ -167,18 +190,30 @@ class _HeartRateState extends State<HeartRate> {
|
|
|
|
|
|
void _onConnectFail(sender, e) {
|
|
|
print('连接设备失败');
|
|
|
- _connectStatus = WorkerStatus.connectionFailed;
|
|
|
- setState(() {});
|
|
|
- }
|
|
|
|
|
|
- void _onConnectSuccess(sender, e) {
|
|
|
- _connectStatus = WorkerStatus.connected;
|
|
|
- setState(() {});
|
|
|
+ if (errorCount < 3) {
|
|
|
+ worker.connect();
|
|
|
+ }
|
|
|
+ setState(() {
|
|
|
+ errorCount++;
|
|
|
+ _connectStatus = WorkerStatus.connectionFailed;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
void _onDisconnected(sender, e) {
|
|
|
print('设备连接中断');
|
|
|
- _connectStatus = WorkerStatus.disconnected;
|
|
|
+
|
|
|
+ if (errorCount < 3) {
|
|
|
+ worker.connect();
|
|
|
+ }
|
|
|
+ setState(() {
|
|
|
+ errorCount++;
|
|
|
+ _connectStatus = WorkerStatus.disconnected;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ void _onConnectSuccess(sender, e) {
|
|
|
+ _connectStatus = WorkerStatus.connected;
|
|
|
setState(() {});
|
|
|
}
|
|
|
|
|
@@ -220,60 +255,100 @@ class _HeartRateState extends State<HeartRate> {
|
|
|
return base64Image;
|
|
|
}
|
|
|
|
|
|
+ /// 需要封装一下
|
|
|
+ Widget _buildErrorButton() {
|
|
|
+ return DeviceStatusPosition(
|
|
|
+ deviceStatus: Row(
|
|
|
+ children: [
|
|
|
+ const Text(
|
|
|
+ '请确认设备是否启动',
|
|
|
+ style: TextStyle(fontSize: 24, color: Colors.red),
|
|
|
+ ),
|
|
|
+ const SizedBox(
|
|
|
+ width: 8,
|
|
|
+ ),
|
|
|
+ IconButton(
|
|
|
+ onPressed: () {
|
|
|
+ worker.connect();
|
|
|
+ setState(() {
|
|
|
+ _connectStatus = WorkerStatus.connecting;
|
|
|
+ errorCount = 0;
|
|
|
+ });
|
|
|
+ },
|
|
|
+ icon: const Icon(Icons.refresh),
|
|
|
+ iconSize: 32,
|
|
|
+ ),
|
|
|
+ const SizedBox(
|
|
|
+ width: 32,
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
- return ExamCard(
|
|
|
- titleText: const SizedBox(),
|
|
|
- // clickCard: () {},
|
|
|
- content: Column(
|
|
|
- mainAxisAlignment: MainAxisAlignment.start,
|
|
|
- children: [
|
|
|
- Padding(
|
|
|
- padding: const EdgeInsets.all(10),
|
|
|
- child: DeviceStatus(connectStatus: _connectStatus)),
|
|
|
- SideBar(
|
|
|
- title: '心率',
|
|
|
- value: _heart.isEmpty ? '--' : _heart,
|
|
|
- unit: '',
|
|
|
- ),
|
|
|
- SizedBox(
|
|
|
- height: 240,
|
|
|
- child: LayoutBuilder(builder: (context, constraints) {
|
|
|
- print(constraints.maxWidth);
|
|
|
- print(constraints.maxHeight);
|
|
|
- return EcgView(
|
|
|
- width: constraints.maxWidth,
|
|
|
- height: constraints.maxHeight,
|
|
|
- );
|
|
|
- }),
|
|
|
- )
|
|
|
- // CustomPaint(
|
|
|
- // painter: GridCanvasPainter(),
|
|
|
- // child: EcgPage(
|
|
|
- // points: ecgPoint,
|
|
|
- // ),
|
|
|
- // ),
|
|
|
- // const Divider(indent: 30),
|
|
|
- // Stack(
|
|
|
- // children: [
|
|
|
- // SideBar(
|
|
|
- // title: '心率评估',
|
|
|
- // value: _assess.isEmpty ? '--' : _assess,
|
|
|
- // hasDevice: true,
|
|
|
- // unit: '',
|
|
|
- // ),
|
|
|
- // // DeviceStatus(connectStatus: _connectStatus),
|
|
|
- // ],
|
|
|
- // ),
|
|
|
- // const Divider(indent: 30),
|
|
|
- // MyWidget()
|
|
|
- // const EcgPage(),
|
|
|
- // SideBar(
|
|
|
- // title: '心电图',
|
|
|
- // value: _assess.isEmpty ? '--' : _assess,
|
|
|
- // unit: '',
|
|
|
- // ),
|
|
|
- ],
|
|
|
- ));
|
|
|
+ return Stack(
|
|
|
+ children: [
|
|
|
+ ExamCard(
|
|
|
+ titleText: const SizedBox(),
|
|
|
+ // clickCard: () {},
|
|
|
+ content: Column(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ SideBar(
|
|
|
+ title: '心率',
|
|
|
+ value: _heart.isEmpty ? '--' : _heart,
|
|
|
+ unit: '',
|
|
|
+ ),
|
|
|
+ if (_assess.isNotEmpty)
|
|
|
+ Row(
|
|
|
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ Container(
|
|
|
+ padding: const EdgeInsets.symmetric(
|
|
|
+ horizontal: 30,
|
|
|
+ ),
|
|
|
+ child: const Text(
|
|
|
+ '心率评估',
|
|
|
+ style: TextStyle(
|
|
|
+ fontSize: 25,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ Container(
|
|
|
+ padding: const EdgeInsets.symmetric(
|
|
|
+ horizontal: 50,
|
|
|
+ ),
|
|
|
+ child: Text(
|
|
|
+ _assess,
|
|
|
+ style: const TextStyle(
|
|
|
+ fontSize: 24,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ],
|
|
|
+ ),
|
|
|
+ SizedBox(
|
|
|
+ height: 240,
|
|
|
+ child: LayoutBuilder(builder: (context, constraints) {
|
|
|
+ print(constraints.maxWidth);
|
|
|
+ print(constraints.maxHeight);
|
|
|
+ return EcgView(
|
|
|
+ width: constraints.maxWidth,
|
|
|
+ height: constraints.maxHeight,
|
|
|
+ );
|
|
|
+ }),
|
|
|
+ )
|
|
|
+ ],
|
|
|
+ )),
|
|
|
+ if (errorCount < 3)
|
|
|
+ DeviceStatusPosition(
|
|
|
+ deviceStatus: DeviceStatus(connectStatus: _connectStatus),
|
|
|
+ ),
|
|
|
+ if (errorCount >= 3) _buildErrorButton(),
|
|
|
+ ],
|
|
|
+ );
|
|
|
}
|
|
|
}
|