update MW13C algorithm.
authorTrillGates <williamtrillgates@gmail.com>
Thu, 23 Sep 2021 09:17:28 +0000 (17:17 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Thu, 23 Sep 2021 09:17:28 +0000 (17:17 +0800)
app/src/main/java/com/ic/work/SensorDataService.java
app/src/main/java/com/ic/work/utils/AlgorithmUtils.java
app/src/main/java/com/ic/work/utils/TemperatureUtil.java
app/src/main/res/values-en/strings.xml [new file with mode: 0644]
app/src/main/res/values/strings.xml

index abf9b06..d9c98d0 100644 (file)
@@ -199,7 +199,11 @@ public class SensorDataService extends Service implements TemperatureHelper.Temp
         }
         sendTempBroadcast(wristTemp, bodyTemp, envTemp);
         //写到设置项里,供各个地方获取
-        temperatureSave2Db(wristTemp, bodyTemp, envTemp);
+        try {
+            temperatureSave2Db(wristTemp, bodyTemp, envTemp);
+        } catch (Exception e) {
+            //有可能没有数据库
+        }
     }
 
     public static final String PATH = "settings";
index 517405f..1c1711e 100644 (file)
@@ -134,7 +134,24 @@ public class AlgorithmUtils {
         return sInstance;
     }
 
+    private final int ZERO_MAX_TIME = 20;
+
+    private int zeroTime = 0;
+
     public double MW13C(double bodyTemp, double boardTemp) throws TempValueException {
+        if (bodyTemp == 0.0) {
+            zeroTime++;
+            return 0.0;
+        } else {
+            zeroTime = 0;
+        }
+        if (zeroTime > ZERO_MAX_TIME) {
+            //超过20次,我们就认为传感器检测不到温度了
+            zeroTime = 0;
+            throw new TempValueException(
+                    mContext.getString(R.string.sensor_break) + ":" + bodyTemp,
+                    ERROR_HARD_WEAR_ERROR);
+        }
         //对体温值进行检查
         if (bodyTemp <= 28.0f) {
             throw new TempValueException(
@@ -163,6 +180,7 @@ public class AlgorithmUtils {
     }
 
     public static final int ERROR_HARD_WEAR_TOO_HIGH = 1;
+    public static final int ERROR_HARD_WEAR_ERROR = 2;
     public static final int ERROR_SENSOR_TOO_HIGH = 3;
     public static final int ERROR_SENSOR_TOO_LOW = 4;
 
index d2ddf1e..a16e331 100644 (file)
@@ -136,7 +136,11 @@ public class TemperatureUtil {
                     ICLogger.d("final wrist temp == > " + bodyTempResult);
                 }
             } else if ("MW13C".equals(property)) {
-                AlgorithmUtils.getInstance(WorkServiceApp.sContext).MW13C(bodyTemp, boardTemp);
+                bodyTemp = AlgorithmUtils.getInstance(WorkServiceApp.sContext).MW13C(bodyTemp, boardTemp);
+                if (bodyTemp == 0) {
+                    return null;
+                }
+                lastBodyTemp = getBodyTemp(bodyTemp, 26.1f);
             } else {
                 //   double bodyTempResult = AlgorithmUtils.l004Pt(bodyTemp, evnTemp);
                 ICLogger.d("wrist TempResult == > " + bodyTemp);
diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml
new file mode 100644 (file)
index 0000000..12d2965
--- /dev/null
@@ -0,0 +1,7 @@
+<resources>
+    <string name="app_name">IcWorkService</string>
+    <string name="body_sensor_value_too_low_text">sensor temperature too low</string>
+    <string name="body_sensor_value_too_high_text">sensor temperature too high</string>
+    <string name="board_temperature_high_text">board temperature too high</string>
+    <string name="sensor_break">传感器检测不到温度</string>
+</resources>
index 3f41099..4b04937 100644 (file)
@@ -1,8 +1,8 @@
 <resources>
     <string name="app_name">IcWorkService</string>
-    <string name="program_abnormal">很抱歉,程序出现异常,即将退出</string>
+    <string name="program_abnormal" translatable="false">很抱歉,程序出现异常,即将退出</string>
     <string name="body_sensor_value_too_low_text">体温传感器温度过低</string>
     <string name="body_sensor_value_too_high_text">体温传感器温度过高</string>
-    <string name="board_temperature_low_text">主板温度低影响测试结果</string>
     <string name="board_temperature_high_text">主板温度过高</string>
+    <string name="sensor_break">传感器检测不到温度</string>
 </resources>