mcu_ab568x/userboot240328/app/projects/AB5681G_320/functions/func_timer.c
2025-05-30 18:03:10 +08:00

182 lines
5.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "include.h"
#include "func.h"
#if TRACE_EN
#define TRACE(...) printf(__VA_ARGS__)
#else
#define TRACE(...)
#endif
//组件ID
enum {
//按键
COMPO_ID_BTN_1MIN = 1,
COMPO_ID_BTN_2MIN = 2,
COMPO_ID_BTN_3MIN = 3,
COMPO_ID_BTN_5MIN = 5,
COMPO_ID_BTN_10MIN = 10,
COMPO_ID_BTN_30MIN = 30,
COMPO_ID_BTN_CUSTOM,
};
typedef struct f_timer_t_ {
} f_timer_t;
typedef struct timer_btn_item_t_ {
u32 res_addr;
u16 btn_id;
s16 x;
s16 y;
bool visible_en;
} timer_btn_item_t;
#define TIMER_BTN_ITEM_CNT ((int)(sizeof(tbl_timer_btn_item) / sizeof(tbl_timer_btn_item[0])))
//搞个按键item创建时遍历一下
static const timer_btn_item_t tbl_timer_btn_item[] = {
{UI_BUF_TIMER_BG_BIN, COMPO_ID_BTN_1MIN, 64, 128, true},
{UI_BUF_TIMER_BG_BIN, COMPO_ID_BTN_2MIN, 160, 128, true},
{UI_BUF_TIMER_BG_BIN, COMPO_ID_BTN_3MIN, 256, 128, true},
{UI_BUF_TIMER_BG_BIN, COMPO_ID_BTN_5MIN, 64, 228, true},
{UI_BUF_TIMER_BG_BIN, COMPO_ID_BTN_10MIN, 160, 228, true},
{UI_BUF_TIMER_BG_BIN, COMPO_ID_BTN_30MIN, 256, 228, true},
{UI_BUF_COMMON_BUTTON_BIN, COMPO_ID_BTN_CUSTOM, 160, 336, true},
};
typedef struct timer_txt_item_t_ {
const char *text;
u16 max_word_cnt;
s16 x;
s16 y;
s16 width;
s16 height;
bool visible_en;
} timer_txt_item_t;
#define TIMER_TXT_ITEM_CNT ((int)(sizeof(tbl_timer_txt_item) / sizeof(tbl_timer_txt_item[0])))
//搞个文本item创建时遍历一下
static const timer_txt_item_t tbl_timer_txt_item[] = {
{"计时器", 3, 30, 22, 110, 40, true},
{"1分", 2, 42, 110, 80, 40, true},
{"2分", 2, 136, 110, 80, 40, true},
{"3分", 2, 231, 110, 80, 40, true},
{"5分", 2, 42, 212, 80, 40, true},
{"10分", 3, 130, 212, 80, 40, true},
{"30分", 3, 224, 212, 80, 40, true},
{"自定义", 3, 120, 320, 110, 40, true},
};
//创建计时器窗体,创建窗体中不要使用功能结构体 func_cb.f_cb
compo_form_t *func_timer_form_create(void)
{
//新建窗体和背景
compo_form_t *frm = compo_form_create(true);
//创建按钮
compo_button_t *btn;
for (u8 idx = 0; idx < TIMER_BTN_ITEM_CNT; idx++) {
btn = compo_button_create_by_image(frm, tbl_timer_btn_item[idx].res_addr);
compo_setid(btn, tbl_timer_btn_item[idx].btn_id);
compo_button_set_pos(btn, tbl_timer_btn_item[idx].x, tbl_timer_btn_item[idx].y);
widget_set_visible(btn->widget, tbl_timer_btn_item[idx].visible_en);
}
//创建文本
compo_textbox_t *txt;
for (u8 idx = 0; idx < TIMER_TXT_ITEM_CNT; idx++) {
txt = compo_textbox_create(frm, tbl_timer_txt_item[idx].max_word_cnt);
compo_textbox_set_location(txt, tbl_timer_txt_item[idx].x, tbl_timer_txt_item[idx].y, tbl_timer_txt_item[idx].width, tbl_timer_txt_item[idx].height);
compo_textbox_set(txt, tbl_timer_txt_item[idx].text);
widget_set_visible(txt->page, tbl_timer_txt_item[idx].visible_en);
}
func_text_time_create(frm); //时间文本框
return frm;
}
//单击按钮
static void func_timer_button_click(void)
{
int id = compo_get_button_id();
switch (id) {
case COMPO_ID_BTN_1MIN:
case COMPO_ID_BTN_2MIN:
case COMPO_ID_BTN_3MIN:
case COMPO_ID_BTN_5MIN:
case COMPO_ID_BTN_10MIN:
case COMPO_ID_BTN_30MIN:
sys_cb.timer_total_sec = id * 60; //分钟
func_cb.sta = FUNC_TIMER_SUB_DISP;
break;
case COMPO_ID_BTN_CUSTOM:
func_cb.sta = FUNC_TIMER_SUB_CUSTOM;
break;
default:
break;
}
}
//计时器功能事件处理
static void func_timer_process(void)
{
func_process();
}
//计时器功能消息处理
static void func_timer_message(size_msg_t msg)
{
switch (msg) {
case MSG_CTP_CLICK:
func_timer_button_click();
break;
case MSG_CTP_SHORT_RIGHT:
func_switching_to_menu(); //右滑缓慢退出任务
break;
case MSG_QDEC_FORWARD:
case MSG_QDEC_REVERSE:
break;
default:
func_message(msg);
break;
}
}
//进入计时器功能
static void func_timer_enter(void)
{
func_cb.f_cb = func_zalloc(sizeof(f_timer_t));
func_cb.frm_main = func_timer_form_create();
}
//退出计时器功能
static void func_timer_exit(void)
{
func_cb.last = FUNC_TIMER;
}
//计时器功能
void func_timer(void)
{
printf("%s\n", __func__);
func_timer_enter();
while (func_cb.sta == FUNC_TIMER) {
func_timer_process();
func_timer_message(msg_dequeue());
}
func_timer_exit();
}