Browse Source

1、心电去除前三秒的数据

guanxinyi 1 year ago
parent
commit
377511dfe0
1 changed files with 4 additions and 30 deletions
  1. 4 30
      lib/pages/medical/widgets/heart_rate.dart

+ 4 - 30
lib/pages/medical/widgets/heart_rate.dart

@@ -1,6 +1,5 @@
 import 'dart:async';
 import 'dart:convert';
-import 'dart:math';
 
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
@@ -47,37 +46,9 @@ class _HeartRateState extends State<HeartRate> {
   @override
   void initState() {
     initHeart();
-    // mockECG();
     super.initState();
   }
 
-  void mockECG() {
-    Random random = Random();
-    int min = -125;
-    int max = 125;
-    int time = 1;
-    int duration = 500 + random.nextInt(501); // 生成500到1000之间的随机持续时间
-
-    Timer.periodic(Duration(milliseconds: duration), (timer) {
-      if (time > 1) {
-        timer.cancel(); // 取消定时器
-      } else {
-        time++;
-        List<int> data = [];
-        for (int i = 0; i < 160; i++) {
-          int value = min + random.nextInt(max - min + 1); // 生成125到200之间的随机整数
-          data.add(value);
-        }
-        try {
-          EcgViewController ecgViewController = Get.find<EcgViewController>();
-          ecgViewController.addData(data);
-        } catch (e) {
-          print(e);
-        }
-      }
-    });
-  }
-
   Future<void> connect() async {
     await worker.connect();
   }
@@ -179,7 +150,10 @@ class _HeartRateState extends State<HeartRate> {
   void _onEcgValueUpdate(_, List<int> e) {
     try {
       EcgViewController ecgViewController = Get.find<EcgViewController>();
-      ecgViewController.addData(e);
+      ecgPoint.addAll(e);
+      if (ecgPoint.length > 125 * 3) {
+        ecgViewController.addData(e);
+      }
     } catch (e) {
       print(e);
     }