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

unlisted

Healthrian visualization support library

example/lib/main.dart

import 'dart:convert';
import 'dart:io';

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';
import 'package:http/http.dart' as http;

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),
            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'),
                  )
                ],
              ),
            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();
                }
              },
            ),
          ],
        ),
      ),
    );
  }
}