From 0b0ac9cf3a54e59fc4b196ea32b2c6e9e25a1186 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 16 Jul 2024 16:05:51 +0800 Subject: [PATCH] =?utf8?q?=E6=AD=A5=E6=95=B0=E6=95=B0=E6=8D=AE=E5=90=8C?= =?utf8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../drivers/peripheral/cywee/Inc/cywee_hal.h | 3 + .../peripheral/cywee/src/board_yh601s.c | 91 ++++++++++++++++++- .../drivers/peripheral/cywee/src/main_dml.c | 18 +++- 3 files changed, 104 insertions(+), 8 deletions(-) diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index a1818f5ad..69529db30 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -38,9 +38,12 @@ extern int CWM_OS_i2cTransfer(uint16_t slaveAddr, uint16_t reg, int regLength, u extern void* CWM_OS_malloc(int size); extern void CWM_OS_free(void *ptr); extern void CWM_OS_saveData(int* data, uint32_t len,uint8_t type); +extern void CWM_OS_OneHourAgo_saveData(int* data, uint32_t len,uint8_t type); + extern void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t type); extern void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len); extern void CWM_OS_restoreData(int* data, uint32_t len,uint8_t type); +extern void CWM_OS_OneHourAgo_restoreData(int* data, uint32_t len,uint8_t type); /********************CYWEE LIB*************************/ diff --git a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c index 43ea7cda1..474e6fdd2 100644 --- a/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c +++ b/code/sdk/drivers/peripheral/cywee/src/board_yh601s.c @@ -274,6 +274,12 @@ typedef enum { #define CWM_DISTANCE_DATA_PATH "/user/userdata/sport/distancecount.bin" #define CWM_FAT_DATA_PATH "/user/userdata/sport/fatcount.bin" +#define CWM_STEP_DATA_PATH_AGO "/user/userdata/sport/stepcount_ago.bin" +#define CWM_CALORIES_DATA_PATH_AGO "/user/userdata/sport/caloriescount_ago.bin" +#define CWM_DISTANCE_DATA_PATH_AGO "/user/userdata/sport/distancecount_ago.bin" +#define CWM_FAT_DATA_PATH_AGO "/user/userdata/sport/fatcount_ago.bin" + + #define CWM_DATA_DIR_PATH "/user/userdata/sport" #include void CWM_OS_saveData(int* data, uint32_t len,uint8_t type){ @@ -322,6 +328,50 @@ void CWM_OS_saveData(int* data, uint32_t len,uint8_t type){ } +void CWM_OS_OneHourAgo_saveData(int* data, uint32_t len,uint8_t type){ + + struct stat info; + + if (stat(CWM_DATA_DIR_PATH, &info) != 0) + { + if (mkdir(CWM_DATA_DIR_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) + { + return ; // Failed to create folder + } + } + FILE * fp=NULL; + switch (type) + { + case CYWEE_DATA_CALORIES: + fp = fopen(CWM_CALORIES_DATA_PATH_AGO ,"wb"); + break; + case CYWEE_DATA_STEP: + fp = fopen(CWM_STEP_DATA_PATH_AGO ,"wb"); + break; + case CYWEE_DATA_DISTANCE: + fp = fopen(CWM_DISTANCE_DATA_PATH_AGO ,"wb"); + break; + case CYWEE_DATA_FAT: + fp = fopen(CWM_FAT_DATA_PATH_AGO ,"wb"); + break; + + default: + break; + } + + if(fp==NULL) + { + CWM_OS_dbgPrintf("%s open fail\n",CWM_STEP_DATA_PATH_AGO ); + return; + } + int ret =fwrite(data,1,len,fp); + + CWM_OS_dbgPrintf("CWM_OS_saveData fwrite failed %d %d\n",ret,*data); + + fclose(fp); +} + + #define CWM_HISTORY_DATA_PATH "/user/userdata/goal/step_" @@ -378,9 +428,6 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t ty { data=0; *history=0; - //CWM_OS_dbgPrintf("异常 清除步数数据\n"); - //return; - } FILE * fp = fopen(path_,"ab+"); @@ -397,6 +444,7 @@ void CWM_OS_saveData_history(int* new_data,int *history ,uint32_t len,uint8_t ty CWM_OS_dbgPrintf("uapi_get_timestampe_ss %d %d\n",ret,creationTime); + creationTime=creationTime-60*60;//当前值计入上小时 ret =fwrite(&creationTime,1,4,fp); if(ret==0) @@ -452,7 +500,7 @@ void CWM_OS_saveData_STAND_history(uint8_t *falg,uint32_t len){ uint32_t creationTime; int ret =uapi_get_timestampe_ss(&creationTime); - creationTime=creationTime-60*60; + creationTime=creationTime-60*60;//当前值计入上小时 CWM_OS_dbgPrintf("uapi_get_timestampe_ss %d\n",ret); ret =fwrite(&creationTime,1,len,fp); @@ -500,6 +548,41 @@ void CWM_OS_restoreData(int* data, uint32_t len,uint8_t type){ } + if(fp==NULL) + { + CWM_OS_dbgPrintf("%s open fail\n",CWM_HISTORY_DATA_PATH);; + return; + } + int ret =fread(data,1,len,fp); + + CWM_OS_dbgPrintf("CWM_OS_restoreData fread failed %d %d\n",ret,*data); + + fclose(fp); +} + +void CWM_OS_OneHourAgo_restoreData(int* data, uint32_t len,uint8_t type){ + + + FILE * fp=NULL; + switch (type) + { + case CYWEE_DATA_CALORIES: + fp = fopen(CWM_CALORIES_DATA_PATH_AGO,"rb"); + break; + case CYWEE_DATA_STEP: + fp = fopen(CWM_STEP_DATA_PATH_AGO,"rb"); + break; + case CYWEE_DATA_DISTANCE: + fp = fopen(CWM_DISTANCE_DATA_PATH_AGO,"rb"); + break; + case CYWEE_DATA_FAT: + fp = fopen(CWM_FAT_DATA_PATH_AGO,"rb"); + break; + default: + break; + } + + if(fp==NULL) { CWM_OS_dbgPrintf("%s open fail\n",CWM_HISTORY_DATA_PATH);; diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 835667bdf..c0bf8f0b6 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -110,30 +110,39 @@ void cywee_save_data(void) stepcount+=history_step; CWM_OS_saveData(&stepcount,sizeof(int),CYWEE_SAVE_DATA_STEP); + CWM_OS_OneHourAgo_saveData(&history_step_,sizeof(int),CYWEE_SAVE_DATA_STEP); + + new_calories+=history_calories; CWM_OS_saveData(&(new_calories),sizeof(int),CYWEE_SAVE_DATA_CALORIES); + CWM_OS_OneHourAgo_saveData(&history_calories_,sizeof(int),CYWEE_SAVE_DATA_CALORIES); + new_distance+=history_distances; CWM_OS_saveData(&(new_distance),sizeof(int),CYWEE_SAVE_DATA_DISTANCE); + CWM_OS_OneHourAgo_saveData(&history_distances_,sizeof(int),CYWEE_SAVE_DATA_DISTANCE); new_fat+=history_fat; CWM_OS_saveData(&new_fat,sizeof(int),CYWEE_SAVE_DATA_FAT); + CWM_OS_OneHourAgo_saveData(&history_fat_,sizeof(int),CYWEE_SAVE_DATA_FAT); } void cywee_restoreData(void) { CWM_OS_restoreData(&history_step,sizeof(int),CYWEE_SAVE_DATA_STEP); - history_step_=history_step; + CWM_OS_OneHourAgo_restoreData(&history_step_,sizeof(int),CYWEE_SAVE_DATA_STEP); CWM_OS_restoreData(&history_calories,sizeof(int),CYWEE_SAVE_DATA_CALORIES); - history_calories_=history_calories; + CWM_OS_OneHourAgo_restoreData(&history_calories_,sizeof(int),CYWEE_SAVE_DATA_CALORIES); CWM_OS_restoreData(&history_distances,sizeof(int),CYWEE_SAVE_DATA_DISTANCE); - history_distances_=history_distances; + CWM_OS_OneHourAgo_restoreData(&history_distances_,sizeof(int),CYWEE_SAVE_DATA_DISTANCE); + CWM_OS_restoreData(&history_fat,sizeof(int),CYWEE_SAVE_DATA_FAT); - history_fat_=history_fat; + CWM_OS_OneHourAgo_restoreData(&history_fat_,sizeof(int),CYWEE_SAVE_DATA_FAT); + //WM_OS_restoreData(int* data, uint32_t len,uint8_t type)(int* data, uint32_t len,uint8_t type); } @@ -146,6 +155,7 @@ void set_step_data(uint32_t data) uint32_t get_step_data(void) { + return stepcount+history_step; } -- 2.17.1