healthrian_visualization_support 2.5.1 copy "healthrian_visualization_support: ^2.5.1" to clipboard
healthrian_visualization_support: ^2.5.1 copied to clipboard

unlisted

Healthrian visualization support library

example/lib/main.dart

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
  // void initState() {
  //   super.initState();
  //   // BLEManager().samplingRate = SamplingRate.freq500hz;
  //   // final file = File('20s/30hz.json');
  //   // BLEManager().ecg?.callbacks.add(
  //   //   (
  //   //     (a, b) {
  //   //       final map = {
  //   //         'l1' : a.l1,
  //   //         'l2' : a.l2,
  //   //         'l3' : a.l3,
  //   //         'aVR' : a.aVR,
  //   //         'aVL' : a.aVL,
  //   //         'aVF' : a.aVF,
  //   //         'v1' : a.v1,
  //   //         'v2' : a.v2,
  //   //         'v3' : a.v3,
  //   //         'v4' : a.v4,
  //   //         'v5' : a.v5,
  //   //         'v6' : a.v6,
  //   //       };
  //   //       final mapAsJson = jsonEncode(map);
  //   //       file.writeAsString(mapAsJson);
  //   //       print(DateTime.now());
  //   //     },
  //   //     500 * 20,
  //   //   ),
  //   // );
  // }

  @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),
            Expanded(
              child: SingleChildScrollView(
                child: EcgMonitor(
                  module: _manager.module,
                  // isFiltered: false,
                ),
              ),
            ),
          ],
        ),
        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().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();
                      await usb.BLEManager().disconnectDevice();
                      final samplingRateList = usb.SamplingRate.values;
                      final currentIndex = samplingRateList.indexOf(usb.BLEManager().samplingRate);
                      final nextIndex = (currentIndex + 1) % samplingRateList.length;
                      usb.BLEManager().samplingRate = usb.SamplingRate.values[nextIndex];
                      setState(() {});
                    },
                    backgroundColor: Colors.white,
                    child: Text('${usb.BLEManager().samplingRate.sps}Hz'),
                  )
                ],
              ),
            // FloatingActionButton(
            //   onPressed: () {
            //     FlutterBluePlus.setLogLevel(LogLevel.none);
            //     final random = Random();
            //     final list = List.generate(10000000, (i) =>   random.nextDouble());
            //     print(list.reduce((a, b) => a + b));
            //   },
            // ),
            // FloatingActionButton(
            //   onPressed: () {
            //     BLEManager().module.ecg?.dataFilter?.dcBlock = DcBlock.off;
            //     BLEManager().module.ecg?.dataFilter?.lowPass = LowPass.off;
            //     BLEManager().module.ecg?.dataFilter?.highPass = HighPass.off;
            //     BLEManager().module.ecg?.dataFilter?.bandStop = BandStop.off;
            //   },
            // ),
            // FloatingActionButton(
            //   onPressed: () {
            //     // BLEManager().module.ecg?.resetPlot();
            //     BLEManager().ecg?.dataFilter?.impulseType = ImpulseType.iir;
            //     // print(BLEManager().ecg?.dataFilter?.impulseType );
            //   },
            // ),
            // FloatingActionButton(
            //   onPressed: () {
            //     final dir = Directory('20s_250sps');
            //     for (final file in dir.listSync()) {
            //       if (file is! File) continue;
            //       // if(!file.path.contains('260hz')) continue;
            //       print(file.path);
            //       final dataAsString = file.readAsStringSync();
            //       final dataJson = jsonDecode(dataAsString);
            //       final hr = AdaptiveFilterRT();
            //       final l2 = dataJson['l2'] as List;
            //       final hrList = [];
            //       for (final d in l2) {
            //         final d2 = hr.applyFilter(d)[1];
            //         if (d2 <= 0) continue;
            //         hrList.add(d2);
            //       }
            //       print(hrList);
            //     }
            //   },
            // ),
            // FloatingActionButton(
            //   onPressed: () {
            //     print(BLEManager().module.ecg?.dataFilter?.samplingRate);
            //   },
            // ),
            // FloatingActionButton(
            //   onPressed: () async {
            //     final inDir = Directory('20s');
            //     final outDir = Directory('20s_250sps');
            //     for (final inFile in inDir.listSync()) {
            //       if (inFile is! File) continue;
            //       final outFile = File('${outDir.path}/${inFile.path.split('\\').last}');
            //       final dataAsString = inFile.readAsStringSync();
            //       final dataJson = jsonDecode(dataAsString);
            //       final newMap = <String, dynamic>{};
            //       final keys = ['l1', 'l2', 'l3', 'aVR', 'aVL', 'aVF', 'v1', 'v2', 'v3', 'v4', 'v5', 'v6'];
            //       for (final key in keys) {
            //         newMap[key] =
            //             await Stream.fromIterable(dataJson[key] as List).bufferCount(2).map((e) => e.first).toList();
            //       }
            //       final newMapAsString = jsonEncode(newMap);
            //       outFile.writeAsStringSync(newMapAsString);
            //     }
            //   },
            // ),
          ],
        ),
      ),
    );
  }
}