451 lines
14 KiB
C
451 lines
14 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 TEST_EN 0 //假数据测试
|
|
|
|
|
|
#if 1
|
|
|
|
#define STEPS_DATA_LIMIT "99999"
|
|
#define KCAL_DATA_LIMIT "99999 千卡"
|
|
#define DISTANCE_DATA_LIMIT "99999.9 千米"
|
|
|
|
enum
|
|
{
|
|
ACTIVITY_STEPS,
|
|
ACTIVITY_KCAL,
|
|
ACTIVITY_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;
|
|
UNIT_TYPE last_distanceUnit;
|
|
} f_activity_t;
|
|
|
|
#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_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME);
|
|
compo_form_set_title(frm, i18n[STR_ACTIVITY_RECORD]);
|
|
|
|
//函数方法画圆形
|
|
// compo_arc = (component_t *)compo_arc_create(frm);
|
|
// compo_arc_set_location(compo_arc,44+9,73+9,20,20);
|
|
// compo_arc_set_size(compo_arc,20,20);
|
|
// compo_arc_set_angles
|
|
// compo_arc_set_rotation
|
|
// compo_arc_set_width
|
|
// compo_arc_set_color
|
|
//step_pic
|
|
compo = (component_t *)compo_picturebox_create(frm, res_bin[ACTIVITY_STEPS]);
|
|
compo_picturebox_set_pos((compo_picturebox_t *)compo, 44+9, 73+5);
|
|
|
|
//kcal_pic
|
|
compo = (component_t *)compo_picturebox_create(frm, res_bin[ACTIVITY_KCAL]);
|
|
compo_picturebox_set_pos((compo_picturebox_t *)compo, 44+9, 152+5);
|
|
|
|
//km_pic
|
|
compo = (component_t *)compo_picturebox_create(frm, res_bin[ACTIVITY_TIME]);
|
|
compo_picturebox_set_pos((compo_picturebox_t *)compo, 44+9, 233+5);
|
|
|
|
//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_textbox_set_align_center(compo, false);
|
|
compo_setid(compo, COMPO_ID_TXT_STEPS);
|
|
compo_textbox_set_pos((compo_textbox_t *)compo, 94, 60);
|
|
|
|
compo_textbox_t *txt_step = compo_textbox_create(frm, 5);
|
|
compo_textbox_set_pos(txt_step, 94, 92);
|
|
compo_textbox_set_align_center(txt_step, false);
|
|
compo_textbox_set_forecolor(txt_step, make_color(17,134,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_textbox_set_align_center((compo_textbox_t *)compo, false);
|
|
compo_setid(compo, COMPO_ID_TXT_KCAL);
|
|
compo_textbox_set_pos((compo_textbox_t *)compo, 94, 142);
|
|
|
|
compo_textbox_t *txt_kcal = compo_textbox_create(frm, 4);
|
|
compo_textbox_set_pos(txt_kcal, 94, 170);
|
|
compo_textbox_set_align_center(txt_kcal, false);
|
|
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_textbox_set_align_center((compo_textbox_t *)compo, false);
|
|
compo_setid(compo, COMPO_ID_TXT_TIME);
|
|
compo_textbox_set_pos((compo_textbox_t *)compo, 94, 220);
|
|
|
|
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, 94, 252);
|
|
compo_textbox_set_align_center(txt_time, false);
|
|
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)
|
|
{
|
|
if(SysVariable.deviceInfo.distanceUnit==UNIT_TYPE_INCH){
|
|
compo_textbox_set(txt_time, "英里");
|
|
}else{
|
|
compo_textbox_set(txt_time, "千米");
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
if(SysVariable.deviceInfo.distanceUnit==UNIT_TYPE_INCH){
|
|
compo_textbox_set(txt_time, "MILE");
|
|
}else{
|
|
compo_textbox_set(txt_time, "KM");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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 buf[16] = {0};
|
|
|
|
//获取当前值(从存储接口或外设接口获取)
|
|
// SysVariable.curSportRecord.pedo = 10000;
|
|
if (f_activity->last_steps != SysVariable.curSportRecord.pedo) {
|
|
txt_compo = compo_getobj_byid(COMPO_ID_TXT_STEPS);
|
|
snprintf(buf, sizeof(buf), "%05d", SysVariable.curSportRecord.pedo);
|
|
compo_textbox_set(txt_compo, buf);
|
|
f_activity->last_steps = SysVariable.curSportRecord.pedo;
|
|
}
|
|
|
|
if (f_activity->last_kcal != getCalorie(SysVariable.curSportRecord.pedo)/1000) {
|
|
txt_compo = compo_getobj_byid(COMPO_ID_TXT_KCAL);
|
|
snprintf(buf, sizeof(buf), "%04d", getCalorie(SysVariable.curSportRecord.pedo)/1000 );
|
|
compo_textbox_set(txt_compo, buf);
|
|
f_activity->last_kcal = getCalorie(SysVariable.curSportRecord.pedo)/1000;
|
|
}
|
|
|
|
if (f_activity->last_distance != getDistance(SysVariable.curSportRecord.pedo) ||
|
|
f_activity->last_distanceUnit != SysVariable.deviceInfo.distanceUnit) {
|
|
int32_t distance = getDistance(SysVariable.curSportRecord.pedo);
|
|
txt_compo = compo_getobj_byid(COMPO_ID_TXT_TIME);
|
|
if (SysVariable.deviceInfo.distanceUnit == 1) {
|
|
distance = distance * 6 / 10; // 转英制数据
|
|
}
|
|
snprintf(buf, sizeof(buf), "%d.%02d", distance / 1000, distance % 1000 / 10);
|
|
compo_textbox_set(txt_compo, buf);
|
|
f_activity->last_distance = getDistance(SysVariable.curSportRecord.pedo);
|
|
}
|
|
|
|
if (f_activity->last_distanceUnit != SysVariable.deviceInfo.distanceUnit) {
|
|
txt_compo = compo_getobj_byid(COMPO_ID_TXT_KCAL_UNIT);
|
|
#if defined(__LANGUAGE_SM_CHINESE__)
|
|
if(tjd_Get_Language_Current_Index() == LANGUAGE_TYPE_Chinese)
|
|
{
|
|
if (SysVariable.deviceInfo.distanceUnit == UNIT_TYPE_INCH) {
|
|
compo_textbox_set(txt_compo, "英里");
|
|
} else {
|
|
compo_textbox_set(txt_compo, "千米");
|
|
}
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
if (SysVariable.deviceInfo.distanceUnit == UNIT_TYPE_INCH) {
|
|
compo_textbox_set(txt_compo, "MILE");
|
|
} else {
|
|
compo_textbox_set(txt_compo, "KM");
|
|
}
|
|
}
|
|
|
|
f_activity->last_distanceUnit = SysVariable.deviceInfo.distanceUnit;
|
|
}
|
|
}
|
|
|
|
//活动记录功能事件处理
|
|
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();
|
|
}
|
|
|
|
//退出活动记录功能
|
|
static void func_activity_exit(void)
|
|
{
|
|
func_cb.last = FUNC_ACTIVITY;
|
|
SysVariable.duty_flag = true;
|
|
}
|
|
|
|
//活动记录功能
|
|
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();
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
enum
|
|
{
|
|
ARC_ANIM_STATUS_START = 0,
|
|
ARC_ANIM_STATUS_FW,
|
|
ARC_ANIM_STATUS_BW,
|
|
ARC_ANIM_STATUS_END,
|
|
};
|
|
|
|
enum
|
|
{
|
|
//文本框
|
|
COMPO_ID_ARC_START = 1,
|
|
COMPO_ID_ARC_END = 3,
|
|
};
|
|
|
|
typedef struct f_activity_t_ {
|
|
uint32_t tick;
|
|
uint32_t last_steps;
|
|
uint32_t last_kcal;
|
|
uint32_t last_distance;
|
|
|
|
u16 value[3];
|
|
u8 anim_status;
|
|
} f_activity_t;
|
|
|
|
// size, arc_w, rotation, s_angle, e_angle, content_color, bg_color
|
|
static const int16_t activity_arc_info[][7] = {
|
|
{300, 30, 0, 0, 3600, COLOR_BLUE, COLOR_WHITE}, //kcal
|
|
{220, 30, 0, 3600, 0, 0x9772, COLOR_WHITE}, //steps
|
|
{140, 30, 0, 0, 3600, 0xfbea, COLOR_WHITE}, //exervise
|
|
};
|
|
static const u16 activity_arc_value_goal[3] = {750, 750, 1000};
|
|
|
|
//创建活动记录窗体
|
|
compo_form_t *func_activity_form_create(void)
|
|
{
|
|
//新建窗体和背景
|
|
compo_form_t *frm = compo_form_create(true);
|
|
|
|
//设置标题栏
|
|
compo_form_set_mode(frm, COMPO_FORM_MODE_SHOW_TITLE | COMPO_FORM_MODE_SHOW_TIME);
|
|
compo_form_set_title(frm, i18n[STR_ACTIVITY_RECORD]);
|
|
|
|
//创建圆弧
|
|
for (u8 i = 0; i < sizeof(activity_arc_info) / sizeof(activity_arc_info[0]); i++) {
|
|
compo_arc_t *arc = compo_arc_create(frm);
|
|
compo_setid(arc, COMPO_ID_ARC_START + i);
|
|
compo_arc_set_alpha(arc, 0xff, 0);
|
|
compo_arc_set_location(arc, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 40, activity_arc_info[i][0], activity_arc_info[i][0]);
|
|
compo_arc_set_width(arc, activity_arc_info[i][1]);
|
|
compo_arc_set_rotation(arc, activity_arc_info[i][2]);
|
|
compo_arc_set_angles(arc, activity_arc_info[i][3], activity_arc_info[i][4]);
|
|
compo_arc_set_color(arc, activity_arc_info[i][5], activity_arc_info[i][6]);
|
|
}
|
|
|
|
return frm;
|
|
}
|
|
|
|
//活动记录功能事件处理
|
|
static void func_activity_process(void)
|
|
{
|
|
int i = 0;
|
|
f_activity_t *f_activity = (f_activity_t *)func_cb.f_cb;
|
|
|
|
func_process();
|
|
if (ARC_ANIM_STATUS_END == f_activity->anim_status) {
|
|
return ;
|
|
}
|
|
|
|
if(tick_check_expire(f_activity->tick, 10)) {
|
|
f_activity->tick = tick_get();
|
|
u8 count = sizeof(f_activity->value) / sizeof(f_activity->value[0]);
|
|
|
|
switch (f_activity->anim_status) {
|
|
case ARC_ANIM_STATUS_START:
|
|
{
|
|
for (i = 0; i < count; i++) {
|
|
f_activity->value[i] = 0;
|
|
}
|
|
f_activity->anim_status = ARC_ANIM_STATUS_FW;
|
|
}break;
|
|
|
|
case ARC_ANIM_STATUS_FW:
|
|
{
|
|
for (i = 0; i < count; i++) {
|
|
f_activity->value[i] += 10;
|
|
if (f_activity->value[i] > ARC_VALUE_MAX) {
|
|
f_activity->value[i] = ARC_VALUE_MAX;
|
|
f_activity->anim_status = ARC_ANIM_STATUS_BW;
|
|
}
|
|
}
|
|
}break;
|
|
|
|
case ARC_ANIM_STATUS_BW:
|
|
{
|
|
for (i = 0; i < sizeof(f_activity->value) / sizeof(f_activity->value[0]); i++) {
|
|
u16 offset = (ARC_VALUE_MAX - activity_arc_value_goal[i]) / 20;
|
|
if (f_activity->value[i] < activity_arc_value_goal[i]) {
|
|
f_activity->value[i] = activity_arc_value_goal[i];
|
|
f_activity->anim_status = ARC_ANIM_STATUS_END;
|
|
} else {
|
|
f_activity->value[i] -= offset;
|
|
}
|
|
}
|
|
}break;
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < sizeof(activity_arc_info) / sizeof(activity_arc_info[0]); i++) {
|
|
compo_arc_t *arc = compo_getobj_byid(COMPO_ID_ARC_START + i);
|
|
compo_arc_set_value(arc, f_activity->value[i]);
|
|
}
|
|
}
|
|
|
|
//活动记录功能消息处理
|
|
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));
|
|
func_cb.frm_main = func_activity_form_create();
|
|
f_activity_t *f_activity = (f_activity_t *)func_cb.f_cb;
|
|
f_activity->last_steps = 0xffffffff;
|
|
f_activity->last_kcal = 0xffffffff;
|
|
f_activity->last_distance = 0xffffffff;
|
|
f_activity->tick = tick_get();
|
|
}
|
|
|
|
//退出活动记录功能
|
|
static void func_activity_exit(void)
|
|
{
|
|
func_cb.last = FUNC_ACTIVITY;
|
|
}
|
|
|
|
//活动记录功能
|
|
void func_activity(void)
|
|
{
|
|
printf("%s\n", __func__);
|
|
func_activity_enter();
|
|
while (func_cb.sta == FUNC_ACTIVITY) {
|
|
func_activity_process();
|
|
func_activity_message(msg_dequeue());
|
|
}
|
|
func_activity_exit();
|
|
}
|
|
|
|
|
|
#endif
|