From 31bf1b712abc3d18a1e0828d77134b2db84249aa Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Wed, 20 Nov 2024 21:39:10 +0800 Subject: [PATCH] =?utf8?q?=E8=B0=83=E6=95=B4=E6=B4=BB=E4=BD=93=E6=A3=80?= =?utf8?q?=E6=B5=8B=E9=98=88=E5=80=BC=EF=BC=8C=E4=BC=98=E5=8C=96=E7=9D=A1?= =?utf8?q?=E7=9C=A0=E6=95=B0=E6=8D=AE=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../drivers/peripheral/cywee/src/main_dml.c | 77 +++++++++++-------- .../drivers/peripheral/ppg/hx3695/hx3695.c | 2 +- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index bf918790b..bea215a58 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -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); } diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index 71a0068a3..5c37eec0d 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -2254,7 +2254,7 @@ bool hx3695_init(WORK_MODE_T mode) case HRS_MODE: //TYHX_LOG(" hx3695_init mode : HRS_MODE \n"); #ifdef HRS_ALG_LIB - tyhx_hrs_set_living(1, 20, 30); + tyhx_hrs_set_living(1, 15, 30); if(hx3695_hrs_enable()== SENSOR_OP_FAILED) { return false; -- 2.17.1