fixed heart rate test time out issues.
authorTrillGates <williamtrillgates@gmail.com>
Wed, 2 Jun 2021 12:16:27 +0000 (20:16 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Wed, 2 Jun 2021 12:16:27 +0000 (20:16 +0800)
app/IcL02WorkService/release/IcL02WorkService_V59_202105281829_release.apk [deleted file]
app/IcL02WorkService/release/IcL02WorkService_V59_202105291708_release.apk [new file with mode: 0644]
app/IcL02WorkService/release/output.json
app/src/main/java/com/ic/work/hardware/BloodInfoHelper.java
app/src/main/java/com/ic/work/utils/SizeUtils.java [new file with mode: 0644]

diff --git a/app/IcL02WorkService/release/IcL02WorkService_V59_202105281829_release.apk b/app/IcL02WorkService/release/IcL02WorkService_V59_202105281829_release.apk
deleted file mode 100644 (file)
index c97d222..0000000
Binary files a/app/IcL02WorkService/release/IcL02WorkService_V59_202105281829_release.apk and /dev/null differ
diff --git a/app/IcL02WorkService/release/IcL02WorkService_V59_202105291708_release.apk b/app/IcL02WorkService/release/IcL02WorkService_V59_202105291708_release.apk
new file mode 100644 (file)
index 0000000..78c2b37
Binary files /dev/null and b/app/IcL02WorkService/release/IcL02WorkService_V59_202105291708_release.apk differ
index 2646b8c..c2c6b89 100644 (file)
@@ -1 +1 @@
-[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.1","enabled":true,"outputFile":"IcL02WorkService_V59_202105281829_release.apk","fullName":"IcL02WorkServiceRelease","baseName":"IcL02WorkService-release"},"path":"IcL02WorkService_V59_202105281829_release.apk","properties":{}}]
\ No newline at end of file
+[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.1","enabled":true,"outputFile":"IcL02WorkService_V59_202105291708_release.apk","fullName":"IcL02WorkServiceRelease","baseName":"IcL02WorkService-release"},"path":"IcL02WorkService_V59_202105291708_release.apk","properties":{}}]
\ No newline at end of file
index dd9de46..c80e481 100644 (file)
@@ -80,15 +80,33 @@ public class BloodInfoHelper implements SensorEventListener {
             checkCount = 0;
             noWearCount = 0;
             invalidateTime = 0;
-            //TODO:这个是走官方API的,也得有机器再进行修改代码
-            //sendTipsEventBus(BLOOD_PLEASE_QUIET, BLOOD_START_CHECK);
-            // EventBus.getDefault().post(new BloodSensorEvent(1));
+            //加一个超时处理,如果超过30秒没有数据返回
+            //那么就会干掉当前的任务,并且取消监听,重置数据
+            //如果有数据回来,那么就重新设置下一次超时
+            ppgLooper.postDelayed(mTask, TIME_OUT_VALUE);
         } else {
             //这个走JNI获取数据的,完成了
             checkBloodOther();
         }
     }
 
+    //10秒还没有数据回来,那么就结束测试
+    public static final int TIME_OUT_VALUE = 10 * 1000;
+
+    private final Runnable mTask = new Runnable() {
+        @Override
+        public void run() {
+            //超时了
+            //取消监听监听注册
+            mSensorManager.unregisterListener(BloodInfoHelper.this);
+            //结束任务
+            if (mListener != null) {
+                mListener.onHeartRateResult(ndkHigh, ndkLow, ndkHeart, oxygen);
+                mListener.onHeartRateTestFinished();
+            }
+        }
+    };
+
     private Sensor mHeartRate = null;
     private int ndkHeart = 0;
     private int ndkHigh = 0;
@@ -274,7 +292,12 @@ public class BloodInfoHelper implements SensorEventListener {
             doPPGtest();
             /*[0]---心率;[1]---血压高压;[2]---血压低压;[3]---血氧;[4]---佩戴检测(1--脱手,2--上手);*/
             if (checkCount > 10 || invalidateTime > 30) {
+                //结束了,干掉超时任务
+                ppgLooper.removeCallbacks(mTask);
                 handleResult();
+            } else {
+                ppgLooper.removeCallbacks(mTask);
+                ppgLooper.postDelayed(mTask, TIME_OUT_VALUE);
             }
         } else {
             Log.d(TAG, "on sensor change == > PPG= " + values[0]);
diff --git a/app/src/main/java/com/ic/work/utils/SizeUtils.java b/app/src/main/java/com/ic/work/utils/SizeUtils.java
new file mode 100644 (file)
index 0000000..b079ed9
--- /dev/null
@@ -0,0 +1,18 @@
+package com.ic.work.utils;
+
+import android.content.Context;
+
+public class SizeUtils {
+    public static int dip2px(Context context, float dpValue) {
+        float scale = context.getResources().getDisplayMetrics().density;
+        return (int) (dpValue * scale + 0.5f);
+    }
+
+
+    //根据手机分辨率从px转成为dip
+    public static int px2dip(Context context, float pxValue) {
+        //获取当前手机的像素密度
+        final float scale = context.getResources().getDisplayMetrics().density;
+        return (int) (pxValue / scale + 0.5f); //四舍五入取整
+    }
+}
\ No newline at end of file