mcu_ab568x/app/projects/AB5681F_240_32M/functions/func_drink.c
2025-05-30 18:03:10 +08:00

157 lines
4.5 KiB
C

#include "include.h"
#include "func.h"
#include "app_variable.h"
#if TRACE_EN
#define TRACE(...) printf(__VA_ARGS__)
#else
#define TRACE(...)
#endif
typedef struct f_sedentary_t_
{
} f_sedentary_t;
// 组件ID
enum
{
COMPO_ID_BIN_DRINK_REMIND_SWITCH = 1,
COMPO_ID_DRINK_SHOW_SET_TIME,
};
// 喝水设置页面
compo_form_t *func_drink_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_DRINK_WATER]);
/* 创建灰色圆角矩形框 */
u16 compo_h = 44 + 33;
compo_shape_t *grey_btn_sit = compo_radius_shape_create(frm, COMPO_SHAPE_TYPE_ROUNDED_RECTANGLE, 16);
compo_shape_set_color(grey_btn_sit, make_color(75, 75, 75));
compo_shape_set_location(grey_btn_sit, GUI_SCREEN_CENTER_X, compo_h, 236, 66);
/* 创建 左边 文本框 */
compo_h = 56;
compo_textbox_t *txt_sit = compo_textbox_create(frm, 50);
compo_textbox_set_align_center(txt_sit, FALSE);
compo_textbox_set_location(txt_sit, 22, compo_h, 140, 30);
compo_textbox_set_autoroll_mode(txt_sit, TEXT_AUTOROLL_MODE_SROLL_CIRC);
compo_textbox_set(txt_sit, i18n[STR_INTERVAL_REMINDER]);
compo_h = 81;
compo_textbox_t *txt_sit_time = compo_textbox_create(frm, 50);
compo_textbox_set_align_center(txt_sit_time, FALSE);
compo_textbox_set_location(txt_sit_time, 22, compo_h, 140, 30);
compo_textbox_set_autoroll_mode(txt_sit_time, TEXT_AUTOROLL_MODE_SROLL_CIRC);
char text_buf[TEXTBOX_TEXT_BUF_LEN] = {0};
sprintf(text_buf, "%d%s", SysVariable.remind.waterInterval, i18n[STR_MIN_SIMPLY]);
compo_textbox_set(txt_sit_time, text_buf);
compo_setid(txt_sit_time, COMPO_ID_DRINK_SHOW_SET_TIME);
/* 创建按钮 */
compo_h = 64 + 14;
compo_button_t *btn_sit;
if (SysVariable.funtionSwitch & FUNTION_REMIND_DRINK_WATER)
btn_sit = compo_button_create_by_image(frm, UI_BUF_COMMON_ON_BIN);
else
btn_sit = compo_button_create_by_image(frm, UI_BUF_COMMON_OFF_BIN);
compo_setid(btn_sit, COMPO_ID_BIN_DRINK_REMIND_SWITCH);
compo_button_set_pos(btn_sit, 195, compo_h);
/* 创建背景 */
//compo_picturebox_t *bg = compo_picturebox_create(frm, UI_BUF_DRINK_DRINK_BIN);
//compo_picturebox_set_pos(bg, GUI_SCREEN_CENTER_X, GUI_SCREEN_CENTER_Y + 60);
return frm;
}
// 开关按钮更新
static void func_drink_restart(void)
{
compo_button_t *btn = NULL;
btn = (compo_button_t *)compo_getobj_byid(COMPO_ID_BIN_DRINK_REMIND_SWITCH);
if (SysVariable.funtionSwitch & FUNTION_REMIND_DRINK_WATER)
compo_button_set_bgimg(btn, UI_BUF_COMMON_ON_BIN);
else
compo_button_set_bgimg(btn, UI_BUF_COMMON_OFF_BIN);
}
// 喝水设置功能事件处理
static void func_drink_process(void)
{
char text_buf[20] = {0};
compo_textbox_t *txt_sit_time = compo_getobj_byid(COMPO_ID_DRINK_SHOW_SET_TIME);
sprintf(text_buf, "%d%s", SysVariable.remind.waterInterval, i18n[STR_MIN_SIMPLY]);
compo_textbox_set(txt_sit_time, text_buf);
func_drink_restart();
func_process();
}
// 单击按钮
static void func_notice_button_click(void)
{
int id = compo_get_button_id();
switch (id)
{
case COMPO_ID_BIN_DRINK_REMIND_SWITCH:
if (SysVariable.funtionSwitch & FUNTION_REMIND_DRINK_WATER)
SysVariable.funtionSwitch &= ~FUNTION_REMIND_DRINK_WATER;
else
SysVariable.funtionSwitch |= FUNTION_REMIND_DRINK_WATER;
ble_function_protocol_packetsend();
break;
default:
break;
}
func_drink_restart();
}
// 喝水设置功能消息处理
static void func_drink_message(size_msg_t msg)
{
switch (msg)
{
case MSG_CTP_CLICK:
func_notice_button_click();
break;
default:
func_message(msg);
break;
}
}
// 进入喝水设置功能
static void func_drink_enter(void)
{
func_cb.f_cb = func_zalloc(sizeof(f_sedentary_t));
func_cb.frm_main = func_drink_form_create();
func_drink_restart();
}
// 退出喝水设置功能
static void func_drink_exit(void)
{
func_cb.last = FUNC_DRINK;
SysVariable.duty_flag = true;
}
// 喝水设置功能
void func_drink(void)
{
func_drink_enter();
while (func_cb.sta == FUNC_DRINK) {
func_drink_process();
func_drink_message(msg_dequeue());
}
func_drink_exit();
}