#include "include.h" #include "func.h" #include "app_variable.h" #if TRACE_EN #define TRACE(...) printf(__VA_ARGS__) #else #define TRACE(...) #endif #define TEST_EN 0 //假数据测试 #define STEPS_DATA_LIMIT "99999" #define KCAL_DATA_LIMIT "99999 千卡" #define DISTANCE_DATA_LIMIT "99999.9 千米" enum { ACTIVITY_STEPS, ACTIVITY_KCAL, ACTIVITY_TIME, /* 圆弧数据 */ COMPO_ID_ARC_STEP = 0x10, COMPO_ID_ARC_HEAT, COMPO_ID_ARC_TIME, }; enum { //文本框 COMPO_ID_TXT_STEPS = 1, COMPO_ID_TXT_KCAL, COMPO_ID_TXT_TIME, COMPO_ID_TXT_KCAL_UNIT, }; typedef struct f_activity_t_ { uint32_t last_steps; uint32_t last_kcal; uint32_t last_distance; u32 data_refresh_tick; UNIT_TYPE last_distanceUnit; } f_activity_t; /* 圆弧相关参数 */ #define ACTIVITY_ARC_WIDTH (30) #define ACTIVITY_ARC_SIZE (240) static int activity_time_data_get(void) { int minute = (SysVariable.pedoInfo.hour * 60) + SysVariable.pedoInfo.minute + (SysVariable.pedoInfo.second / 60); return minute; } static uint8_t activity_time_percent_data_get(void) { int percent = (activity_time_data_get() * 100) / SysVariable.curSportRecord.goalTime; if (percent >= 100) { percent = 100; } return percent; } static uint8_t activity_step_percent_data_get(void) { int percent = SysVariable.curSportRecord.pedo * 100 / SysVariable.curSportRecord.goalPedo; if (percent >= 100) { percent = 100; } return percent; } static uint8_t activity_heat_percent_data_get(void) { int percent = (getCalorie(SysVariable.curSportRecord.pedo) / 1000 * 100) / SysVariable.curSportRecord.goalCalorie; if (percent >= 100) { percent = 100; } return percent; } #if TEST_EN static int cur_steps = 0, cur_kcal = 0, cur_distance = 0; #endif //创建活动记录窗体 compo_form_t *func_activity_form_create(void) { component_t *compo; compo_arc_t *compo_arc; uint32_t res_bin[] = { UI_BUF_ACTIVITY_STEP_BIN, UI_BUF_ACTIVITY_KCAL_BIN, UI_BUF_ACTIVITY_TIME_BIN, }; //新建窗体和背景 compo_form_t *frm = compo_form_create(true); /* 实心外圆弧 */ compo_arc_t *arc = compo_arc_create(frm); /*步数底图*/ compo_arc_set_angles(arc, 1350, 2250); compo_arc_set_alpha(arc,255,0); compo_arc_set_width(arc, ACTIVITY_ARC_WIDTH); compo_arc_set_location(arc, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y , ACTIVITY_ARC_SIZE, ACTIVITY_ARC_SIZE); compo_arc_set_edge_circle(arc, true, true); compo_arc_set_value(arc, 1000); compo_arc_set_color(arc, make_color(22, 24, 84), make_color(0, 0, 0)); /* 时间底图 */ arc = compo_arc_create(frm); compo_arc_set_angles(arc, 2550, 3450); compo_arc_set_alpha(arc,255,0); compo_arc_set_width(arc, ACTIVITY_ARC_WIDTH); compo_arc_set_location(arc, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, ACTIVITY_ARC_SIZE, ACTIVITY_ARC_SIZE); compo_arc_set_edge_circle(arc, true, true); compo_arc_set_value(arc, 1000); compo_arc_set_color(arc, make_color(0, 81, 52), make_color(0, 0, 0)); /* 热量底图 */ arc = compo_arc_create(frm); compo_arc_set_angles(arc, 150, 1050); compo_arc_set_alpha(arc,255,0); compo_arc_set_width(arc, ACTIVITY_ARC_WIDTH); compo_arc_set_location(arc, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y , ACTIVITY_ARC_SIZE, ACTIVITY_ARC_SIZE); compo_arc_set_edge_circle(arc, true, true); compo_arc_set_value(arc, 1000); compo_arc_set_color(arc, make_color(89, 50, 6), make_color(0, 0, 0)); /* 步数进度 */ arc = compo_arc_create(frm); compo_setid(arc, COMPO_ID_ARC_STEP); compo_arc_set_angles(arc, 1350, 2250); compo_arc_set_alpha(arc,255,0); compo_arc_set_width(arc, ACTIVITY_ARC_WIDTH); compo_arc_set_location(arc, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y , ACTIVITY_ARC_SIZE, ACTIVITY_ARC_SIZE); compo_arc_set_edge_circle(arc, true, true); compo_arc_set_value(arc, 0); compo_arc_set_color(arc, make_color(66, 78, 255), make_color(0, 0, 0)); compo_arc_set_visible(arc, false); // /* 时间进度 */ arc = compo_arc_create(frm); compo_setid(arc, COMPO_ID_ARC_TIME); compo_arc_set_angles(arc, 2550, 3450); compo_arc_set_alpha(arc,255,0); compo_arc_set_width(arc, ACTIVITY_ARC_WIDTH); compo_arc_set_location(arc, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y, ACTIVITY_ARC_SIZE, ACTIVITY_ARC_SIZE); compo_arc_set_edge_circle(arc, true, true); compo_arc_set_value(arc, 0); compo_arc_set_color(arc, make_color(0, 233, 150), make_color(0, 0, 0)); compo_arc_set_visible(arc, false); // /* 热量进度 */ arc = compo_arc_create(frm); compo_setid(arc, COMPO_ID_ARC_HEAT); compo_arc_set_angles(arc, 150, 1050); compo_arc_set_alpha(arc,255,0); compo_arc_set_width(arc, ACTIVITY_ARC_WIDTH); compo_arc_set_location(arc, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y , ACTIVITY_ARC_SIZE, ACTIVITY_ARC_SIZE); compo_arc_set_edge_circle(arc, true, true); compo_arc_set_value(arc, 0); compo_arc_set_color(arc, make_color(255, 99, 20), make_color(0, 0, 0)); compo_arc_set_visible(arc, false); compo = (component_t *)compo_picturebox_create(frm, res_bin[ACTIVITY_STEPS]); compo_picturebox_set_pos((compo_picturebox_t *)compo, GUI_SCREEN_CENTER_X, 39+11); //kcal_pic compo = (component_t *)compo_picturebox_create(frm, res_bin[ACTIVITY_KCAL]); compo_picturebox_set_pos((compo_picturebox_t *)compo, GUI_SCREEN_CENTER_X, 93+11); //km_pic compo = (component_t *)compo_picturebox_create(frm, res_bin[ACTIVITY_TIME]); compo_picturebox_set_pos((compo_picturebox_t *)compo, GUI_SCREEN_CENTER_X, 148+11); //steps text compo = (component_t *)compo_textbox_create(frm, sizeof(STEPS_DATA_LIMIT)); compo_textbox_set_font(compo, UI_BUF_0FONT_FONT_NUM_24_BIN); compo_setid(compo, COMPO_ID_TXT_STEPS); compo_textbox_set_pos((compo_textbox_t *)compo, 65 + 34 -5, 66 + 10); compo_textbox_t *txt_step = compo_textbox_create(frm, 5); compo_textbox_set_pos(txt_step, 136 + 20 +5 , 66 + 15); compo_textbox_set_forecolor(txt_step, make_color(7,147,255)); #if defined(__LANGUAGE_SM_CHINESE__) if(tjd_Get_Language_Current_Index() == LANGUAGE_TYPE_Chinese) compo_textbox_set(txt_step, "步数"); else #endif compo_textbox_set(txt_step, "STEPS"); //kcal text compo = (component_t *)compo_textbox_create(frm, sizeof(KCAL_DATA_LIMIT)); compo_textbox_set_font(compo, UI_BUF_0FONT_FONT_NUM_24_BIN); compo_setid(compo, COMPO_ID_TXT_KCAL); compo_textbox_set_pos((compo_textbox_t *)compo, 73+27 -5, 120+10); compo_textbox_t *txt_kcal = compo_textbox_create(frm, 4); compo_textbox_set_pos(txt_kcal, 130+20 +5, 120+15); compo_textbox_set_forecolor(txt_kcal, make_color(255,70,23)); #if defined(__LANGUAGE_SM_CHINESE__) if(tjd_Get_Language_Current_Index() == LANGUAGE_TYPE_Chinese) compo_textbox_set(txt_kcal, "千卡"); else #endif compo_textbox_set(txt_kcal, "KCAL"); //time text compo = (component_t *)compo_textbox_create(frm, sizeof(DISTANCE_DATA_LIMIT)); compo_textbox_set_font(compo, UI_BUF_0FONT_FONT_NUM_24_BIN); compo_setid(compo, COMPO_ID_TXT_TIME); compo_textbox_set_pos((compo_textbox_t *)compo, 87 + 13, 175 + 10); compo_textbox_t *txt_time = compo_textbox_create(frm, 4); compo_setid(txt_time,COMPO_ID_TXT_KCAL_UNIT); compo_textbox_set_pos(txt_time, 116 + 20 +5, 175 + 15); compo_textbox_set_forecolor(txt_time, make_color(0,245,121)); #if defined(__LANGUAGE_SM_CHINESE__) if (tjd_Get_Language_Current_Index() == LANGUAGE_TYPE_Chinese) compo_textbox_set(txt_time, "分钟"); else #endif compo_textbox_set(txt_time, "MIN"); return frm; } //刷新活动数据 static void func_activity_data_refresh(void) { u32 distance; compo_textbox_t *txt_compo; f_activity_t *f_activity = (f_activity_t *)func_cb.f_cb; char text_buf[TEXTBOX_TEXT_BUF_LEN] = {0}; /* 500ms刷新事件 */ if (tick_check_expire(f_activity->data_refresh_tick, 500)) { f_activity->data_refresh_tick = tick_get(); compo_arc_t *step_arc = compo_getobj_byid(COMPO_ID_ARC_STEP); compo_arc_t *heat_arc = compo_getobj_byid(COMPO_ID_ARC_HEAT); compo_arc_t *time_arc = compo_getobj_byid(COMPO_ID_ARC_TIME); compo_textbox_t *step_text = compo_getobj_byid(COMPO_ID_TXT_STEPS); compo_textbox_t *kcal_text = compo_getobj_byid(COMPO_ID_TXT_KCAL); compo_textbox_t *minu_text = compo_getobj_byid(COMPO_ID_TXT_TIME); /* 更新圆弧数据 */ if(step_arc){ compo_arc_set_alpha(step_arc,255,0); compo_arc_set_value(step_arc, activity_step_percent_data_get() * 10 <= 0 ? 0 : activity_step_percent_data_get() * 10); compo_arc_set_visible(step_arc, activity_step_percent_data_get() > 0 ? true : false); } /* 热量进度 */ if(heat_arc){ compo_arc_set_alpha(heat_arc,255,0); compo_arc_set_value(heat_arc, activity_heat_percent_data_get() * 10 <= 0 ? 0 : activity_heat_percent_data_get() * 10); compo_arc_set_visible(heat_arc, activity_heat_percent_data_get() > 0 ? true : false); } /* 时间进度 */ if(time_arc) { compo_arc_set_alpha(time_arc,255,0); compo_arc_set_value(time_arc, activity_time_percent_data_get() * 10 <= 0 ? 0 : activity_time_percent_data_get() * 10); compo_arc_set_visible(time_arc, activity_time_percent_data_get() > 0 ? true : false); } /* 更新时间数据 */ 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); /* 更新详细数据 */ memset(text_buf, 0, sizeof(text_buf)); sprintf(text_buf, "%05d", SysVariable.curSportRecord.pedo); compo_textbox_set(step_text, text_buf); memset(text_buf, 0, sizeof(text_buf)); sprintf(text_buf, "%04d", getCalorie(SysVariable.curSportRecord.pedo)/1000); compo_textbox_set(kcal_text, text_buf); memset(text_buf, 0, sizeof(text_buf)); sprintf(text_buf, "%02d", activity_time_data_get()); compo_textbox_set(minu_text, text_buf); } txt_compo = compo_getobj_byid(COMPO_ID_TXT_KCAL_UNIT); #if defined(__LANGUAGE_SM_CHINESE__) if (tjd_Get_Language_Current_Index() == LANGUAGE_TYPE_Chinese) compo_textbox_set(txt_compo, "分钟"); else #endif compo_textbox_set(txt_compo, "MIN"); } //活动记录功能事件处理 static void func_activity_process(void) { func_activity_data_refresh(); func_process(); } //活动记录功能消息处理 static void func_activity_message(size_msg_t msg) { switch (msg) { case MSG_CTP_CLICK: break; case MSG_CTP_SHORT_UP: break; case MSG_CTP_SHORT_DOWN: break; case MSG_CTP_LONG: break; default: func_message(msg); break; } } //进入活动记录控制功能 static void func_activity_enter(void) { func_cb.f_cb = func_zalloc(sizeof(f_activity_t)); f_activity_t *f_activity = (f_activity_t *)func_cb.f_cb; f_activity->last_steps = 0xfffff; f_activity->last_kcal = 0xfffff; f_activity->last_distance = 0xfffff; f_activity->last_distanceUnit = 0xff; func_cb.frm_main = func_activity_form_create(); // tft_set_temode(false); } //退出活动记录功能 static void func_activity_exit(void) { func_cb.last = FUNC_ACTIVITY; SysVariable.duty_flag = true; // tft_set_temode(DEFAULT_TE_MODE); } //活动记录功能 void func_activity(void) { printf("1111%s\n", __func__); func_activity_enter(); while (func_cb.sta == FUNC_ACTIVITY) { func_activity_process(); func_activity_message(msg_dequeue()); } func_activity_exit(); }