119 lines
3.4 KiB
C
119 lines
3.4 KiB
C
#include "include.h"
|
|
|
|
#define TRACE_EN 1
|
|
|
|
#if TRACE_EN
|
|
#define TRACE(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define TRACE(...)
|
|
#endif
|
|
|
|
//根据ID获取组件对象
|
|
void *compo_getobj_byid(u16 id)
|
|
{
|
|
if (id == 0) {
|
|
return NULL;
|
|
}
|
|
component_t *compo = compo_get_head();
|
|
while (compo != NULL) {
|
|
if (compo->id == id) {
|
|
return compo;
|
|
}
|
|
compo = compo_get_next(compo); //遍历组件
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
//更新组件时间到TE时间
|
|
ALIGNED(256)
|
|
void compo_time_update(void)
|
|
{
|
|
u32 rtc_cnt, rtc_cnt2, rtc_pr2;
|
|
bool rtc_update;
|
|
|
|
GLOBAL_INT_DISABLE();
|
|
rtc_update = compo_cb.rtc_update;
|
|
rtc_cnt = compo_cb.rtc_cnt;
|
|
rtc_cnt2 = compo_cb.rtc_cnt2 >> 17 << 2;
|
|
rtc_pr2 = (compo_cb.rtc_cnt2 & 0x1FFFF) + 1;
|
|
compo_cb.rtc_update = false;
|
|
GLOBAL_INT_RESTORE();
|
|
|
|
if (!rtc_update) {
|
|
return;
|
|
}
|
|
compo_cb.tm = time_to_tm(rtc_cnt);
|
|
compo_cb.mtime = rtc_cnt2 * 1000 / rtc_pr2;
|
|
compo_settime(compo_cb.tm, compo_cb.mtime);
|
|
}
|
|
|
|
|
|
//更新组件时间
|
|
void compo_settime(tm_t tm, u16 mtime)
|
|
{
|
|
component_t *compo = compo_get_head();
|
|
s16 angle_h, angle_m, angle_s;
|
|
|
|
angle_h = tm.hour * 300 + tm.min * 5 + tm.sec / 12 - 900;
|
|
angle_m = tm.min * 60 + tm.sec - 900;
|
|
//angle_s = tm.sec * 60 + mtime / 100 * 6 - 900; //按100ms对齐
|
|
angle_s = tm.sec * 60 + mtime * 3 / 100 * 2 - 900; //按33ms(0.2度)对齐
|
|
//angle_s = tm.sec * 60 + mtime * 6 / 100 - 900; //按实际ms
|
|
|
|
//printf("%d %d %d\n", angle_h, angle_m, angle_s);
|
|
|
|
while (compo != NULL) {
|
|
if (compo->type == COMPO_TYPE_DATETIME) {
|
|
compo_datetime_t *dtime = (compo_datetime_t *)compo;
|
|
s16 angle = 0;
|
|
switch (dtime->dt_type) {
|
|
case COMPO_DATETIME_TYPE_HOUR:
|
|
angle = angle_h;
|
|
break;
|
|
|
|
case COMPO_DATETIME_TYPE_MINUTE:
|
|
angle = angle_m;
|
|
break;
|
|
|
|
case COMPO_DATETIME_TYPE_SECOND:
|
|
angle = angle_s;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
widget_image_set_rotation(dtime->img, angle);
|
|
} else if (compo->type == COMPO_TYPE_ICONLIST) {
|
|
compo_iconlist_t *iconlist = (compo_iconlist_t *)compo;
|
|
if (iconlist->hour != NULL) {
|
|
widget_image_set_rotation(iconlist->hour, angle_h);
|
|
}
|
|
if (iconlist->min != NULL) {
|
|
widget_image_set_rotation(iconlist->min, angle_m);
|
|
}
|
|
if (iconlist->sec != NULL) {
|
|
widget_image_set_rotation(iconlist->sec, angle_s);
|
|
}
|
|
}
|
|
compo = compo_get_next(compo); //遍历组件
|
|
}
|
|
}
|
|
|
|
//获取按键ID
|
|
int compo_get_button_id(void)
|
|
{
|
|
point_t pt = ctp_get_sxy();
|
|
component_t *compo = compo_get_head();
|
|
while (compo != NULL) {
|
|
if (compo->type == COMPO_TYPE_BUTTON) {
|
|
compo_button_t *btn = (compo_button_t *)compo;
|
|
rect_t rect = widget_get_absolute(btn->widget);
|
|
if (abs_s(pt.x - rect.x) * 2 <= rect.wid && abs_s(pt.y - rect.y) * 2 <= rect.hei) {
|
|
return btn->id;
|
|
}
|
|
}
|
|
compo = compo_get_next(compo); //遍历组件
|
|
}
|
|
return ID_NULL;
|
|
}
|