callibri_ecg 1.0.3 copy "callibri_ecg: ^1.0.3" to clipboard
callibri_ecg: ^1.0.3 copied to clipboard

Flutter wrapper for CallibriECG library

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:callibri_ecg/callibri_ecg.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late final CallibriEcgMath math;

  @override
  void initState() {
    super.initState();

    int samplingRate = 500;
    int dataWindow = samplingRate ~/ 2;
    int nWinsForPressureIndex = 30;
    math = CallibriEcgMath(samplingRate, dataWindow, nWinsForPressureIndex);    
  }

  @override
  void dispose() {
    super.dispose();
    math.dispose();
  }

  void run() {
    final samples = List<double>.generate(100, (i) => i * 0.006);
    math.pushAndProcess(samples);
    if(math.isRRDetected){
      // check for a new peak in the signal
      // RR-interval length
      double rr = math.rr;
      // last RP index
      int rpIdx = math.lastRPeakIndex;
      // HR     
      double hr = math.hr;
      // SI
      double pi = math.pressureIndex;
      // Moda
      double moda = math.moda;
      // Amplitude of mode
      double amplModa = math.amplitudeModa;
      // Variation range
      double variationDist = math.variationDistance;
      math.checkRR();
    }

    math.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: ElevatedButton(
            onPressed: run,
            child: const Text("Run"),
          ),
        ),
      ),
    );
  }
}