feat(ui): extend set_clock_app to edit day/month/year, not just time

time_edit_field now cycles through 5 fields (hour/min/day/month/year)
via long-press CONFIRM. Up/down adjusts whichever field is focused,
with day clamped to Days_In_Month() when month/year changes, and
Clock_RecalcWeekday() called after every date edit so the weekday
label stays in sync. UI_UpdateSetTimeDigit() now also refreshes the
weekday abbreviation when editing day/month/year, since the computed
weekday can change independently of which digit was actually touched.
Save writes the full date+weekday via PCF8563_WriteDateTime(). Also
removes PCF8563_ReadTime()/WriteTime(), now unused since every caller
was updated to the DateTime variants directly.
This commit is contained in:
edisondeng
2026-07-31 19:53:56 +08:00
parent 6baf93c550
commit 6022f0a409
5 changed files with 73 additions and 88 deletions

View File

@@ -12,7 +12,7 @@ extern SystemState current_state;
extern volatile u16 ms_tick;
// 本应用私有的时间编辑状态
static u8 time_edit_field = 1; // 标识当前聚焦在哪一个参数上进行微调 (1:修改小时, 2:修改分钟)
static u8 time_edit_field = 1; // 当前聚焦调节的字段 (1:小时, 2:分钟, 3:日, 4:月, 5:年)
static u8 time_edit_blink_on = 1; // 时钟修改时光标闪烁周期状态位
// 声明本应用的生命周期回调函数
@@ -49,7 +49,7 @@ static void SetClockApp_OnStart(void)
MOTOR = 0;
// 渲染显示时间编辑界面,默认高亮编辑小时字段,消隐位开启
UI_ShowSetTimePage(current_hour, current_min, time_edit_field, 1);
UI_ShowSetTimePage(current_hour, current_min, current_day, current_month, current_year, current_weekday, time_edit_field, 1);
XTELL_LOG("[SetClockApp] Started\r\n");
}
@@ -63,8 +63,8 @@ static void SetClockApp_onRun(void)
if (blink != time_edit_blink_on)
{
time_edit_blink_on = blink;
// 每次闪烁状态发生变化,只局部刷新正在调节的那个字,不整屏重绘
UI_UpdateSetTimeDigit(current_hour, current_min, time_edit_field, time_edit_blink_on);
// 每次闪烁状态发生变化,只局部刷新正在调节的那个字,不整屏重绘
UI_UpdateSetTimeDigit(current_hour, current_min, current_day, current_month, current_year, current_weekday, time_edit_field, time_edit_blink_on);
}
}
@@ -84,49 +84,83 @@ static EventResult SetClockApp_onEvent(SystemEvent *evt)
{
if (evt->key_event == KEY_EVENT_UP_CLICK)
{
// 短按 ▲ 键增加数值 (小时/分钟循环相加)
if (time_edit_field == 1) {
current_hour = (current_hour + 1) % 24;
} else {
current_min = (current_min + 1) % 60;
// 短按 ▲ 键增加当前聚焦字段的数值 (各字段独立循环)
switch (time_edit_field) {
case 1: current_hour = (current_hour + 1) % 24; break;
case 2: current_min = (current_min + 1) % 60; break;
case 3:
current_day = (current_day >= Days_In_Month(current_year, current_month)) ? 1 : (current_day + 1);
Clock_RecalcWeekday();
break;
case 4:
current_month = (current_month >= 12) ? 1 : (current_month + 1);
// 月份变化后,若当前日超出新月份的最大天数,截断到最大天数
if (current_day > Days_In_Month(current_year, current_month)) {
current_day = Days_In_Month(current_year, current_month);
}
Clock_RecalcWeekday();
break;
default: // 5: 年
current_year = (current_year >= 99) ? 0 : (current_year + 1);
if (current_day > Days_In_Month(current_year, current_month)) {
current_day = Days_In_Month(current_year, current_month);
}
Clock_RecalcWeekday();
break;
}
time_edit_blink_on = 1; // 调值后强制显示 (不处于消隐周期)
UI_UpdateSetTimeDigit(current_hour, current_min, time_edit_field, 1);
UI_UpdateSetTimeDigit(current_hour, current_min, current_day, current_month, current_year, current_weekday, time_edit_field, 1);
return EVENT_HANDLED;
}
if (evt->key_event == KEY_EVENT_DOWN_CLICK)
{
// 短按 ▼ 键减小数值
if (time_edit_field == 1) {
current_hour = (current_hour == 0) ? 23 : (current_hour - 1);
} else {
current_min = (current_min == 0) ? 59 : (current_min - 1);
// 短按 ▼ 键减小当前聚焦字段的数值 (各字段独立循环)
switch (time_edit_field) {
case 1: current_hour = (current_hour == 0) ? 23 : (current_hour - 1); break;
case 2: current_min = (current_min == 0) ? 59 : (current_min - 1); break;
case 3:
current_day = (current_day <= 1) ? Days_In_Month(current_year, current_month) : (current_day - 1);
Clock_RecalcWeekday();
break;
case 4:
current_month = (current_month <= 1) ? 12 : (current_month - 1);
if (current_day > Days_In_Month(current_year, current_month)) {
current_day = Days_In_Month(current_year, current_month);
}
Clock_RecalcWeekday();
break;
default: // 5: 年
current_year = (current_year == 0) ? 99 : (current_year - 1);
if (current_day > Days_In_Month(current_year, current_month)) {
current_day = Days_In_Month(current_year, current_month);
}
Clock_RecalcWeekday();
break;
}
time_edit_blink_on = 1; // 调值后强制显示 (不处于消隐周期)
UI_UpdateSetTimeDigit(current_hour, current_min, time_edit_field, 1);
UI_UpdateSetTimeDigit(current_hour, current_min, current_day, current_month, current_year, current_weekday, time_edit_field, 1);
return EVENT_HANDLED;
}
if (evt->key_event == KEY_EVENT_CONFIRM_LONG)
{
// 长按 ■ 确认键切换调节字段 (在修改小时与修改分钟间跳转)
if (time_edit_field == 1) {
time_edit_field = 2;
} else {
time_edit_field = 1;
}
time_edit_blink_on = 1; // 切换焦点后两个字段都应处于可见状态
// 两个数字区域都局部刷新一次,避免切换前正处于消隐周期的那个数字停留在涂黑状态
UI_UpdateSetTimeDigit(current_hour, current_min, 1, 1);
UI_UpdateSetTimeDigit(current_hour, current_min, 2, 1);
// 长按 ■ 确认键切换调节字段 (小时 -> 分钟 -> 日 -> 月 -> 年 -> 循环回小时)
time_edit_field = (time_edit_field >= 5) ? 1 : (time_edit_field + 1);
time_edit_blink_on = 1; // 切换焦点后所有字段都应处于可见状态
// 全部字段各局部刷新一次,避免切换前正处于消隐周期的那个字段停留在涂黑状态
UI_UpdateSetTimeDigit(current_hour, current_min, current_day, current_month, current_year, current_weekday, 1, 1);
UI_UpdateSetTimeDigit(current_hour, current_min, current_day, current_month, current_year, current_weekday, 2, 1);
UI_UpdateSetTimeDigit(current_hour, current_min, current_day, current_month, current_year, current_weekday, 3, 1);
UI_UpdateSetTimeDigit(current_hour, current_min, current_day, current_month, current_year, current_weekday, 4, 1);
UI_UpdateSetTimeDigit(current_hour, current_min, current_day, current_month, current_year, current_weekday, 5, 1);
return EVENT_HANDLED;
}
if (evt->key_event == KEY_EVENT_CONFIRM_CLICK)
{
// 短按 ■ 确认键保存最新时配置,退出到主菜单 (父 App)
// 短按 ■ 确认键保存最新时间与日期配置,退出到主菜单 (父 App)
current_state = STATE_PAIR_MENU;
// 同步将最新时间 (hour, min, 0秒) 写入 PCF8563 芯片寄存器
PCF8563_WriteTime(current_hour, current_min, 0);
// 同步将最新时间与日期 (含算好的星期) 一次性写入 PCF8563 芯片寄存器
PCF8563_WriteDateTime(current_hour, current_min, 0, current_day, current_month, current_year, current_weekday);
// 退出短振反馈
MOTOR = 1; Delay_ms(50); MOTOR = 0;