healthrian_visualization_support 2.7.11
healthrian_visualization_support: ^2.7.11 copied to clipboard
Healthrian visualization support library
example/lib/main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:healthrian_ble_support_for_cardio_em/healthrian_ble_support_for_cardio_em.dart' as ble;
import 'package:healthrian_ble_support_for_cardio_em_cdc/healthrian_ble_support_for_cardio_em_cdc.dart' as usb;
import 'package:healthrian_visualization_support/healthrian_visualization_support.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) => const MaterialApp(home: MyHomePage());
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
ble.ManagerInterface _manager = ble.BLEManager();
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Column(
children: [
ConnectionMonitor(module: _manager.module),
HeartRateMonitor(module: _manager.module, isUsingMean: false),
LeadstateMonitor(module: _manager.module),
SamplingRateMonitor(module: _manager.module),
EcgMonitor(module: _manager.module, isHeartRate: true),
Expanded(
child: SingleChildScrollView(
child: EcgMonitor(module: _manager.module),
),
),
],
),
floatingActionButton: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ControlPanel(module: _manager.module),
SizedBox(height: 10),
FloatingActionButton(
onPressed: () {
if (_manager is ble.BLEManager) {
_manager = usb.BLEManager();
usb.BLEManager().module.ecg?.samplingRate = usb.SamplingRate.freq500hz;
setState(() {});
return;
}
if (_manager is usb.BLEManager) {
_manager = ble.BLEManager();
setState(() {});
return;
}
},
backgroundColor: Colors.white,
child: Icon(
_manager is usb.BLEManager ? Icons.usb : Icons.bluetooth_audio_rounded,
color: _manager is usb.BLEManager ? Colors.black : Colors.blueAccent,
),
),
if (_manager is usb.BLEManager)
Column(
children: [
SizedBox(height: 10),
FloatingActionButton(
onPressed: () async {
await usb.BLEManager().stopMeasurement();
final samplingRateList = usb.SamplingRate.values;
final currentIndex = samplingRateList
.indexOf(usb.BLEManager().module.ecg?.samplingRate ?? usb.SamplingRate.freq500hz);
final nextIndex = (currentIndex + 1) % samplingRateList.length;
usb.BLEManager().module.ecg?.samplingRate = usb.SamplingRate.values[nextIndex];
setState(() {});
},
backgroundColor: Colors.white,
child: Text('${usb.BLEManager().module.ecg?.samplingRate.sps}Hz'),
)
],
),
if (_manager is ble.BLEManager)
Column(
children: [
SizedBox(height: 10),
FloatingActionButton(
onPressed: () async {
await ble.BLEManager().stopMeasurement();
final samplingRateList = ble.SamplingRate.values;
final currentIndex = samplingRateList
.indexOf(ble.BLEManager().module.ecg?.samplingRate ?? ble.SamplingRate.freq500hz);
final nextIndex = (currentIndex + 1) % samplingRateList.length;
ble.BLEManager().module.ecg?.samplingRate = usb.SamplingRate.values[nextIndex];
setState(() {});
},
backgroundColor: Colors.white,
child: Text(
'${ble.BLEManager().module.ecg?.samplingRate.sps}Hz',
style: TextStyle(color: Colors.blueAccent),
),
)
],
),
// SizedBox(height: 10),
// FloatingActionButton(
// onPressed: () async {
// _subscription?.cancel();
// for (var i = 0; i < 100; i++) {
// final file = File(
// 'ECG-PACKET-$i-${DateTime.now().toIso8601String().replaceAll(':', '-').split('.').first}.txt');
// _subscription = _manager.ble.streams.ecg.meta.raw?.listen((event) {
// file.writeAsStringSync('$event\n', mode: FileMode.writeOnlyAppend);
// });
// await Future.delayed(Duration(seconds: 30));
// _subscription?.cancel();
// print(file.path);
// }
// },
// child: Icon(Icons.emergency_recording),
// ),
// SizedBox(height: 10),
// FloatingActionButton(
// onPressed: () async {
// final dbs = [
// 'CTSCSE_CAL10000',
// 'CTSCSE_CAL20000',
// 'CTSCSE_CAL20110',
// 'CTSCSE_CAL20210',
// 'CTSCSE_CAL20160',
// 'CTSCSE_CAL20260',
// ];
// for (final db in dbs) {
// _manager.ecg?.callbacks.clear();
// _manager.ecg?.callbacks.add(
// (
// (ecg, filter) {
// final file = File('$db.json');
// final map = {
// 'l1': ecg.l1,
// 'l2': ecg.l2,
// 'l3': ecg.l3,
// 'aVR': ecg.aVR,
// 'aVL': ecg.aVL,
// 'aVF': ecg.aVF,
// 'v1': ecg.v1,
// 'v2': ecg.v2,
// 'v3': ecg.v3,
// 'v4': ecg.v4,
// 'v5': ecg.v5,
// 'v6': ecg.v6,
// };
// final mapAsJson = jsonEncode(map);
// file.writeAsString(mapAsJson);
// print(DateTime.now());
// },
// 250 * 20,
// ),
// );
//
// final url = Uri.parse('http://127.0.0.1:20001/jsonrpc');
// final body = {
// "id": 2,
// "jsonrpc": "2.0",
// "method": "load_db",
// "params": [
// {
// "db": db,
// "noise": "CTSCSENoise_MAX",
// }
// ]
// };
// final response = await http.post(
// url,
// body: jsonEncode(body),
// );
// print(response.body);
//
// await _manager.startMeasurement();
//
// await Future.delayed(const Duration(seconds: 22));
//
// await _manager.stopMeasurement();
// }
// },
// ),
],
),
),
);
}
}