healthrian_usb_support 1.4.2 copy "healthrian_usb_support: ^1.4.2" to clipboard
healthrian_usb_support: ^1.4.2 copied to clipboard

PlatformAndroid

Healthrian usb support library for connecting health monitoring devices via USB

example/lib/main.dart

import 'dart:convert';

import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
import 'package:healthrian_usb_support/healthrian_usb_support.dart';

Future<void> main() async {
  await usb.waitForCompletion();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
    usb.onProgressChanged = (progress, [data]) => print((progress, data));
  }

  final _channelsFromReadFile = <String, List<double>>{};
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Text('${usb.isRooted}'),
          Expanded(
            child: ListView(
              children: [
                for (final label in [
                  'l1',
                  'l2',
                  'l3',
                  'aVR',
                  'aVL',
                  'aVF',
                  'v1',
                  'v2',
                  'v3',
                  'v4',
                  'v5',
                  'v6'
                ])
                  SingleChildScrollView(
                    scrollDirection: Axis.horizontal,
                    child: Row(
                      children: [
                        SizedBox(
                          width: 1800,
                          height: 120,
                          child: LineChart(
                            LineChartData(
                              minY: -3,
                              maxY: 3,
                              titlesData: const FlTitlesData(show: false),
                              lineTouchData:
                                  const LineTouchData(enabled: false),
                              lineBarsData: [
                                LineChartBarData(
                                  dotData: const FlDotData(show: false),
                                  spots: List.generate(
                                    _channelsFromReadFile[label]?.length ?? 0,
                                    (i) => FlSpot(
                                      i.toDouble(),
                                      _channelsFromReadFile[label]![i]
                                          .toDouble(),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
              ],
            ),
          ),
        ],
      ),
      floatingActionButton: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          FloatingActionButton(
            onPressed: () async {
              print(await usb.getDeviceList());
            },
            child: const Text('FW'),
          ),
          FloatingActionButton(
            onPressed: () async {
              print(await usb.erasePatientInfo(deviceIndex: 0));
            },
            child: const Text('EP'),
          ),
          FloatingActionButton(
            onPressed: () async {
              print(await usb.setPatientInfo(
                deviceIndex: 0,
                firstName: 'abbb',
                lastName: 'b',
                age: 22,
                gender: 0,
                birth: '2002-11-11',
                height: 0.0,
                weight: 0.0,
                physician: 'physician',
                socialNumber: '123-123',
                patientId: '123-123-123',
              ));
            },
            child: const Text('S'),
          ),
          FloatingActionButton(
            onPressed: () async {
              print(jsonEncode(await usb.readPatientInfo(deviceIndex: 0)));
            },
            child: const Text('R'),
          ),
          FloatingActionButton(
            onPressed: () async {
              print(await usb.getFileState(deviceIndex: 0));
            },
            child: const Text('FS'),
          ),
          FloatingActionButton(
            onPressed: () async {
              final stream = usb.readFile(deviceIndex: 0, fileIndex: 0);
              final stopwatch = Stopwatch();
              stopwatch.start();
              _channelsFromReadFile.clear();
              try{
                await for (final event in stream) {
                  for (final entry in event.entries) {
                    final key = entry.key;
                    _channelsFromReadFile[key] ??= <double>[];
                    _channelsFromReadFile[key]!.addAll(entry.value);
                  }
                }
              } catch (e) {
                print(e);
              }
              stopwatch.stop();
              print('Read Finished');
              print(stopwatch.elapsed);
              setState(() {});
            },
            child: const Text('RF'),
          ),
          FloatingActionButton(
            onPressed: () async {
              print(await usb.eraseMemory(deviceIndex: 0));
            },
            child: const Text('EM'),
          ),
          FloatingActionButton(
            onPressed: () async {
              print(await usb.resetDevice(deviceIndex: 0));
            },
            child: const Text('RD'),
          ),
        ],
      ),
    );
  }
}
0
likes
105
points
30
downloads

Publisher

unverified uploader

Weekly Downloads

Healthrian usb support library for connecting health monitoring devices via USB

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_libserialport, healthrian_common_support, mobx, usb_serial

More

Packages that depend on healthrian_usb_support