fixed bugs that looper to death
authorkfl_614 <kfl_614@163.com>
Wed, 6 Jan 2021 07:36:52 +0000 (15:36 +0800)
committerkfl_614 <kfl_614@163.com>
Wed, 6 Jan 2021 07:36:52 +0000 (15:36 +0800)
app/src/main/java/com/ic/work/SensorDataService.java
app/src/main/java/com/ic/work/hardware/BloodInfoHelper.java

index 3e84414..865d1bb 100644 (file)
@@ -425,6 +425,10 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp
         HeartRate heartRate = new HeartRate(high, low, heart, oxygen);
         //遍历集合,通知一次内容
         dispatchHeartRateResult(heartRate);
+        if (heart == 0) {
+            //不通知UI了
+            return;
+        }
         //发送一次广播给 心率 launcher
         sendHeartBroadcast(heart, oxygen);
     }
@@ -624,6 +628,14 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp
 
     @Override
     public void onHeartRateResult(int high, int low, int heart, int oxygen) {
+        handleBloodResult(high, low, heart, oxygen);
+        IcLog.d(TAG, "high == > " + high);
+        IcLog.d(TAG, "low == > " + low);
+        IcLog.d(TAG, "heart == > " + heart);
+        IcLog.d(TAG, "oxygen == > " + oxygen);
+        if (heart == 0) {
+            return;
+        }
         //处理心率测量数据给掌育的
         //发广播给掌育,如果不为-1,说明有掌育的份
         IcLog.d(TAG, "jxHeartRateMode..." + jxHeartRateMode);
@@ -636,7 +648,6 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp
             jxHeartRateMode = -1;
         }
         //reset data.
-        handleBloodResult(high, low, heart, oxygen);
         IcLog.d(TAG, "on blood test end...");
         //checkContinue();
         // 心率有一个方去结束
index c5d071d..b4b4b82 100644 (file)
@@ -84,6 +84,7 @@ public class BloodInfoHelper {
 
         sendTipsEventBus(BLOOD_PLEASE_QUIET, BLOOD_START_CHECK);
 
+        int invalidateTime = 0;
         try {
             while (!Thread.currentThread().isInterrupted()) {
                 ndkHeart = HardwareUtils.getNdkPPGValue();
@@ -111,8 +112,10 @@ public class BloodInfoHelper {
                             break;
                         }
                         checkCount++;
+                    } else {
+                        //如果为0的话,记录下来
+                        invalidateTime++;
                     }
-
                     if (!isSendCheckTips) {
                         //正在测量中,请稍等
                         sendTipsEventBus(BLOOD_PLEASE_QUIET, BLOOD_ING_CHECK);
@@ -120,16 +123,13 @@ public class BloodInfoHelper {
                     }
                 }
                 Thread.sleep(1000);
-            }
-            if (noWearCount >= 5) {
-                //sendTipsEventBus(BLOOD_NULL_TIPS, BLOOD_NOT_WEAR);
-            } else if (ndkHeart == 0) {
-                //sendTipsEventBus(BLOOD_STOP_CHECK, BLOOD_NOT_DATA_CHECK);
-            } else {
-                if (mListener != null) {
-                    mListener.onHeartRateResult(ndkHigh, ndkLow, ndkHeart, oxygen);
+                if (invalidateTime > 20) {
+                    break;
                 }
             }
+            if (mListener != null) {
+                mListener.onHeartRateResult(ndkHigh, ndkLow, ndkHeart, oxygen);
+            }
             if (mListener != null) {
                 mListener.onHeartRateTestFinished();
             }