修复心率血氧佩戴消息错误问题,血氧还遗留提醒检测失败,后台仍然工作的bug
authorSnickerSun <snickersun@163.com>
Tue, 19 Mar 2024 01:55:25 +0000 (09:55 +0800)
committerSnickerSun <snickersun@163.com>
Tue, 19 Mar 2024 01:55:25 +0000 (09:55 +0800)
code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp
code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp
code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartModel.h
code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp
code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c

index 0c185ef..f426c36 100644 (file)
@@ -6,7 +6,7 @@
 #include "health_service.h"
 #include "custom_utils.h"
 extern "C" errcode_t uapi_get_timestamp_ms(uint64_t *tm);
-
+#define MAX_UNWARE_COUNT 30
 namespace OHOS
 {
     /**
@@ -126,17 +126,21 @@ namespace OHOS
      */
     void BloodOxygenModel::SetWearStatus(int32_t wear)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weartest::%d", wear);
-        wear_ = wear;
-        if (wear_ != 1)
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenModel Weartest::%d", wear);
+        
+        if (wear_ != 1 && wear != 1)
         {
             wear_error++;
-            if (wear_error >= 10)
+            if (wear_error >= MAX_UNWARE_COUNT)
             {
                 WearStatus = false;
             }
+        }else{
+            wear_error = 0;
+            WearStatus = true;
         }
-        WearStatus = true;
+        wear_ = wear;
+        
     }
 
     /**
index d90a60c..3348fe8 100644 (file)
@@ -216,6 +216,21 @@ namespace OHOS
     }
     void BloodOxygenPresenter::ProgressNotify(void)
     {
+
+               // 当检测状态为结束检测,结束检测
+        if (BloodOxygenModel::GetInstance()->GetCheckStatus() == false)
+        {
+            if (startspo2 == false)
+            {
+                uint8_t md = PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST;
+                send_ppg_cmd_msg(md);
+                startspo2 = true;
+                BloodOxygenModel::GetInstance()->StopTest();
+            }
+        }
+
+        if (BloodOxygenModel::GetInstance()->GetBloodCheckViewStatus() == false)
+            return ;
         // 当检测状态为开始检测,开始检测
         if (BloodOxygenModel::GetInstance()->GetCheckStatus() == true)
         {
@@ -229,19 +244,8 @@ namespace OHOS
             }
         }
 
-        // 当检测状态为结束检测,结束检测
-        if (BloodOxygenModel::GetInstance()->GetCheckStatus() == false)
-        {
-            BloodOxygenView::GetInstance()->Upspo2data(); // 更新主界面
-            if (startspo2 == false)
-            {
-                uint8_t md = PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST;
-                send_ppg_cmd_msg(md);
-                startspo2 = true;
-                BloodOxygenModel::GetInstance()->StopTest();
-            }
-        }
 
+        // 长时间未佩戴,则停止检测
         if (BloodOxygenModel::GetInstance()->GetWearStatus() == false)
         {
             BloodOxygenView::GetInstance()->ChangeView(BLOODCHECKVIEW, BLOODRESULT);
@@ -280,6 +284,7 @@ namespace OHOS
                 else
                 {
                     BloodOxygenView::GetInstance()->ChangeView(BLOODCHECKVIEW, BLOODVIEW);
+                    BloodOxygenView::GetInstance()->Upspo2data(); // 更新主界面
                 }
                 BloodOxygenModel::GetInstance()->SetCheckStatus(false); // 关闭检测
                 BloodOxygenModel::GetInstance()->SetBloodCheckViewStatus(false);
index d9a6e69..9ae55a0 100644 (file)
@@ -44,6 +44,7 @@ namespace OHOS
         cJSON *latestData = cJSON_GetObjectItem(root, "spo2_latest_data");
         data->SPO2 = cJSON_GetObjectItem(latestData, "oxygen_value")->valueint;
         data->timestamp = cJSON_GetObjectItem(latestData, "timestamp")->valuedouble;
+        cJSON_Delete(root);
         return data;
     }
 
@@ -70,8 +71,10 @@ namespace OHOS
         if (UpdateJsonData() == false)
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateJsonData is error");
+            cJSON_Delete(root);
             return false;
         }
+        cJSON_Delete(root);
         return true;
     }
     HeartRateData *HeartService::ReadHeartRateData()
@@ -81,6 +84,7 @@ namespace OHOS
         cJSON *latestData = cJSON_GetObjectItem(root, "heart_latest_data");
         data->Heart = cJSON_GetObjectItem(latestData, "heart_value")->valueint;
         data->timestamp = cJSON_GetObjectItem(latestData, "timestamp")->valuedouble;
+        cJSON_Delete(root);
         return data;
     }
 
@@ -107,8 +111,10 @@ namespace OHOS
         if (UpdateJsonData() == false)
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateJsonData is error");
+            cJSON_Delete(root);
             return false;
         }
+        cJSON_Delete(root);
         return true;
     }
 
index 64dd9fd..d24ef9d 100644 (file)
@@ -144,7 +144,7 @@ extern "C"
             uint16_t preMinX{NUM_1};\r
             uint16_t countMax{0};\r
             uint16_t countMin{0};\r
-            bool wearStatus{false};\r
+            bool wearStatus{true};\r
             uint16_t index_ = 0;\r
 \r
             bool HeartView;\r
@@ -157,10 +157,9 @@ extern "C"
             uint64 TIME_;         // 检测时间(存(时、分),大于24小时,改为1天前,小于1分钟为刚刚)\r
 \r
             bool initstatus = true;\r
-            bool wearstatus;\r
             uint8_t wear_;\r
             uint8_t valid_counter_ = 0;//有效数计数器\r
-            uint8_t wear_counter_ = 0;//佩戴错误计数器\r
+            uint8_t unwear_counter_ = 0;//佩戴错误计数器\r
         };\r
     }\r
 \r
index 491264c..97bda4e 100644 (file)
@@ -19,6 +19,8 @@ extern "C"
 {\r
 #endif\r
 \r
+#define MAX_UNWEAR_COUNT 30\r
+#define MAX_VALID_HRS_COUNT 30\r
     /* 佩戴检测结果 */\r
     enum\r
     {\r
@@ -138,16 +140,16 @@ extern "C"
             uint32 wearStatus = *((uint32 *)request->data);\r
             if (wearStatus == SENSOR_WEAR_OFF)\r
             {\r
-                OHOS::HeartModel::GetInstance()->SetWearStatus(false);\r
-                OHOS::HeartModel::GetInstance()->SetHeartRatePerSec(0);\r
-                if (OHOS::MainClockView::GetInstance() != nullptr)\r
-                {\r
+                // OHOS::HeartModel::GetInstance()->SetWearStatus(false);\r
+                // OHOS::HeartModel::GetInstance()->SetHeartRatePerSec(0);\r
+                // if (OHOS::MainClockView::GetInstance() != nullptr)\r
+                // {\r
                     // OHOS::MainClockView::GetInstance()->RefreshHeartRate(*(uint16_t *)request->data);\r
-                }\r
+                // }\r
             }\r
             else\r
             {\r
-                OHOS::HeartModel::GetInstance()->SetWearStatus(true);\r
+                // OHOS::HeartModel::GetInstance()->SetWearStatus(true);\r
             }\r
         }\r
     }\r
@@ -481,21 +483,26 @@ namespace OHOS
     void HeartModel::Heart_Stop()\r
     {\r
         valid_counter_ = 0;\r
-        wear_counter_ = 0;\r
+        unwear_counter_ = 0;\r
         SetCheckStatus(false);\r
-        SetWearStatus(true);\r
+        SetWearStatus(1);\r
     }\r
 \r
     void HeartModel::SetWearStatus(uint8_t wear)\r
     {\r
         // 设置佩戴状态\r
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weartest::%d", wear);\r
-        wear_ = wear_;\r
-        if (wear_ != 1)\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartModel Weartest::%d", wear);\r
+        if (wear_ != 1 && wear !=1)\r
         {\r
-            wear_counter_++; // 佩戴错误计时器计数\r
+            unwear_counter_++; // 佩戴错误计时器计数\r
+        }else{\r
+            unwear_counter_ = 0;\r
         }\r
-        if (wear_counter_ >= 10)\r
+\r
+        wear_ = wear;\r
+\r
+\r
+        if (unwear_counter_ >= MAX_UNWEAR_COUNT)\r
         {\r
             wearStatus = false; // 计数达到10次,停止检测\r
         }\r
@@ -593,7 +600,7 @@ namespace OHOS
             valid_counter_ = 0; // 清零有效计数器\r
         }\r
 \r
-        if (valid_counter_ >= 10)\r
+        if (valid_counter_ >= MAX_VALID_HRS_COUNT)\r
         {\r
             // 结束本次测试,将最后一次有效数作为本次测量结果\r
             Heart_Stop();\r
@@ -604,6 +611,7 @@ namespace OHOS
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d %lld", heart, data->timestamp);\r
             SetCheckTime(data->timestamp);\r
             HeartService::GetInstance()->UpdateHeartRateData(*data);\r
+\r
             /* -------------------------------------------------------------------------- */\r
         }\r
     }\r
index cad40dd..2a67dee 100644 (file)
@@ -2700,7 +2700,7 @@ void hx3695_hrs_ppg_Int_handle(void)
     if(func != NULL)\r
     {\r
       hrsresult.wearstatus = hrs_wear_status;\r
-      func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult.wearstatus,sizeof(int32_t));\r
+      func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
       func(HX3695_MSG_TYPE_HRS_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
     }\r
 ////////////////////////////////////////////////////////////////////////////////////\r
@@ -3000,7 +3000,7 @@ void hx3695_spo2_ppg_Int_handle(void)
     hx3695_msg_callback_t func =  hx3695_get_send_msg_callback_func();\r
     if(func != NULL)\r
     {\r
-      func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult.wearstatus,sizeof(spo2_wear_status));\r
+      func(HX3695_MSG_TYPE_WEARSTAT_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
       func(HX3695_MSG_TYPE_SPO2_UPDATE,&hrsresult,sizeof(FT_CUSTOM_RESULTS_t));\r
     }\r
 \r