优化debug界面电量信息显示,支持多页显示,调整夜间心率检测时长,调整活体检测阈值,改善佩戴不出值的情况 1488/1 1488/head
authorpenglei <1624952103@qq.com>
Tue, 3 Dec 2024 02:15:31 +0000 (10:15 +0800)
committerpenglei <1624952103@qq.com>
Tue, 3 Dec 2024 02:15:31 +0000 (10:15 +0800)
code/sdk/application/battery/service/battery_service.cpp
code/sdk/application/battery/service/battery_service.h
code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp
code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695_hrs_agc.c

index 4110b63..14a54aa 100644 (file)
@@ -100,6 +100,47 @@ errcode_t charger_plug_event_ui_sendmsg_toUI(uint8_t plugged);
 static BATTERY_DATA_T *bat_t;
 static uint32_t len = 0;
 
+void battery_file_check(BATTERY_DATA_T newStruct, const char *filename) 
+{
+    FILE *fp;
+    BATTERY_DATA_T data[200];
+    uint8_t count = 0;
+    uint8_t oldest = 0;
+    fp = fopen(filename, "r+b");
+    if(!fp)
+        fp = fopen(filename, "wb");
+
+    fseek(fp, 0, SEEK_END);
+    count = ftell(fp) / sizeof(BATTERY_DATA_T);
+    fseek(fp, 0, SEEK_SET);
+    // PRINT("battery data count %d \n",count);
+    if (count >= 180) 
+    {
+        fread(data, sizeof(BATTERY_DATA_T), count, fp);
+
+        for (int i = 1; i < count; i++) 
+        {
+            if (data[i].tm < data[oldest].tm) 
+            {
+                oldest = i;
+            }
+        }
+
+        data[oldest] = newStruct;
+        
+        fseek(fp, 0, SEEK_SET);
+        fwrite(data, sizeof(BATTERY_DATA_T), count, fp);
+    }
+    else
+    {
+        fseek(fp, 0, SEEK_END);
+        fwrite(&newStruct, sizeof(BATTERY_DATA_T), 1, fp);
+    }
+
+    fclose(fp);
+}
+
+
 void battery_get_data_t(BATTERY_DATA_T **data,uint16_t *length)
 {
     if(!len)
@@ -112,17 +153,17 @@ void battery_get_data_t(BATTERY_DATA_T **data,uint16_t *length)
 
 void battery_get_data(void)   
 {
-    len = uapi_get_file_size("/user/userdata/battery_data.bin");
+    len = uapi_get_file_size("/user/userdata/bat_data.bin");
     if(!len)
       return;
 
     bat_t = (BATTERY_DATA_T *)malloc(len);
     FILE *fp;
 
-    fp = fopen("/user/userdata/battery_data.bin", "rb"); 
+    fp = fopen("/user/userdata/bat_data.bin", "rb"); 
     if (fp == NULL) 
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery_data file open failed");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bat_data file open failed");
         free(bat_t);
         return;
     }
@@ -130,7 +171,7 @@ void battery_get_data(void)
     if(fread(bat_t, 1, len, fp) != len)
     {
         free(bat_t);
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery_data file read failed");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bat_data file read failed");
     }
     fclose(fp);
 }
@@ -138,11 +179,11 @@ void battery_get_data(void)
 //保存电池信息到文件
 void battery_save_data(void)
 {
-    len = uapi_get_file_size("/user/userdata/battery_data.bin");
-    if(len > sizeof(BATTERY_DATA_T) * 24 * 7)
-    {
-        uapi_delete_files("/user/userdata/battery_data.bin");
-    }
+    // len = uapi_get_file_size("/user/userdata/battery_data.bin");
+    // if(len > sizeof(BATTERY_DATA_T) * 24 * 7)
+    // {
+    //     uapi_delete_files("/user/userdata/battery_data.bin");
+    // }
 
     BATTERY_DATA_T data;
     float voltage;
@@ -150,9 +191,10 @@ void battery_save_data(void)
     data.voltage = voltage;
     data.percent = percent;
     uapi_get_timestampe_ss(&data.tm);
+    data.stat = get_charge_stat();
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "data.voltage : %f , data[i].percent : %d  tm : %d",data.voltage,data.percent,data.tm);
-    uapi_save_file_data("user/userdata/battery_data.bin",(uint8_t *)&data,sizeof(BATTERY_DATA_T),"ab");
-
+    // uapi_save_file_data("user/userdata/battery_data.bin",(uint8_t *)&data,sizeof(BATTERY_DATA_T),"ab");
+    battery_file_check(data,"user/userdata/bat_data.bin");
     uapi_save_file_data("/user/userdata/battery.bin",&percent,1,"wb");
 }
 
index b3328cb..73627a4 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com
  * @Date: 2024-10-25 14:42:28
  * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-11-12 11:10:16
+ * @LastEditTime: 2024-12-02 11:16:37
  * @FilePath: /FD230/code/sdk/application/battery/service/battery_service.h
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
@@ -33,6 +33,7 @@ typedef struct
     uint32_t tm;
     float voltage; //电压
     uint8_t percent;// 电量
+    uint8_t stat;// 充电状态
 }BATTERY_DATA_T;
 #pragma pack()
 
index ee2c95a..917a5d6 100644 (file)
@@ -49,7 +49,7 @@ extern "C" {
 \r
 #define MAX_UNWEAR_COUNT 2\r
 #define MAX_VALID_HRS_COUNT 10    //最大有效数\r
-#define MAX_DISVALID_HRS_COUNT 30 //最大无效数\r
+#define MAX_DISVALID_HRS_COUNT 15 //最大无效数\r
 #define MIN_DISPLAY_HEART 50      //最新心率\r
 #define DISPLAY_COUNT 0\r
 #define HEARTTEST 1 //[0 开启测试 1 关闭]\r
@@ -690,7 +690,7 @@ void HeartModel::UpHeartdata(uint16_t heart) {
 \r
   // 检查无效计数器是否达标\r
   if (uapi_dev_runtime_get_sleep_monitoring_status()) //睡眠监测模式下,增加未佩戴个数最大值,避免误判\r
-    max_valid_count = MAX_DISVALID_HRS_COUNT * 3;\r
+    max_valid_count = MAX_DISVALID_HRS_COUNT * 2;\r
   else\r
     max_valid_count = MAX_DISVALID_HRS_COUNT;\r
 \r
index 7d27dd3..4205023 100644 (file)
@@ -62,6 +62,8 @@
 #include "diag_log.h"
 namespace OHOS
 {
+    static int get_battery_percent_flag = 0;
+    static int refreshbutton_is_visible = 1; //刷新按钮是否显示
     /**************************************************************************************************** */
     // 辅助函数
 
@@ -122,8 +124,10 @@ namespace OHOS
     UIToggleButton* toggleButton = nullptr;
     UIToggleButton* toggleButtonOffline = nullptr;
     UILabelButton *debugOutputbleServiceLabelButton{nullptr};
+    UILabelButton *nextorprepageLabelButton{nullptr};
     static constexpr const char *DEBUGOUTPUTLABELBUTTON = "debugOutputLabelButton";
     static constexpr const char *DEBUGOUTPUTBLESERVICELABELBUTTON = "debugOutputbleServiceLabelButton";
+    static constexpr const char *NEXTORPREPAGELABELBUTTON = "nextorprepageLabelButton";
     /* -------------------------------------------------------------------------- */
 
     void DebugOutputViewEventListener::InitDebugOutputItem()
@@ -468,10 +472,13 @@ namespace OHOS
         return get_wear_status_str(); // 返回结果字符串  
     } 
 
-    // 获取佩戴状态  
+
+    // 获取电池状态  
     std::string DebugOutputViewEventListener::get_battery_percent(void) 
     {
         std::string result;
+        std::string charge_stat;
+        int index = 0;
         // 进行文件读取
         do_custom_fileoperate_service_check_msg(  
             CUSTOM_FILEOPERATE_MSG_TYPE_BATTERY_DATA_READ, nullptr, 0);  
@@ -482,7 +489,41 @@ namespace OHOS
         if(len == 0)
             return result;
 
-        for(int i = 0; i < len/sizeof(BATTERY_DATA_T); i++)
+        len = len/sizeof(BATTERY_DATA_T);
+
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "111111len : %d",len);
+
+        if(get_battery_percent_flag == 1)
+        {
+            nextorprepageLabelButton->SetText("第二页");
+            get_battery_percent_flag = 2;
+            if(len >= 120)
+            {
+                index = 60;
+                len = 120;
+            }
+            else if(len >= 60 && len < 120)
+                index = 60;
+            else
+                return result;
+        }
+        else if(get_battery_percent_flag == 2)
+        {
+            nextorprepageLabelButton->SetText("第三页");
+            get_battery_percent_flag = 3;
+            if(len >= 120)
+                index = 120;
+            else
+                return result;
+        }
+        else
+        {
+            nextorprepageLabelButton->SetText("第一页");
+            get_battery_percent_flag = 1;
+            if(len >= 60)
+                len = 90;
+        }
+        for(int i = index; i < len; i++)
         {
             std::string timestr;
             char labelTime[20] = {0};
@@ -497,14 +538,23 @@ namespace OHOS
             } 
 
             std::ostringstream oss;
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "data[i].voltage : %f , data[i].percent : %d",data[i].voltage,data[i].percent);
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "data[%d].voltage : %f , data[%d].percent : %d",i,data[i].voltage,i,data[i].percent);
+
+            if(data[i].stat)
+                // charge_stat = static_cast<int>(i) + ":充电中";
+                charge_stat = "充电中";
+            else
+                // charge_stat = static_cast<int>(i) + ":未充电";
+                charge_stat = "未充电";
+
+            // result += std::to_string(i) + ":" + charge_stat  + "[" + timestr + "]\n" + std::to_string(data[i].voltage) + " V, " + std::to_string(data[i].percent) + "%\n";
 
             oss << std::fixed
             << std::setprecision(3) // 设置为固定小数位,保留两位小数
-            <<"["<<timestr<< "] :\n"
-            << data[i].voltage << " V, "
-            << static_cast<int>(data[i].percent)
-            << "%\n";
+            << charge_stat
+            <<", ["<<timestr<< "] ,"
+            << data[i].voltage << "V , "
+            << static_cast<int>(i) << "%\n";
 
             result += oss.str();
             // result += std::to_string(i*10) + " min  , " + std::to_string(data[i].voltage) + "V , "+ std::to_string(data[i].percent) + "%" + "\n";
@@ -713,7 +763,8 @@ namespace OHOS
             viewIndex = GetCurViewIndex();
         }
         //点击开启按键
-        else if (viewId == "uart_at_set") {
+        else if (viewId == "uart_at_set") 
+        {
           if (toggleButton) {
             if (toggleButton->GetState() == false) {
                 // toggleButton->SetState(false);
@@ -732,7 +783,8 @@ namespace OHOS
         //   viewIndex = GetCurViewIndex();
           return true; //进行UI刷新
         }//点击开启按键
-        else if (viewId == "offline_log_switch") {
+        else if (viewId == "offline_log_switch") 
+        {
           if (toggleButtonOffline) {
             if (toggleButtonOffline->GetState() == false) {
                 int ret1 =  enable_offline_log_nv(0);
@@ -748,7 +800,8 @@ namespace OHOS
         //   viewIndex = GetCurViewIndex();
           return true; //进行UI刷新
         }
-        else if (viewId == "hrs_ble_switch") {
+        else if (viewId == "hrs_ble_switch") 
+        {
           if (toggleButtonOffline) {
             if (toggleButtonOffline->GetState() == false) {
                 send_ppg_cmd_msg(PPG_SERVICE_CMD_TYPE_CLOSE_HRS_BLE);
@@ -763,6 +816,25 @@ namespace OHOS
           }
             return true; //进行UI刷新
         }
+        else if (viewId == NEXTORPREPAGELABELBUTTON)
+        {
+            // std::string str;
+            viewIndex = GetCurViewIndex();
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"111111 viewIndex : %d",viewIndex);
+            // if(nextorprepageLabelButton)
+            // {
+            //     if(get_battery_percent_flag == 0)
+            //     {
+            //         nextorprepageLabelButton->SetText("下一页");
+            //         // str = get_battery_percent();
+            //     }
+            //     else if(get_battery_percent_flag == 1)
+            //     {
+            //         nextorprepageLabelButton->SetText("上一页");
+            //         // str = get_battery_percent();
+            //     }
+            // }
+        }
         else // 如果点击的是列表中的itemview
         {
             DebugOutputItemView *debugOutputItemView = static_cast<DebugOutputItemView *>(&view);
@@ -834,7 +906,15 @@ namespace OHOS
             str = get_wear_status();
             break;
         case 16:
+            refreshbutton_is_visible = 0;
             str = get_battery_percent();
+            if (nextorprepageLabelButton) 
+            { 
+              if (nextorprepageLabelButton->IsVisible() == false) 
+              {
+                nextorprepageLabelButton->SetVisible(true);
+              }
+            }
             break;
         case 17:
             str = get_offline_log_status();
@@ -878,10 +958,16 @@ namespace OHOS
         {
             debugOutputLabel->SetText(str.c_str());
         }
-        if (debugOutputLabelButton)
+        if(refreshbutton_is_visible) {
+            if (debugOutputLabelButton)
+            {
+                debugOutputLabelButton->SetY(debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
+                debugOutputLabelButton->Invalidate();
+            }
+        }
+        else
         {
-            debugOutputLabelButton->SetY(debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20);
-            debugOutputLabelButton->Invalidate();
+            debugOutputLabelButton->SetVisible(false);
         }
         debugOutputLabel->Invalidate();
     }
@@ -960,6 +1046,7 @@ namespace OHOS
     {
         if (hideView == 1)
         {
+            refreshbutton_is_visible = 1;
             DebugGroupView->Remove(DebugScrollView[1]);
             if (DebugScrollView[1] != nullptr)
             {
@@ -968,6 +1055,15 @@ namespace OHOS
                 delete debugOutputLabel;
                 debugOutputLabel = nullptr;
 
+                delete toggleButton;
+                toggleButton = nullptr;
+
+                delete nextorprepageLabelButton;
+                nextorprepageLabelButton = nullptr;
+
+                delete toggleButtonOffline;
+                toggleButtonOffline = nullptr;
+
                 delete debugOutputLabelButton;
                 debugOutputLabelButton = nullptr;
 
@@ -1011,6 +1107,7 @@ namespace OHOS
         DebugScrollView[1]->SetScrollBlankSize(70);
         DebugScrollView[1]->SetReboundSize(35);
         DebugScrollView[1]->SetThrowDrag(true);
+        DebugScrollView[1]->SetMaxScrollDistance(1000);
         UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(&DebugOutputViewEventListener::GetInstance());
         if (dragListener == nullptr)
         {
@@ -1035,6 +1132,32 @@ namespace OHOS
         debugOutputLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
         DebugScrollView[1]->Add(debugOutputLabel);
         /* -------------------------------------------------------------------------- */
+        if (nextorprepageLabelButton == nullptr)
+        {
+            nextorprepageLabelButton = new UILabelButton();
+            if (nextorprepageLabelButton == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "nextorprepageLabelButton is new fail!!");
+                return nullptr;
+            }
+        }
+        nextorprepageLabelButton->SetPosition(143, 20);
+        nextorprepageLabelButton->Resize(100, 100);
+        nextorprepageLabelButton->SetViewId(NEXTORPREPAGELABELBUTTON);
+        nextorprepageLabelButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
+        nextorprepageLabelButton->SetText("下一页");
+        nextorprepageLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
+        nextorprepageLabelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffff0000, UIButton::PRESSED);
+        nextorprepageLabelButton->SetVisible(false);
+        DebugScrollView[1]->Add(nextorprepageLabelButton);
+        UIView::OnClickListener *nextorpreclickListener = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
+        if (nextorpreclickListener == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "nextorpreclickListener is new fail!!");
+            return nullptr;
+        }
+        nextorprepageLabelButton->SetOnClickListener(nextorpreclickListener);
+        /* -------------------------------------------------------------------------- */
         if (debugOutputLabelButton == nullptr)
         {
             debugOutputLabelButton = new UILabelButton();
@@ -1274,12 +1397,6 @@ namespace OHOS
                 delete debugOutputbleServiceLabelButton;
                 debugOutputbleServiceLabelButton = nullptr;
 
-                delete toggleButton;
-                toggleButton = nullptr;
-
-                delete toggleButtonOffline;
-                toggleButtonOffline = nullptr;
-
                 delete DebugScrollView[0];
                 DebugScrollView[0] = nullptr;
             }
index a4f63ce..8917677 100644 (file)
@@ -2254,7 +2254,7 @@ bool hx3695_init(WORK_MODE_T mode)
     case HRS_MODE:\r
                //TYHX_LOG(" hx3695_init mode : HRS_MODE \n");\r
 #ifdef HRS_ALG_LIB\r
-                               tyhx_hrs_set_living(1, 18, 30);\r
+                               tyhx_hrs_set_living(1, 15, 30);\r
         if(hx3695_hrs_enable()== SENSOR_OP_FAILED)\r
         {\r
             return false;\r
index 04fd3f8..45936e2 100644 (file)
@@ -920,7 +920,7 @@ uint8_t hx3695_hrs_read(hrs_sensor_data_t * s_dat)
 //    TYHX_LOG("ppg_state: %d ,hrs_cal_state:  %d\r\n",s_ppg_state,hrs_cal_state);             \r
                    data_count = hx3695_read_fifo_data(s_buf,hrs_phase_num,1); \r
 \r
-        if(data_count > 20)\r
+        if(data_count > 9)\r
           return 0;\r
 \r
                    // PRINT("ppg data size: %d %d\r\n", data_count,hrs_phase_num);\r