调整活体检测阈值,优化睡眠数据存储 1434/1 1434/head
authorpenglei <1624952103@qq.com>
Wed, 20 Nov 2024 13:39:10 +0000 (21:39 +0800)
committerpenglei <1624952103@qq.com>
Wed, 20 Nov 2024 13:39:10 +0000 (21:39 +0800)
code/sdk/drivers/peripheral/cywee/src/main_dml.c
code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c

index bf91879..bea215a 100644 (file)
@@ -130,6 +130,33 @@ int cm__hs1__init(void);
 int cm__hs1__deinit(void);
 #endif
 
+void get_sleep_file_day(char *day)
+{
+    uint32_t sleep_time = get_sleep_time_from_config_model();
+    uint32_t wake_up_time = get_wake_up_time_from_config_model();
+    uint32_t sleep_min = ((sleep_time & 0xFFFF0000) >> 16) * 60 + sleep_time & 0x0000FFFF;
+    uint32_t wake_min = ((wake_up_time & 0xFFFF0000) >> 16) * 60 + wake_up_time & 0x0000FFFF;
+    uint32_t current_min = 0;
+
+    if (sleep_min > wake_min)
+    {
+        time_t rawtime;
+        struct tm *timeinfo;
+
+        time(&rawtime);
+        timeinfo = localtime(&rawtime);
+
+        current_min = timeinfo->tm_hour * 60 + timeinfo->tm_min;
+
+        if (current_min >= sleep_min && current_min < 24 * 60)
+            uapi_get_YYMMDD_Time_extend(day, '\0', -1);
+        else if (current_min >= 0 && current_min < wake_min)
+            uapi_get_YYMMDD_Time_extend(day, '\0', 0);
+    }
+    else
+        uapi_get_YYMMDD_Time_extend(day, '\0', 0);
+}
+
 void cywee_check_acc(void)
 {
     if(!timeout)
@@ -225,9 +252,11 @@ void cywee_set_sleep_time_data(cywee_inactivity_accumulate_time_t *sleep_data)
 
 void cywee_save_sleep_time_data(cywee_inactivity_accumulate_time_t sleep_time)
 {
-    if (access(time_file_path, 0) == -1)
+    // if (access(time_file_path, 0) == -1)
     {
         memset(time_file_path, 0, sizeof(time_file_path));
+        memset(day, 0, sizeof(day));
+        get_sleep_file_day(day);
         sprintf_s(time_file_path, 64, SLEEP_TIME_PATH, day);
     }
 
@@ -309,12 +338,13 @@ void cywee_save_sleep_time_data(cywee_inactivity_accumulate_time_t sleep_time)
 
 void cywee_save_sleep_stat_data(void)
 {
+    memset(status_file_path, 0, sizeof(status_file_path));
+    memset(day, 0, sizeof(day));
+    get_sleep_file_day(day);
+    sprintf_s(status_file_path, 64, SLEEP_STATUS_PATH, day);
     if (access(status_file_path, 0) == -1) // 文件不存在 直接写入
     {
-      memset(status_file_path, 0, sizeof(status_file_path));
-      sprintf_s(status_file_path, 64, SLEEP_STATUS_PATH, day);
-
-      uapi_save_file_data(status_file_path,(uint8_t *)&sleep_stat,stat_num * sizeof(SLEEP_STAT_T),"wb+");  
+        uapi_save_file_data(status_file_path,(uint8_t *)sleep_stat,stat_num * sizeof(SLEEP_STAT_T),"wb+");  
     }
     else // 文件已存在 需要判断是否需要补上清醒状态
     {
@@ -336,20 +366,25 @@ void cywee_save_sleep_stat_data(void)
             fseek(fp, -sizeof(SLEEP_STAT_T), SEEK_END);
             fwrite(&sleep_status, sizeof(SLEEP_STAT_T), 1, fp); // 补上清醒状态
             // fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp); //写入本次睡眠状态
-
-            fwrite(&sleep_stat[1], sizeof(SLEEP_STAT_T),stat_num - 1, fp); // 跳过入睡状态写入文件
+            if(sleep_stat[0].stat == 0)
+            {
+                sleep_stat[0].stat = 1;
+                fwrite(sleep_stat, sizeof(SLEEP_STAT_T),stat_num, fp); // 跳过入睡状态写入文件
+            }
+            else
+                fwrite(sleep_stat, sizeof(SLEEP_STAT_T), stat_num, fp);
 
         }
         else // 不满足补清醒状态条件 直接写入本次睡眠状态
         {
             fseek(fp, 0, SEEK_END);
-            fwrite(&sleep_stat, sizeof(SLEEP_STAT_T), stat_num, fp);
+            fwrite(sleep_stat, sizeof(SLEEP_STAT_T), stat_num, fp);
         }
         fclose(fp);
     }
     
     stat_num = 0;
-    memset(&sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T));
+    memset(sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T));
 
 }
 void cywee_set_sleep_stat_data(cywee_inactivity_result_t c_inactivity_result_t)
@@ -760,11 +795,6 @@ void cywee_time_sync(void)
 
     clean_sleep_data();
 
-    uint32_t sleep_time = get_sleep_time_from_config_model();
-    uint32_t wake_up_time = get_wake_up_time_from_config_model();
-    uint32_t sleep_min = ((sleep_time & 0xFFFF0000) >> 16) * 60 + sleep_time & 0x0000FFFF;
-    uint32_t wake_min = ((wake_up_time & 0xFFFF0000) >> 16) * 60 + wake_up_time & 0x0000FFFF;
-    uint32_t current_min = 0;
 
     time(&rawtime);
     timeinfo = localtime(&rawtime);
@@ -785,24 +815,7 @@ void cywee_time_sync(void)
     CWM_SettingControl(SCL_DATE_TIME, &scl);
 
     //时间同步以后创建文件夹
-    if (sleep_min > wake_min)
-    {
-        time_t rawtime;
-        struct tm *timeinfo;
-
-        time(&rawtime);
-        timeinfo = localtime(&rawtime);
-
-        current_min = timeinfo->tm_hour * 60 + timeinfo->tm_min;
-
-        if (current_min >= sleep_min && current_min < 24 * 60)
-            uapi_get_YYMMDD_Time_extend(day, '\0', -1);
-        else if (current_min >= 0 && current_min < wake_min)
-            uapi_get_YYMMDD_Time_extend(day, '\0', 0);
-    }
-    else
-        uapi_get_YYMMDD_Time_extend(day, '\0', 0);
-
+    get_sleep_file_day(day);
     sprintf_s(dir_path, 64, SLEEP_DIR_PATH, day);
     uapi_create_folder(dir_path);
 }
index 71a0068..5c37eec 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, 20, 30);\r
+                               tyhx_hrs_set_living(1, 15, 30);\r
         if(hx3695_hrs_enable()== SENSOR_OP_FAILED)\r
         {\r
             return false;\r