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)
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);
}
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 // 文件已存在 需要判断是否需要补上清醒状态
{
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)
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);
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);
}