336 lines
10 KiB
C
336 lines
10 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 FUNC_HR_SIMULATE_DATA_EN 0
|
|
//组件ID;
|
|
enum {
|
|
COMPO_ID_NUM_HEARTRATE_MAX = 1,
|
|
COMPO_ID_NUM_HEARTRATE_CUR,
|
|
COMPO_ID_NUM_HEARTRATE_MIN,
|
|
COMPO_ID_TEXT_HEARTRATE_TIME,
|
|
COMPO_ID_PIC_BT_LEF,
|
|
COMPO_ID_PIC_BT_CEN,
|
|
COMPO_ID_PIC_BT_RIG,
|
|
COMPO_ID_CHART,
|
|
};
|
|
|
|
enum
|
|
{
|
|
CHART_ANIM_STA_IDLE,
|
|
CHART_ANIM_STA_START,
|
|
CHART_ANIM_STA_END,
|
|
};
|
|
|
|
#define HEARTRATE_TEXT_ITEM_CNT 2
|
|
|
|
typedef struct f_heartrate_t_ {
|
|
page_tp_move_t *ptm;
|
|
u32 tick;
|
|
s16 lef_x;
|
|
s16 cen_x;
|
|
s16 rig_x;
|
|
u8 sec;
|
|
} f_heartrate_t;
|
|
|
|
#if FUNC_HR_SIMULATE_DATA_EN
|
|
static const uint16_t total_hr_value[] = {10,20,30,40,50,60,70};
|
|
#endif
|
|
|
|
|
|
//创建心率窗体,创建窗体中不要使用功能结构体 func_cb.f_cb
|
|
compo_form_t *func_heartrate_form_create(void)
|
|
{
|
|
//新建窗体
|
|
u8 idx = 0;
|
|
component_t *compo;
|
|
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_HEART_RATE]);
|
|
|
|
//设置内容
|
|
compo_form_add_image(frm, UI_BUF_HEART_RATE_ICON_HR_BIN, 10+13, 27+13);
|
|
compo_form_add_image(frm, UI_BUF_HEART_RATE_HR_BG_BIN, GUI_SCREEN_CENTER_X, 70+25);
|
|
|
|
compo_form_add_image(frm, UI_BUF_HEART_RATE_UP_BIN, 12 + 4, 138+ 4);
|
|
compo_form_add_image(frm, UI_BUF_HEART_RATE_DOWN_BIN, 81 + 4, 138+ 4);
|
|
|
|
//创建文本
|
|
compo_textbox_t *txt_title = compo_textbox_create(frm, 6);
|
|
#if defined(__LANGUAGE_SM_CHINESE__)
|
|
if(tjd_Get_Language_Current_Index() == LANGUAGE_TYPE_Chinese)
|
|
{
|
|
compo_textbox_set_pos(txt_title, 82+25, 40);
|
|
compo_textbox_set(txt_title, "次/分");
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
compo_textbox_set_pos(txt_title, 82+18, 40);
|
|
compo_textbox_set(txt_title, "BPM");
|
|
}
|
|
|
|
|
|
//测量心率值
|
|
compo_textbox_t *txt_val = compo_textbox_create(frm, 3);
|
|
compo_textbox_set_font(txt_val, UI_BUF_0FONT_FONT_DIN_PRO_NUM_20_BIN);
|
|
compo_setid(txt_val, COMPO_ID_NUM_HEARTRATE_CUR);
|
|
// compo_textbox_set_align_center(txt_val, false);
|
|
compo_textbox_set_pos(txt_val, 43+18, 40);
|
|
compo_textbox_set(txt_val, "---");
|
|
|
|
//心率值最大值
|
|
txt_val = compo_textbox_create(frm, 3);
|
|
compo_textbox_set_font(txt_val, UI_BUF_0FONT_FONT_BIN);
|
|
compo_setid(txt_val, COMPO_ID_NUM_HEARTRATE_MAX);
|
|
// compo_textbox_set_align_center(txt_val, false);
|
|
compo_textbox_set_pos(txt_val, 24+9, 139);
|
|
compo_textbox_set(txt_val, "---");
|
|
|
|
//心率值最小值
|
|
txt_val = compo_textbox_create(frm, 3);
|
|
compo_textbox_set_font(txt_val, UI_BUF_0FONT_FONT_BIN);
|
|
compo_setid(txt_val, COMPO_ID_NUM_HEARTRATE_MIN);
|
|
// compo_textbox_set_align_center(txt_val, false);
|
|
compo_textbox_set_pos(txt_val, 92+9, 139);
|
|
compo_textbox_set(txt_val, "---");
|
|
|
|
|
|
|
|
//创建动画
|
|
// compo_picturebox_t *animation = compo_picturebox_create(frm, UI_BUF_COMMON_HR_DT_BIN);
|
|
// compo_animation_set_pos(animation, GUI_SCREEN_CENTER_X, 70 + 25 );
|
|
// compo_setid(animation, COMPO_ID_PIC_BT_LEF);
|
|
|
|
|
|
compo_picturebox_t *pic_lef = compo_picturebox_create(frm, UI_BUF_COMMON_HR_DT_1_BIN);
|
|
compo_setid(pic_lef, COMPO_ID_PIC_BT_LEF);
|
|
compo_picturebox_set_pos(pic_lef, GUI_SCREEN_WIDTH/4, 70+25);
|
|
compo_picturebox_set_visible(pic_lef, false); //触摸按下的效果图先设置不可见
|
|
|
|
compo_picturebox_t *pic_cen = compo_picturebox_create(frm, UI_BUF_COMMON_HR_DT_1_BIN);
|
|
compo_setid(pic_cen, COMPO_ID_PIC_BT_CEN);
|
|
compo_picturebox_set_pos(pic_cen, GUI_SCREEN_WIDTH/4 * 3, 70+25);
|
|
compo_picturebox_set_visible(pic_cen, false); //触摸按下的效果图先设置不可见
|
|
|
|
compo_picturebox_t *pic_rig = compo_picturebox_create(frm, UI_BUF_COMMON_HR_DT_1_BIN);
|
|
compo_setid(pic_rig, COMPO_ID_PIC_BT_RIG);
|
|
compo_picturebox_set_pos(pic_rig, GUI_SCREEN_WIDTH/4 * 5, 70+25);
|
|
compo_picturebox_set_visible(pic_rig, false); //触摸按下的效果图先设置不可见
|
|
|
|
|
|
// //心率详情
|
|
// compo_form_add_image(frm, UI_BUF_HEART_RATE_CHART_BG_BIN, 160, 580);
|
|
|
|
// //创建图表
|
|
// compo = (component_t *)compo_chartbox_create(frm, CHART_TYPE_BAR, 7);
|
|
// compo_chartbox_set_location((compo_chartbox_t *)compo, 180, 572, 230, 150);
|
|
// compo_chartbox_set_pixel((compo_chartbox_t *)compo, 2);
|
|
// compo_setid((compo_chartbox_t *)compo, COMPO_ID_CHART);
|
|
|
|
return frm;
|
|
}
|
|
|
|
// 刷新心率
|
|
static void func_heartrate_refresh(void)
|
|
{
|
|
compo_textbox_t *txt = NULL;
|
|
f_heartrate_t *f_heartrate = (f_heartrate_t *)func_cb.f_cb;
|
|
|
|
static char hr_buf[4];
|
|
memset(hr_buf, 0, sizeof(hr_buf));
|
|
|
|
if (SysVariable.heartRateModule.openStatus == true) {
|
|
reset_sleep_delay_all();
|
|
}
|
|
|
|
//实时测量心率
|
|
|
|
if (SysVariable.heartRateModule.heart > 0) {
|
|
txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_NUM_HEARTRATE_CUR);
|
|
snprintf(hr_buf, sizeof(hr_buf), "%d", SysVariable.heartRateModule.heart);
|
|
compo_textbox_set(txt, hr_buf);
|
|
}
|
|
|
|
if (SysVariable.heartRateModule.maxHeart)
|
|
{
|
|
txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_NUM_HEARTRATE_MAX);
|
|
snprintf(hr_buf, sizeof(hr_buf), "%d", SysVariable.heartRateModule.maxHeart);
|
|
compo_textbox_set(txt, hr_buf);
|
|
}
|
|
|
|
if (SysVariable.heartRateModule.minHeart)
|
|
{
|
|
txt = (compo_textbox_t *)compo_getobj_byid(COMPO_ID_NUM_HEARTRATE_MIN);
|
|
snprintf(hr_buf, sizeof(hr_buf), "%d", SysVariable.heartRateModule.minHeart);
|
|
compo_textbox_set(txt, hr_buf);
|
|
}
|
|
}
|
|
|
|
//动画滚动
|
|
static void func_animation_roll(void)
|
|
{
|
|
f_heartrate_t *f_heartrate = (f_heartrate_t *)func_cb.f_cb;
|
|
compo_picturebox_t *pic_lef = compo_getobj_byid(COMPO_ID_PIC_BT_LEF);
|
|
compo_picturebox_t *pic_cen = compo_getobj_byid(COMPO_ID_PIC_BT_CEN);
|
|
compo_picturebox_t *pic_rig = compo_getobj_byid(COMPO_ID_PIC_BT_RIG);
|
|
|
|
if (SysVariable.heartRateModule.heart > 0){
|
|
if ((SysVariable.heartRateModule.timeOutFlag == true) || (SysVariable.heartRateModule.measureEndFlag == true))
|
|
{
|
|
|
|
}
|
|
else{
|
|
if (tick_check_expire(f_heartrate->tick, 100)){
|
|
f_heartrate->tick = tick_get();
|
|
|
|
f_heartrate->lef_x -= 2;
|
|
f_heartrate->cen_x -= 2;
|
|
f_heartrate->rig_x -= 2;
|
|
|
|
|
|
if(f_heartrate->lef_x < (-GUI_SCREEN_WIDTH/4))
|
|
f_heartrate->lef_x = GUI_SCREEN_WIDTH/4*5;
|
|
|
|
if(f_heartrate->cen_x < (-GUI_SCREEN_WIDTH/4))
|
|
f_heartrate->cen_x = GUI_SCREEN_WIDTH/4*5;
|
|
|
|
if(f_heartrate->rig_x < (-GUI_SCREEN_WIDTH/4))
|
|
f_heartrate->rig_x = GUI_SCREEN_WIDTH/4*5;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
compo_picturebox_set_pos(pic_lef, f_heartrate->lef_x, 70 + 25);
|
|
compo_picturebox_set_visible(pic_lef, true); //触摸按下的效果图先设置不可见
|
|
|
|
compo_picturebox_set_pos(pic_cen, f_heartrate->cen_x, 70 + 25);
|
|
compo_picturebox_set_visible(pic_cen, true); //触摸按下的效果图先设置不可见
|
|
|
|
compo_picturebox_set_pos(pic_rig, f_heartrate->rig_x, 70 + 25);
|
|
compo_picturebox_set_visible(pic_rig, true); //触摸按下的效果图先设置不可见
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//心率功能事件处理
|
|
static void func_heartrate_process(void)
|
|
{
|
|
f_heartrate_t *f_heartrate = (f_heartrate_t *)func_cb.f_cb;
|
|
compo_page_move_process(f_heartrate->ptm);
|
|
|
|
#ifdef TJD_GUI_Remind_slip_wrist_Show
|
|
//脱腕检测
|
|
if (tick_check_expire(f_heartrate->tick, 100)){
|
|
f_heartrate->tick = tick_get();
|
|
if(++f_heartrate->sec > 30)
|
|
{
|
|
if(SysVariable.heartRateModule.is_farway_hand == true){
|
|
func_switch_to_assign_screen(FUNC_FARWAY_HAND, false);
|
|
func_cb.last = FUNC_HEARTRATE;
|
|
// func_switch_to(FUNC_FARWAY_HAND, FUNC_SWITCH_LR_ZOOM_RIGHT); //右滑界面
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
func_heartrate_refresh();
|
|
func_animation_roll();
|
|
func_process();
|
|
}
|
|
|
|
//心率功能消息处理
|
|
static void func_heartrate_message(size_msg_t msg)
|
|
{
|
|
f_heartrate_t *f_heartrate = (f_heartrate_t *)func_cb.f_cb;
|
|
|
|
switch (msg) {
|
|
case MSG_CTP_TOUCH:
|
|
compo_page_move_touch_handler(f_heartrate->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_heartrate->ptm, -1);
|
|
}
|
|
break;
|
|
|
|
case MSG_QDEC_FORWARD:
|
|
if (func_cb.flag_sort) {
|
|
func_message(msg);
|
|
} else {
|
|
// compo_page_move_set_by_pages(f_heartrate->ptm, 1);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
func_message(msg);
|
|
break;
|
|
}
|
|
}
|
|
|
|
//进入心率功能
|
|
static void func_heartrate_enter(void)
|
|
{
|
|
func_cb.f_cb = func_zalloc(sizeof(f_heartrate_t));
|
|
func_cb.frm_main = func_heartrate_form_create();
|
|
|
|
f_heartrate_t *f_heartrate = (f_heartrate_t *)func_cb.f_cb;
|
|
f_heartrate->ptm = (page_tp_move_t *)func_zalloc(sizeof(page_tp_move_t));
|
|
f_heartrate->lef_x = GUI_SCREEN_WIDTH/4 ;
|
|
f_heartrate->cen_x = GUI_SCREEN_WIDTH/4*3 ;
|
|
f_heartrate->rig_x = GUI_SCREEN_WIDTH/4*5 ;
|
|
// page_move_info_t info = {
|
|
// .title_used = true,
|
|
// .page_size = GUI_SCREEN_HEIGHT - (GUI_SCREEN_HEIGHT / 8),
|
|
// .page_count = 2,
|
|
// .jump_perc = 20,
|
|
// .quick_jump_perc = 100,
|
|
// .up_over_perc = 10,
|
|
// .down_over_perc = 10,
|
|
// };
|
|
// compo_page_move_init(f_heartrate->ptm, func_cb.frm_main->page_body, &info);
|
|
bsp_sensor_hr_start(MeasureMode_Heart);
|
|
}
|
|
|
|
//退出心率功能
|
|
static void func_heartrate_exit(void)
|
|
{
|
|
f_heartrate_t *f_heartrate = (f_heartrate_t *)func_cb.f_cb;
|
|
if (f_heartrate->ptm) {
|
|
func_free(f_heartrate->ptm);
|
|
}
|
|
bsp_sensor_hr_stop();
|
|
}
|
|
|
|
//心率功能
|
|
void func_heartrate(void)
|
|
{
|
|
printf("%s\n", __func__);
|
|
func_heartrate_enter();
|
|
while (func_cb.sta == FUNC_HEARTRATE) {
|
|
func_heartrate_process();
|
|
func_heartrate_message(msg_dequeue());
|
|
}
|
|
func_heartrate_exit();
|
|
}
|