重构手环软件架构:实现动态挂载前后台 App 框架,解耦拆分源文件,并引入统一日志宏 xtell.h
This commit is contained in:
37
App/clock.c
Normal file
37
App/clock.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "clock.h"
|
||||
#include "xtell.h"
|
||||
|
||||
// 软时钟基础计时变量
|
||||
u8 current_hour = 10; // 系统软时钟:小时 (默认初始化为 10 点)
|
||||
u8 current_min = 35; // 系统软时钟:分钟 (默认初始化为 35 分)
|
||||
u8 current_sec = 0; // 系统软时钟:秒
|
||||
volatile u8 clock_updated = 0; // 分钟跳变标志位,置位后用于驱动 UI 刷新时间显示
|
||||
|
||||
// 毫秒计数器 (Timer1 每 1ms 累加)
|
||||
static u16 ms_cnt = 0;
|
||||
|
||||
/**
|
||||
* @brief 系统软时钟毫秒递增更新 (在 1ms 中断中调用)
|
||||
* @details 负责由定时器 1ms 驱动递增软时钟,并在分钟发生跳变时将 clock_updated 置位
|
||||
*/
|
||||
void Clock_IncMS(void)
|
||||
{
|
||||
ms_cnt++;
|
||||
if (ms_cnt >= 1000) {
|
||||
ms_cnt = 0; // 1秒时间到
|
||||
current_sec++;
|
||||
if (current_sec >= 60) {
|
||||
current_sec = 0; // 1分钟时间到
|
||||
current_min++;
|
||||
if (current_min >= 60) {
|
||||
current_min = 0; // 1小时时间到
|
||||
current_hour++;
|
||||
if (current_hour >= 24) {
|
||||
current_hour = 0; // 小时循环
|
||||
}
|
||||
}
|
||||
clock_updated = 1; // 分钟跳变,标志位置位,前台待机 App 会捕获以刷新 UI
|
||||
XTELL_LOG("[CLOCK] Time updated!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user