830 lines
30 KiB
C
830 lines
30 KiB
C
#include "include.h"
|
|
#include "func.h"
|
|
#include "app_variable.h"
|
|
|
|
#if TRACE_EN
|
|
#define TRACE(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define TRACE(...)
|
|
#endif
|
|
|
|
/* 总页面数 */
|
|
#define SLEEP_PAGE_TOTAL_NUM (3)
|
|
|
|
/* 睡眠时间图表相关参数 */
|
|
#define SLEEP_TIME_CHART_START_X (120) // 图表起始X轴坐标
|
|
#define SLEEP_TIME_CHART_START_Y (112) // 图表起始Y轴坐标
|
|
#define SLEEP_TIME_CHART_END_X (12) // 图表结束X轴坐标
|
|
#define SLEEP_TIME_CHART_UNIT (9) // 图表每小时单位像素
|
|
#define SLEEP_TIME_CHART_RADIUS (5) // 图表打点柱子圆角
|
|
#define SLEEP_TIME_CHART_BAR_HEIGHT (10) // 图表柱子高度
|
|
|
|
/* 每周睡眠时间图表相关参数 */
|
|
#define SLEEP_WEEK_TIME_CHART_NUMBER (7) // 每周睡眠数据个数
|
|
#define SLEEP_WEEK_TIME_CHART_START_X (29) // 图表起始X轴坐标
|
|
#define SLEEP_WEEK_TIME_CHART_START_Y (176) // 图表起始Y轴坐标
|
|
#define SLEEP_WEEK_TIME_CHART_UNIT (8) // 图表每小时单位像素
|
|
#define SLEEP_WEEK_TIME_CHART_RADIUS (5) // 图表打点柱子圆角
|
|
#define SLEEP_WEEK_TIME_CHART_BAR_WIDTH (10) // 图表柱子宽度
|
|
|
|
/* 每周睡眠时间图表动画 */
|
|
#define SLEEP_CHART_ANIM_LOADING_COMPLETE (BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7))
|
|
|
|
/* 组件ID */
|
|
enum
|
|
{
|
|
/* 标题时间更新 */
|
|
COMPO_ID_TITLE_TIME = 0x01,
|
|
COMPO_ID_TITLE_TODAY_TIME,
|
|
COMPO_ID_TITLE_WEEK_TIME,
|
|
|
|
/* 主页 */
|
|
COMPO_ID_MAIN_PIC_ICON = 0x10,
|
|
COMPO_ID_MAIN_TXT_TIP,
|
|
COMPO_ID_MAIN_DEEP_TIME,
|
|
COMPO_ID_MAIN_LIGHT_TIME,
|
|
|
|
/* 睡眠时间 */
|
|
COMPO_ID_TIME_PIC_CHART_BG = 0x20,
|
|
COMPO_ID_TIME_TXT_TIP,
|
|
COMPO_ID_TIME_TXT_TIME,
|
|
COMPO_ID_TIME_CHART_START,
|
|
COMPO_ID_TIME_CHART_END,
|
|
|
|
/* 每周睡眠时间 */
|
|
COMPO_ID_WEEK_TXT_TIME = 0x30,
|
|
COMPO_ID_WEEK_CHART_DEEP_LIGHT,
|
|
};
|
|
|
|
/* 页面ID */
|
|
typedef enum
|
|
{
|
|
SLEEP_PAGE_MAIN = 0x01,
|
|
SLEEP_PAGE_TODAY_TIME,
|
|
SLEEP_PAGE_WEEK_TMER,
|
|
} activity_page_e;
|
|
|
|
typedef struct f_sleep_t_
|
|
{
|
|
/* 页面移动模块 */
|
|
page_tp_move_t *ptm;
|
|
|
|
/* 页面指示器 */
|
|
widget_icon_t *indicator[SLEEP_PAGE_TOTAL_NUM];
|
|
|
|
/* 进场动画 */
|
|
u8 anim_loading_flag;
|
|
u8 anim_loading_deep_state;
|
|
u8 anim_loading_light_state;
|
|
u16 anim_loading_cnt;
|
|
u32 anim_loading_tick;
|
|
|
|
/* 页面数据刷新 */
|
|
u32 data_refresh_tick;
|
|
u32 indicator_refresh_tick;
|
|
} f_sleep_t;
|
|
|
|
/*-----------------各项详细数据获取 START-----------------*/
|
|
#define FUNC_SLEEP_SIMULATE_DATA_EN 0
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
static const uint8_t record_sleep_week_deep[SLEEP_WEEK_TIME_CHART_NUMBER] = {4, 5, 6, 5, 3, 3, 6};
|
|
static const uint8_t record_sleep_week_light[SLEEP_WEEK_TIME_CHART_NUMBER] = {5, 4, 2, 3, 6, 4, 4};
|
|
#endif
|
|
|
|
static uint16_t sleep_deep_time(void)
|
|
{
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
return record_sleep_week_deep[0] * 60;
|
|
#else
|
|
return SysVariable.sleep.deepTime;
|
|
#endif
|
|
}
|
|
static uint16_t sleep_light_time(void)
|
|
{
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
return record_sleep_week_light[0] * 60;
|
|
#else
|
|
return SysVariable.sleep.lightTime;
|
|
#endif
|
|
}
|
|
|
|
/* 每周深睡浅睡时间 */
|
|
static uint8_t sleep_week_deep_time(uint8_t week)
|
|
{
|
|
uint8_t hour = 0;
|
|
|
|
/* 每周图标星期顺序为(周一到周日) */
|
|
week = (week + 1) % 7;
|
|
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
hour = record_sleep_week_deep[week];
|
|
#else
|
|
if (SysVariable.sleep.record_deep_time[week] / 60 < 1 && SysVariable.sleep.record_deep_time[week] % 60 != 0) {
|
|
hour = 1;
|
|
} else {
|
|
hour = (SysVariable.sleep.record_deep_time[week] / 60) + (SysVariable.sleep.record_deep_time[week] % 60 != 0 ? 1 : 0);
|
|
}
|
|
#endif
|
|
|
|
return hour;
|
|
}
|
|
static uint8_t sleep_week_light_time(uint8_t week)
|
|
{
|
|
uint8_t hour = 0;
|
|
|
|
/* 每周图标星期顺序为(周一到周日) */
|
|
week = (week + 1) % 7;
|
|
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
hour = record_sleep_week_light[week];
|
|
#else
|
|
if (SysVariable.sleep.record_light_time[week] / 60 < 1 && SysVariable.sleep.record_light_time[week] % 60 != 0) {
|
|
hour = 1;
|
|
} else {
|
|
hour = (SysVariable.sleep.record_light_time[week] / 60) + (SysVariable.sleep.record_light_time[week] % 60 != 0 ? 1 : 0);
|
|
}
|
|
#endif
|
|
|
|
return hour;
|
|
}
|
|
|
|
/* 每周平均睡眠时间 */
|
|
static uint16_t sleep_week_average_time(void)
|
|
{
|
|
uint8_t days = 0;
|
|
uint16_t avg_time = 0;
|
|
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
for (int i = 0; i < SLEEP_WEEK_TIME_CHART_NUMBER; i++) {
|
|
avg_time += (record_sleep_week_deep[i] * 60) + (record_sleep_week_light[i] * 60);
|
|
|
|
if (record_sleep_week_deep[i] || record_sleep_week_light[i]) {
|
|
days++;
|
|
}
|
|
}
|
|
#else
|
|
for (int i = 0; i < SLEEP_WEEK_TIME_CHART_NUMBER; i++) {
|
|
avg_time += SysVariable.sleep.record_deep_time[i] + SysVariable.sleep.record_light_time[i];
|
|
|
|
if (SysVariable.sleep.record_deep_time[i] || SysVariable.sleep.record_light_time[i]) {
|
|
days++;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
if (!avg_time || !days) {
|
|
return 0;
|
|
} else {
|
|
return avg_time / days;
|
|
}
|
|
}
|
|
|
|
/* 每日开始、结束睡眠时间 */
|
|
static uint16_t sleep_start_time(void)
|
|
{
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
return SLEEP_START_TIME;
|
|
#else
|
|
return SysVariable.sleep.startTime;
|
|
#endif
|
|
}
|
|
static uint16_t sleep_end_time(void)
|
|
{
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
return SLEEP_END_TIME;
|
|
#else
|
|
return SysVariable.sleep.endTime;
|
|
#endif
|
|
}
|
|
|
|
/* 是否存在有效睡眠数据 */
|
|
static bool sleep_is_valid_data(void)
|
|
{
|
|
#if FUNC_SLEEP_SIMULATE_DATA_EN
|
|
return true;
|
|
#else
|
|
if ((SysVariable.Rtc.hour >= (SLEEP_START_TIME / 60)) || (SysVariable.Rtc.hour < (SLEEP_END_TIME / 60))) {
|
|
return false;
|
|
} else {
|
|
return SysVariable.sleep.totalTime > 0 ? true : false;
|
|
}
|
|
#endif
|
|
}
|
|
/*-----------------各项详细数据获取 END-----------------*/
|
|
|
|
static void func_sleep_indicator_update(void)
|
|
{
|
|
f_sleep_t *f_sleep = (f_sleep_t *)func_cb.f_cb;
|
|
|
|
if (f_sleep->ptm->drag_flag == true) {
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < SLEEP_PAGE_TOTAL_NUM; i++) {
|
|
if (f_sleep->indicator[i] == NULL) {
|
|
return;
|
|
}
|
|
widget_icon_set(f_sleep->indicator[i], UI_BUF_SLEEP_UNSELECT_BIN);
|
|
}
|
|
|
|
int page_offset = compo_page_move_get_offset(f_sleep->ptm) * -1;
|
|
int page_idx = page_offset / GUI_SCREEN_HEIGHT;
|
|
if (page_idx < 0 || page_idx >= SLEEP_PAGE_TOTAL_NUM) {
|
|
page_idx = 0;
|
|
}
|
|
widget_icon_set(f_sleep->indicator[page_idx], UI_BUF_SLEEP_SELECT_BIN);
|
|
}
|
|
|
|
static void func_sleep_indicator_create(compo_form_t *frm)
|
|
{
|
|
f_sleep_t *f_sleep = (f_sleep_t *)func_cb.f_cb;
|
|
|
|
if (f_sleep == NULL) {
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < SLEEP_PAGE_TOTAL_NUM; i++) {
|
|
f_sleep->indicator[i] = widget_icon_create(frm->page, UI_BUF_SLEEP_UNSELECT_BIN);
|
|
widget_set_pos(f_sleep->indicator[i], GUI_SCREEN_CENTER_X + 112, (GUI_SCREEN_CENTER_Y - (96 - i * 11)));
|
|
}
|
|
func_sleep_indicator_update();
|
|
}
|
|
|
|
static void func_sleep_title_create(compo_form_t *frm, activity_page_e page)
|
|
{
|
|
char text_buf[TEXTBOX_TEXT_BUF_LEN / 5] = {0};
|
|
|
|
int start_pos_y = GUI_SCREEN_HEIGHT * (page - SLEEP_PAGE_MAIN);
|
|
|
|
/* 标题文本 */
|
|
compo_textbox_t *txt_title = compo_textbox_create(frm, 10);
|
|
compo_textbox_set_align_center(txt_title, false);
|
|
compo_textbox_set_location(txt_title, 28, start_pos_y + 9, GUI_SCREEN_CENTER_X, 30);
|
|
compo_textbox_set(txt_title, i18n[STR_SLEEP]);
|
|
|
|
/* 标题时间 */
|
|
if (SysVariable.deviceInfo.timeType == TIME_TYPE_12_HOUR)
|
|
sprintf(text_buf, "%02d:%02d%s", get_autoformat_hour(SysVariable.Rtc.hour), SysVariable.Rtc.min, SysVariable.Rtc.hour >= 12 ? "PM" : "AM");
|
|
else
|
|
sprintf(text_buf, "%02d:%02d", SysVariable.Rtc.hour, SysVariable.Rtc.min);
|
|
compo_textbox_t *txt_time = compo_textbox_create(frm, 8);
|
|
compo_setid(txt_time, COMPO_ID_TITLE_TIME);
|
|
compo_textbox_set_location(txt_time, 122, start_pos_y + 9, 90, 30);
|
|
compo_textbox_set_right_align(txt_time, true);
|
|
compo_textbox_set_align_center(txt_time, false);
|
|
compo_textbox_set(txt_time, text_buf);
|
|
}
|
|
|
|
/* 更新睡眠时间图表 */
|
|
static void func_sleep_time_chart_update(void)
|
|
{
|
|
int chart_pos_y = GUI_SCREEN_HEIGHT + SLEEP_TIME_CHART_START_Y;
|
|
|
|
compo_shape_t *end_rect = compo_getobj_byid(COMPO_ID_TIME_CHART_END);
|
|
compo_shape_t *start_rect = compo_getobj_byid(COMPO_ID_TIME_CHART_START);
|
|
|
|
bool is_start_time = (sleep_start_time() / 60) - 12 > 0 ? true : false;
|
|
uint8_t start_hour_num = 23 - (sleep_start_time() / 60);
|
|
uint16_t start_pos_x = (sleep_start_time() / 60) - 12;
|
|
if (is_start_time) {
|
|
compo_shape_set_location(start_rect, SLEEP_TIME_CHART_START_X + (start_pos_x * SLEEP_TIME_CHART_UNIT), chart_pos_y,
|
|
start_hour_num * SLEEP_TIME_CHART_UNIT, SLEEP_TIME_CHART_BAR_HEIGHT);
|
|
}
|
|
|
|
uint16_t end_pos_x;
|
|
if ((sleep_start_time() / 60) > 12)
|
|
end_pos_x = SLEEP_TIME_CHART_END_X;
|
|
else
|
|
end_pos_x = SLEEP_TIME_CHART_END_X + ((sleep_start_time() / 60) * SLEEP_TIME_CHART_UNIT);
|
|
|
|
uint8_t end_hour_num;
|
|
if ((sleep_start_time() / 60) > 12)
|
|
end_hour_num = (sleep_end_time() / 60);
|
|
else
|
|
end_hour_num = (sleep_end_time() / 60) - (sleep_start_time() / 60);
|
|
compo_shape_set_location(end_rect, end_pos_x, chart_pos_y, end_hour_num * SLEEP_TIME_CHART_UNIT, SLEEP_TIME_CHART_BAR_HEIGHT);
|
|
|
|
compo_shape_set_visible(end_rect, sleep_is_valid_data());
|
|
compo_shape_set_visible(start_rect, (sleep_is_valid_data() && is_start_time));
|
|
}
|
|
|
|
/* 创建睡眠时间图表 */
|
|
static void func_sleep_time_chart_create(compo_form_t *frm)
|
|
{
|
|
compo_shape_t *start_rect = compo_shape_create(frm, COMPO_SHAPE_TYPE_RECTANGLE);
|
|
compo_setid(start_rect, COMPO_ID_TIME_CHART_START);
|
|
compo_shape_set_color(start_rect, make_color(4, 249, 250));
|
|
compo_shape_set_radius(start_rect, SLEEP_TIME_CHART_RADIUS);
|
|
compo_shape_set_align_center(start_rect, false);
|
|
|
|
compo_shape_t *end_rect = compo_shape_create(frm, COMPO_SHAPE_TYPE_RECTANGLE);
|
|
compo_setid(end_rect, COMPO_ID_TIME_CHART_END);
|
|
compo_shape_set_color(end_rect, make_color(4, 249, 250));
|
|
compo_shape_set_radius(end_rect, SLEEP_TIME_CHART_RADIUS);
|
|
compo_shape_set_align_center(end_rect, false);
|
|
}
|
|
|
|
/* 每周睡眠时间图表进场动画 */
|
|
static void func_sleep_week_time_chart_anim_handle(void)
|
|
{
|
|
f_sleep_t *f_sleep = (f_sleep_t *)func_cb.f_cb;
|
|
|
|
int start_pos_y = (GUI_SCREEN_HEIGHT * 2) + SLEEP_WEEK_TIME_CHART_START_Y;
|
|
|
|
/* 坐标参数 */
|
|
u16 chart_x, deep_chart_y, light_chart_y;
|
|
u16 chart_offser_x[SLEEP_WEEK_TIME_CHART_NUMBER] = {0, 0, 0, 2, 2, 3, 3};
|
|
|
|
/* 深睡部分动画 */
|
|
if (f_sleep->anim_loading_deep_state != SLEEP_CHART_ANIM_LOADING_COMPLETE)
|
|
{
|
|
f_sleep->anim_loading_cnt++;
|
|
for (u8 i = 0; i < SLEEP_WEEK_TIME_CHART_NUMBER; i++)
|
|
{
|
|
chart_x = SLEEP_WEEK_TIME_CHART_START_X + (i * (19 + SLEEP_WEEK_TIME_CHART_BAR_WIDTH)) - chart_offser_x[i];
|
|
|
|
compo_shape_t *deep_chart = compo_getobj_byid((COMPO_ID_WEEK_CHART_DEEP_LIGHT + SLEEP_WEEK_TIME_CHART_NUMBER) + i);
|
|
if (deep_chart == NULL) {
|
|
return;
|
|
}
|
|
|
|
if (f_sleep->anim_loading_cnt <= (SLEEP_WEEK_TIME_CHART_UNIT * sleep_week_deep_time(i))) {
|
|
deep_chart_y = start_pos_y - f_sleep->anim_loading_cnt;
|
|
compo_shape_set_location(deep_chart, chart_x, deep_chart_y, SLEEP_WEEK_TIME_CHART_BAR_WIDTH, f_sleep->anim_loading_cnt);
|
|
} else {
|
|
f_sleep->anim_loading_deep_state |= BIT(i + 1);
|
|
}
|
|
}
|
|
|
|
/* 深睡部分加载完成开始加载浅睡部分 */
|
|
if (f_sleep->anim_loading_deep_state == SLEEP_CHART_ANIM_LOADING_COMPLETE)
|
|
{
|
|
f_sleep->anim_loading_cnt = 0;
|
|
f_sleep->anim_loading_light_state = BIT(0);
|
|
}
|
|
}
|
|
|
|
/* 浅睡部分动画 */
|
|
if (f_sleep->anim_loading_light_state & BIT(0))
|
|
{
|
|
f_sleep->anim_loading_cnt++;
|
|
for (u8 i = 0; i < SLEEP_WEEK_TIME_CHART_NUMBER; i++)
|
|
{
|
|
chart_x = SLEEP_WEEK_TIME_CHART_START_X + (i * (19 + SLEEP_WEEK_TIME_CHART_BAR_WIDTH)) - chart_offser_x[i];
|
|
deep_chart_y = start_pos_y - (SLEEP_WEEK_TIME_CHART_UNIT * sleep_week_deep_time(i));
|
|
|
|
compo_shape_t *light_chart = compo_getobj_byid(COMPO_ID_WEEK_CHART_DEEP_LIGHT + i);
|
|
if (light_chart == NULL) {
|
|
return;
|
|
}
|
|
|
|
if (f_sleep->anim_loading_cnt <= (SLEEP_WEEK_TIME_CHART_UNIT * sleep_week_light_time(i))) {
|
|
light_chart_y = (deep_chart_y - f_sleep->anim_loading_cnt) + (sleep_week_deep_time(i) ? SLEEP_WEEK_TIME_CHART_RADIUS : 0);
|
|
compo_shape_set_location(light_chart, chart_x, light_chart_y, SLEEP_WEEK_TIME_CHART_BAR_WIDTH, f_sleep->anim_loading_cnt);
|
|
} else {
|
|
f_sleep->anim_loading_light_state |= BIT(i + 1);
|
|
}
|
|
}
|
|
|
|
/* 全部动画加载完成 */
|
|
if (f_sleep->anim_loading_light_state == SLEEP_CHART_ANIM_LOADING_COMPLETE)
|
|
{
|
|
f_sleep->anim_loading_cnt = 0;
|
|
f_sleep->anim_loading_flag = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* 更新每周睡眠时间图表 */
|
|
static void func_sleep_week_time_chart_update(void)
|
|
{
|
|
int start_pos_y = (GUI_SCREEN_HEIGHT * 2) + SLEEP_WEEK_TIME_CHART_START_Y;
|
|
|
|
/* 坐标参数 */
|
|
u16 chart_x, deep_chart_y, light_chart_y;
|
|
u16 chart_offser_x[SLEEP_WEEK_TIME_CHART_NUMBER] = {0, 0, 0, 2, 2, 3, 3};
|
|
|
|
for (u8 i = 0; i < SLEEP_WEEK_TIME_CHART_NUMBER; i++)
|
|
{
|
|
chart_x = SLEEP_WEEK_TIME_CHART_START_X + (i * (19 + SLEEP_WEEK_TIME_CHART_BAR_WIDTH)) - chart_offser_x[i];
|
|
|
|
/* 下方深睡部分 */
|
|
compo_shape_t *deep_chart = compo_getobj_byid((COMPO_ID_WEEK_CHART_DEEP_LIGHT + SLEEP_WEEK_TIME_CHART_NUMBER) + i);
|
|
if (deep_chart == NULL) {
|
|
return;
|
|
}
|
|
deep_chart_y = start_pos_y - (SLEEP_WEEK_TIME_CHART_UNIT * sleep_week_deep_time(i));
|
|
compo_shape_set_location(deep_chart, chart_x, deep_chart_y, SLEEP_WEEK_TIME_CHART_BAR_WIDTH, SLEEP_WEEK_TIME_CHART_UNIT * sleep_week_deep_time(i));
|
|
|
|
/* 上方浅睡部分 */
|
|
compo_shape_t *light_chart = compo_getobj_byid(COMPO_ID_WEEK_CHART_DEEP_LIGHT + i);
|
|
if (light_chart == NULL) {
|
|
return;
|
|
}
|
|
light_chart_y = (deep_chart_y - (SLEEP_WEEK_TIME_CHART_UNIT * sleep_week_light_time(i))) + (sleep_week_deep_time(i) ? SLEEP_WEEK_TIME_CHART_RADIUS : 0);
|
|
compo_shape_set_location(light_chart, chart_x, light_chart_y, SLEEP_WEEK_TIME_CHART_BAR_WIDTH, SLEEP_WEEK_TIME_CHART_UNIT * sleep_week_light_time(i));
|
|
|
|
compo_shape_set_visible(deep_chart, sleep_is_valid_data());
|
|
compo_shape_set_visible(light_chart, sleep_is_valid_data());
|
|
}
|
|
}
|
|
|
|
/* 创建每周睡眠时间图表 */
|
|
static void func_sleep_week_time_chart_create(compo_form_t *frm)
|
|
{
|
|
u16 chart_color;
|
|
for (int i = 0; i < (SLEEP_WEEK_TIME_CHART_NUMBER * 2); i++)
|
|
{
|
|
if (i >= SLEEP_WEEK_TIME_CHART_NUMBER)
|
|
chart_color = make_color(87, 48, 199); // 深睡
|
|
else
|
|
chart_color = make_color(4, 249, 250); // 浅睡
|
|
|
|
compo_shape_t *rect = compo_shape_create(frm, COMPO_SHAPE_TYPE_RECTANGLE);
|
|
compo_setid(rect, COMPO_ID_WEEK_CHART_DEEP_LIGHT + i);
|
|
compo_shape_set_color(rect, chart_color);
|
|
compo_shape_set_radius(rect, SLEEP_WEEK_TIME_CHART_RADIUS);
|
|
compo_shape_set_align_center(rect, false);
|
|
}
|
|
}
|
|
|
|
static void func_sleep_total_data_show(compo_form_t *frm)
|
|
{
|
|
char text_buf[TEXTBOX_TEXT_BUF_LEN / 2] = {0};
|
|
|
|
/* 背景 */
|
|
widget_icon_t *icon = widget_icon_create(frm->page, UI_BUF_SLEEP_SLEEP_BG_BIN);
|
|
widget_set_pos(icon, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y);
|
|
|
|
/* 创建标题栏信息 */
|
|
func_sleep_title_create(frm, SLEEP_PAGE_MAIN);
|
|
|
|
/* ICON */
|
|
compo_picturebox_t *pic = compo_picturebox_create(frm, UI_BUF_SLEEP_ICON_SLEEP_BIN);
|
|
compo_setid(pic, COMPO_ID_MAIN_PIC_ICON);
|
|
compo_picturebox_set_pos(pic, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y - 31);
|
|
compo_picturebox_set_visible(pic, sleep_is_valid_data());
|
|
|
|
/* 无睡眠数据文本 */
|
|
compo_textbox_t *txt_null_data = compo_textbox_create(frm, 50);
|
|
compo_setid(txt_null_data, COMPO_ID_MAIN_TXT_TIP);
|
|
compo_textbox_set_location(txt_null_data, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y - 22, 220, 30);
|
|
compo_textbox_set(txt_null_data, i18n[STR_NO_SLEEP_DATA]);
|
|
compo_textbox_set_visible(txt_null_data, !sleep_is_valid_data());
|
|
|
|
/* 深睡数据区 */
|
|
compo_shape_t *rect = compo_shape_create(frm, COMPO_SHAPE_TYPE_RECTANGLE);
|
|
compo_shape_set_color(rect, make_color(87, 48, 199));
|
|
compo_shape_set_location(rect, 9, 214, 10, 10);
|
|
compo_shape_set_align_center(rect, false);
|
|
compo_shape_set_radius(rect, 5);
|
|
|
|
compo_textbox_t *txt_deep_title = compo_textbox_create(frm, 15);
|
|
compo_textbox_set_location(txt_deep_title, 22, 207, 95, 30);
|
|
compo_textbox_set_align_center(txt_deep_title, false);
|
|
compo_textbox_set(txt_deep_title, i18n[STR_DEEP_SLEEP]);
|
|
|
|
if (sleep_is_valid_data())
|
|
sprintf(text_buf, i18n[STR_HOURS_MINUTES], sleep_deep_time() / 60, sleep_deep_time() % 60);
|
|
else
|
|
sprintf(text_buf, "--");
|
|
compo_textbox_t *txt_deep_time = compo_textbox_create(frm, 15);
|
|
compo_setid(txt_deep_time, COMPO_ID_MAIN_DEEP_TIME);
|
|
compo_textbox_set_location(txt_deep_time, 130, 207, 100, 30);
|
|
compo_textbox_set_right_align(txt_deep_time, true);
|
|
compo_textbox_set_align_center(txt_deep_time, false);
|
|
compo_textbox_set(txt_deep_time, text_buf);
|
|
|
|
/* 浅睡数据区 */
|
|
rect = compo_shape_create(frm, COMPO_SHAPE_TYPE_RECTANGLE);
|
|
compo_shape_set_color(rect, make_color(52, 234, 255));
|
|
compo_shape_set_location(rect, 9, 255, 10, 10);
|
|
compo_shape_set_align_center(rect, false);
|
|
compo_shape_set_radius(rect, 5);
|
|
|
|
compo_textbox_t *txt_light_title = compo_textbox_create(frm, 15);
|
|
compo_textbox_set_location(txt_light_title, 22, 247, 100, 30);
|
|
compo_textbox_set_align_center(txt_light_title, false);
|
|
compo_textbox_set(txt_light_title, i18n[STR_LIGHT_SLEEP]);
|
|
|
|
if (sleep_is_valid_data())
|
|
sprintf(text_buf, i18n[STR_HOURS_MINUTES], sleep_light_time() / 60, sleep_light_time() % 60);
|
|
else
|
|
sprintf(text_buf, "--");
|
|
compo_textbox_t *txt_light_time = compo_textbox_create(frm, 15);
|
|
compo_setid(txt_light_time, COMPO_ID_MAIN_LIGHT_TIME);
|
|
compo_textbox_set_location(txt_light_time, 130, 247, 100, 30);
|
|
compo_textbox_set_right_align(txt_light_time, true);
|
|
compo_textbox_set_align_center(txt_light_time, false);
|
|
compo_textbox_set(txt_light_time, text_buf);
|
|
}
|
|
|
|
static void func_sleep_time_data_show(compo_form_t *frm)
|
|
{
|
|
char text_buf[TEXTBOX_TEXT_BUF_LEN / 2] = {0};
|
|
|
|
int start_pos_y = GUI_SCREEN_HEIGHT;
|
|
|
|
/* 创建标题栏信息 */
|
|
func_sleep_title_create(frm, SLEEP_PAGE_TODAY_TIME);
|
|
|
|
/* 无睡眠数据文本 */
|
|
compo_textbox_t *txt_null_data = compo_textbox_create(frm, 50);
|
|
compo_setid(txt_null_data, COMPO_ID_TIME_TXT_TIP);
|
|
compo_textbox_set_location(txt_null_data, GUI_SCREEN_CENTER_X, start_pos_y + GUI_SCREEN_CENTER_Y - 22, 220, 30);
|
|
compo_textbox_set(txt_null_data, i18n[STR_NO_SLEEP_DATA]);
|
|
compo_textbox_set_visible(txt_null_data, !sleep_is_valid_data());
|
|
|
|
/* 表格背景 */
|
|
compo_picturebox_t *pic = compo_picturebox_create(frm, UI_BUF_SLEEP_TIME_BG_BIN);
|
|
compo_setid(pic, COMPO_ID_TIME_PIC_CHART_BG);
|
|
compo_picturebox_set_pos(pic, GUI_SCREEN_CENTER_X, start_pos_y + GUI_SCREEN_CENTER_Y + 37);
|
|
compo_picturebox_set_visible(pic, sleep_is_valid_data());
|
|
|
|
/* 表格内容 */
|
|
func_sleep_time_chart_create(frm);
|
|
func_sleep_time_chart_update();
|
|
|
|
/* 数据文本 */
|
|
compo_textbox_t *txt_sleep_time = compo_textbox_create(frm, 16);
|
|
compo_textbox_set_location(txt_sleep_time, 19, start_pos_y + 217, 200, 30);
|
|
compo_textbox_set_align_center(txt_sleep_time, false);
|
|
compo_textbox_set(txt_sleep_time, i18n[STR_SLEEP_TIME]);
|
|
|
|
txt_sleep_time = compo_textbox_create(frm, 16);
|
|
compo_setid(txt_sleep_time, COMPO_ID_TIME_TXT_TIME);
|
|
compo_textbox_set_location(txt_sleep_time, 19, start_pos_y + 249, 200, 30);
|
|
compo_textbox_set_align_center(txt_sleep_time, false);
|
|
if (sleep_is_valid_data()) {
|
|
if (SysVariable.deviceInfo.timeType == TIME_TYPE_12_HOUR)
|
|
{
|
|
sprintf(text_buf, "%02d:%02d%s-%02d:%02d%s",
|
|
get_autoformat_hour(sleep_start_time() / 60), sleep_start_time() % 60, sleep_start_time() / 60 >= 12 ? "PM" : "AM",
|
|
get_autoformat_hour(sleep_end_time() / 60), sleep_end_time() % 60, sleep_end_time() / 60 >= 12 ? "PM" : "AM");
|
|
}
|
|
else
|
|
{
|
|
sprintf(text_buf, "%02d:%02d-%02d:%02d",
|
|
get_autoformat_hour(sleep_start_time() / 60), sleep_start_time() % 60,
|
|
get_autoformat_hour(sleep_end_time() / 60), sleep_end_time() % 60);
|
|
}
|
|
} else {
|
|
sprintf(text_buf, "--");
|
|
}
|
|
compo_textbox_set(txt_sleep_time, text_buf);
|
|
}
|
|
|
|
static void func_sleep_week_data_show(compo_form_t *frm)
|
|
{
|
|
char text_buf[TEXTBOX_TEXT_BUF_LEN / 2] = {0};
|
|
|
|
int start_pos_y = GUI_SCREEN_HEIGHT * 2;
|
|
|
|
/* 创建标题栏信息 */
|
|
func_sleep_title_create(frm, SLEEP_PAGE_WEEK_TMER);
|
|
|
|
/* 表格背景 */
|
|
compo_form_add_image(frm, UI_BUF_SLEEP_HISTORY_BG_BIN, GUI_SCREEN_CENTER_X, start_pos_y + GUI_SCREEN_CENTER_Y);
|
|
|
|
/* 表格内容 */
|
|
func_sleep_week_time_chart_create(frm);
|
|
|
|
/* 数据文本 */
|
|
compo_textbox_t *txt_sleep_time = compo_textbox_create(frm, 50);
|
|
compo_textbox_set_location(txt_sleep_time, 19, start_pos_y + 217, 200, 30);
|
|
compo_textbox_set_align_center(txt_sleep_time, false);
|
|
compo_textbox_set(txt_sleep_time, i18n[STR_PAST_WEEK_SLEEP]);
|
|
|
|
txt_sleep_time = compo_textbox_create(frm, 15);
|
|
compo_setid(txt_sleep_time, COMPO_ID_WEEK_TXT_TIME);
|
|
compo_textbox_set_location(txt_sleep_time, 19, start_pos_y + 247, 200, 30);
|
|
compo_textbox_set_align_center(txt_sleep_time, false);
|
|
if (sleep_is_valid_data()) {
|
|
sprintf(text_buf, i18n[STR_HOURS_MINUTES], sleep_week_average_time() / 60, sleep_week_average_time() % 60);
|
|
} else {
|
|
sprintf(text_buf, "--");
|
|
}
|
|
compo_textbox_set(txt_sleep_time, text_buf);
|
|
}
|
|
|
|
static void func_sleep_detail_create(compo_form_t *frm)
|
|
{
|
|
/* 当天睡眠时间界面 */
|
|
func_sleep_time_data_show(frm);
|
|
|
|
/* 每周睡眠时间界面 */
|
|
func_sleep_week_data_show(frm);
|
|
|
|
/* 显示页面指示器 */
|
|
func_sleep_indicator_create(frm);
|
|
}
|
|
|
|
/* 创建睡眠窗体 */
|
|
compo_form_t *func_sleep_form_create(void)
|
|
{
|
|
/* 创建窗体 */
|
|
compo_form_t *frm = compo_form_create(true);
|
|
|
|
func_sleep_total_data_show(frm);
|
|
|
|
return frm;
|
|
}
|
|
|
|
/* 刷新睡眠 */
|
|
static void func_sleep_refresh(void)
|
|
{
|
|
f_sleep_t *f_sleep = (f_sleep_t *)func_cb.f_cb;
|
|
|
|
char text_buf[TEXTBOX_TEXT_BUF_LEN] = {0};
|
|
|
|
/* 10ms进场动画刷新 */
|
|
if (tick_check_expire(f_sleep->anim_loading_tick, 10) && !f_sleep->anim_loading_flag && sleep_is_valid_data())
|
|
{
|
|
f_sleep->anim_loading_tick = tick_get();
|
|
|
|
int page_offset = compo_page_move_get_offset(f_sleep->ptm) * -1;
|
|
int page_idx = page_offset / GUI_SCREEN_HEIGHT;
|
|
if (page_idx == (SLEEP_PAGE_WEEK_TMER - SLEEP_PAGE_MAIN))
|
|
{
|
|
/* 睡眠图表加载动画开始 */
|
|
if (f_sleep->anim_loading_deep_state == 0) {
|
|
f_sleep->anim_loading_deep_state |= BIT(0);
|
|
}
|
|
}
|
|
|
|
if (f_sleep->anim_loading_deep_state & BIT(0))
|
|
{
|
|
func_sleep_week_time_chart_anim_handle();
|
|
}
|
|
}
|
|
|
|
/* 1分钟刷新事件 */
|
|
if (tick_check_expire(f_sleep->data_refresh_tick, 1000 * 60))
|
|
{
|
|
f_sleep->data_refresh_tick = tick_get();
|
|
|
|
/* 主页数据更新 */
|
|
{
|
|
compo_textbox_t *txt_null_data = compo_getobj_byid(COMPO_ID_MAIN_TXT_TIP);
|
|
compo_textbox_t *txt_deep_time = compo_getobj_byid(COMPO_ID_MAIN_DEEP_TIME);
|
|
compo_textbox_t *txt_light_time = compo_getobj_byid(COMPO_ID_MAIN_LIGHT_TIME);
|
|
compo_picturebox_t *main_data_bg = compo_getobj_byid(COMPO_ID_MAIN_PIC_ICON);
|
|
|
|
if (sleep_is_valid_data())
|
|
sprintf(text_buf, i18n[STR_HOURS_MINUTES], sleep_deep_time() / 60, sleep_deep_time() % 60);
|
|
else
|
|
sprintf(text_buf, "--");
|
|
compo_textbox_set(txt_deep_time, text_buf);
|
|
|
|
if (sleep_is_valid_data())
|
|
sprintf(text_buf, i18n[STR_HOURS_MINUTES], sleep_light_time() / 60, sleep_light_time() % 60);
|
|
else
|
|
sprintf(text_buf, "--");
|
|
compo_textbox_set(txt_light_time, text_buf);
|
|
|
|
compo_textbox_set_visible(txt_null_data, !sleep_is_valid_data());
|
|
compo_picturebox_set_visible(main_data_bg, sleep_is_valid_data());
|
|
}
|
|
|
|
/* 睡眠时间页面数据更新 */
|
|
{
|
|
compo_textbox_t *txt_null_data = compo_getobj_byid(COMPO_ID_TIME_TXT_TIP);
|
|
compo_textbox_t *txt_sleep_time = compo_getobj_byid(COMPO_ID_TIME_TXT_TIME);
|
|
compo_picturebox_t *sleep_data_bg = compo_getobj_byid(COMPO_ID_TIME_PIC_CHART_BG);
|
|
|
|
func_sleep_time_chart_update();
|
|
|
|
compo_textbox_set_visible(txt_null_data, !sleep_is_valid_data());
|
|
compo_picturebox_set_visible(sleep_data_bg, sleep_is_valid_data());
|
|
|
|
if (sleep_is_valid_data()) {
|
|
sprintf(text_buf, "%02d:%02d-%02d:%02d",
|
|
get_autoformat_hour(sleep_start_time() / 60), sleep_start_time() % 60,
|
|
get_autoformat_hour(sleep_end_time() / 60), sleep_end_time() % 60);
|
|
} else {
|
|
sprintf(text_buf, "--");
|
|
}
|
|
compo_textbox_set(txt_sleep_time, text_buf);
|
|
}
|
|
|
|
/* 每周睡眠数据更新 */
|
|
{
|
|
compo_textbox_t *txt_sleep_time = compo_getobj_byid(COMPO_ID_WEEK_TXT_TIME);
|
|
|
|
/* 加载完动画再做定时刷新动作 */
|
|
if (f_sleep->anim_loading_flag) {
|
|
func_sleep_week_time_chart_update();
|
|
}
|
|
|
|
if (sleep_is_valid_data()) {
|
|
sprintf(text_buf, i18n[STR_HOURS_MINUTES], sleep_week_average_time() / 60, sleep_week_average_time() % 60);
|
|
} else {
|
|
sprintf(text_buf, "--");
|
|
}
|
|
compo_textbox_set(txt_sleep_time, text_buf);
|
|
}
|
|
}
|
|
|
|
/* 50ms刷新事件 */
|
|
if (tick_check_expire(f_sleep->indicator_refresh_tick, 50))
|
|
{
|
|
f_sleep->indicator_refresh_tick = tick_get();
|
|
|
|
/* 更新页面指示器 */
|
|
func_sleep_indicator_update();
|
|
}
|
|
}
|
|
|
|
/* 睡眠功能事件处理 */
|
|
static void func_sleep_process(void)
|
|
{
|
|
f_sleep_t *f_sleep = (f_sleep_t *)func_cb.f_cb;
|
|
compo_page_move_process(f_sleep->ptm);
|
|
|
|
func_sleep_refresh();
|
|
func_process();
|
|
}
|
|
|
|
/* 睡眠功能消息处理 */
|
|
static void func_sleep_message(size_msg_t msg)
|
|
{
|
|
f_sleep_t *f_sleep = (f_sleep_t *)func_cb.f_cb;
|
|
|
|
switch (msg)
|
|
{
|
|
case MSG_CTP_TOUCH:
|
|
compo_page_move_touch_handler(f_sleep->ptm);
|
|
break;
|
|
|
|
case MSG_CTP_CLICK:
|
|
case MSG_CTP_SHORT_UP:
|
|
case MSG_CTP_SHORT_DOWN:
|
|
case MSG_CTP_LONG:
|
|
break;
|
|
|
|
case MSG_QDEC_BACKWARD:
|
|
if (func_cb.flag_sort) { // 快捷应用状态下不滚动页面
|
|
func_message(msg);
|
|
} else {
|
|
compo_page_move_set_by_pages(f_sleep->ptm, -1);
|
|
}
|
|
break;
|
|
|
|
case MSG_QDEC_FORWARD:
|
|
if (func_cb.flag_sort) {
|
|
func_message(msg);
|
|
} else {
|
|
compo_page_move_set_by_pages(f_sleep->ptm, 1);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
func_message(msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* 进入睡眠功能 */
|
|
static void func_sleep_enter(void)
|
|
{
|
|
func_cb.f_cb = func_zalloc(sizeof(f_sleep_t));
|
|
func_cb.frm_main = func_sleep_form_create();
|
|
|
|
f_sleep_t *f_sleep = (f_sleep_t *)func_cb.f_cb;
|
|
f_sleep->ptm = (page_tp_move_t *)func_zalloc(sizeof(page_tp_move_t));
|
|
|
|
page_move_info_t info = {
|
|
.title_used = false,
|
|
.page_size = GUI_SCREEN_HEIGHT,
|
|
.page_count = SLEEP_PAGE_TOTAL_NUM,
|
|
.jump_perc = 1,
|
|
.quick_jump_perc = 0,
|
|
.up_over_perc = 0,
|
|
.down_over_perc = 0,
|
|
};
|
|
compo_page_move_init(f_sleep->ptm, func_cb.frm_main->page_body, &info);
|
|
|
|
/* 进入界面后再创建详细界面,减少切换动画负担得以快速进入 */
|
|
func_sleep_detail_create(func_cb.frm_main);
|
|
}
|
|
|
|
/* 退出睡眠功能 */
|
|
static void func_sleep_exit(void)
|
|
{
|
|
f_sleep_t *f_sleep = (f_sleep_t *)func_cb.f_cb;
|
|
if (f_sleep->ptm) {
|
|
func_free(f_sleep->ptm);
|
|
}
|
|
}
|
|
|
|
/* 睡眠功能 */
|
|
void func_sleep(void)
|
|
{
|
|
func_sleep_enter();
|
|
while (func_cb.sta == FUNC_SLEEP) {
|
|
func_sleep_process();
|
|
func_sleep_message(msg_dequeue());
|
|
}
|
|
func_sleep_exit();
|
|
}
|