From: penglei <1624952103@qq.com> Date: Tue, 3 Dec 2024 08:54:02 +0000 (+0800) Subject: 优化debug界面佩戴信息存储 X-Git-Tag: fd230_release_V1.3.102~3^2~8^2~1 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F1489%2F3;p=mirrors%2FFD230.git 优化debug界面佩戴信息存储 --- diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 39895b1b5..50899c18a 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -1911,18 +1911,60 @@ void cywee_custom_save_nap_data(void) uapi_dev_runtime_set_sleep_storage_status(0); } -void cywee_custom_save_wear_data(void) +void wear_file_check(SLEEP_STAT_T newStruct, const char *filename) { - int len = uapi_get_file_size("user/userdata/wear.bin"); - if(len > sizeof(SLEEP_STAT_T) * 50) + FILE *fp; + SLEEP_STAT_T data[50]; + 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(SLEEP_STAT_T); + fseek(fp, 0, SEEK_SET); + // PRINT("battery data count %d \n",count); + if (count >= 50) + { + fread(data, sizeof(SLEEP_STAT_T), count, fp); + + for (int i = 1; i < count; i++) + { + if (data[i].timestamp < data[oldest].timestamp) + { + oldest = i; + } + } + + data[oldest] = newStruct; + + fseek(fp, 0, SEEK_SET); + fwrite(data, sizeof(SLEEP_STAT_T), count, fp); + } + else { - uapi_delete_files("user/userdata/wear.bin"); + fseek(fp, 0, SEEK_END); + fwrite(&newStruct, sizeof(SLEEP_STAT_T), 1, fp); } + + fclose(fp); +} + + +void cywee_custom_save_wear_data(void) +{ + // int len = uapi_get_file_size("user/userdata/wear.bin"); + // if(len > sizeof(SLEEP_STAT_T) * 50) + // { + // uapi_delete_files("user/userdata/wear.bin"); + // } SLEEP_STAT_T data; uint32_t tm = 0; uapi_get_timestampe_ss(&tm); data.timestamp = tm; data.stat = wear_status; // CWM_OS_dbgPrintf("data.timestamp : %d , data.stat : %d\n", data.timestamp,data.stat); - uapi_save_file_data("user/userdata/wear.bin",&data,sizeof(SLEEP_STAT_T),"ab"); + // uapi_save_file_data("user/userdata/wear.bin",&data,sizeof(SLEEP_STAT_T),"ab"); + wear_file_check(data,"user/userdata/wear.bin"); }