feat: implement system time synchronization, web server handlers, and clock application components

This commit is contained in:
dark98
2026-09-25 20:57:19 +01:00
parent 4bf31f908a
commit 59b0318579
11 changed files with 442 additions and 33 deletions
+68 -20
View File
@@ -1,11 +1,14 @@
#include "apps.h"
#include "os_gfx.h"
#include "os_status.h"
#include "sys_time.h"
#include <stdio.h>
#include <time.h>
#include "esp_timer.h"
static uint8_t s_view_mode = 0;
static const char *const s_days[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
static const char *const s_months[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
static void clock_init(void)
{
@@ -23,41 +26,86 @@ static void clock_update(uint32_t delta_ms)
sys_gfx_draw_status_bar(&status);
uint32_t sec = status.uptime_sec % 60;
uint32_t min = (status.uptime_sec / 60) % 60;
uint32_t hrs = (status.uptime_sec / 3600);
struct tm tm_info;
bool is_synced = sys_time_get_local(&tm_info);
char time_str[16];
char sub_str[20];
uint32_t sec, min, hrs;
if (is_synced) {
sec = tm_info.tm_sec;
min = tm_info.tm_min;
hrs = tm_info.tm_hour;
} else {
sec = status.uptime_sec % 60;
min = (status.uptime_sec / 60) % 60;
hrs = (status.uptime_sec / 3600);
}
char time_str[32];
char sub_str[48];
if (s_view_mode == 0) {
// Mode 0: Digital Clock (HH:MM:SS) + Date / Status
snprintf(time_str, sizeof(time_str), "%02lu:%02lu:%02lu", (unsigned long)hrs, (unsigned long)min, (unsigned long)sec);
sys_gfx_draw_str_5x7(12, 11, time_str, COLOR_WHITE);
snprintf(sub_str, sizeof(sub_str), "RAM:%luK", (unsigned long)(status.free_heap / 1024));
sys_gfx_draw_str_3x5(4, 21, sub_str, COLOR_WHITE);
snprintf(sub_str, sizeof(sub_str), "CPU:160M");
sys_gfx_draw_str_3x5(40, 21, sub_str, COLOR_WHITE);
if (is_synced) {
int wday = tm_info.tm_wday % 7;
int mon = tm_info.tm_mon % 12;
int mday = tm_info.tm_mday % 100;
int year = (tm_info.tm_year + 1900) % 100;
snprintf(sub_str, sizeof(sub_str), "%s %02d-%s-%02d", s_days[wday], mday, s_months[mon], year);
sys_gfx_draw_str_3x5(9, 21, sub_str, COLOR_WHITE);
} else {
snprintf(sub_str, sizeof(sub_str), "NTP: WAITING...");
sys_gfx_draw_str_3x5(8, 21, sub_str, COLOR_WHITE);
}
sys_gfx_draw_progress_bar(4, 27, 64, 4, (uint8_t)((sec * 100) / 59));
sys_gfx_draw_action_bar("C:MODE", "H:HOME");
} else if (s_view_mode == 1) {
snprintf(time_str, sizeof(time_str), "%02lu:%02lu", (unsigned long)min, (unsigned long)sec);
sys_gfx_draw_str_5x7(18, 14, time_str, COLOR_WHITE);
sys_gfx_draw_str_5x7(19, 14, time_str, COLOR_WHITE);
// Mode 1: Large Minimalist Time (HH:MM) + Seconds + Date
snprintf(time_str, sizeof(time_str), "%02lu:%02lu", (unsigned long)hrs, (unsigned long)min);
sys_gfx_draw_str_5x7(16, 13, time_str, COLOR_WHITE);
sys_gfx_draw_str_5x7(17, 13, time_str, COLOR_WHITE); // Bold effect
snprintf(sub_str, sizeof(sub_str), "UP:%luh %lum", (unsigned long)hrs, (unsigned long)min);
sys_gfx_draw_str_3x5(12, 24, sub_str, COLOR_WHITE);
char sec_str[16];
snprintf(sec_str, sizeof(sec_str), ":%02lu", (unsigned long)sec);
sys_gfx_draw_str_3x5(49, 14, sec_str, COLOR_WHITE);
if (is_synced) {
int wday = tm_info.tm_wday % 7;
int mon = tm_info.tm_mon % 12;
int mday = tm_info.tm_mday % 100;
snprintf(sub_str, sizeof(sub_str), "%s %02d %s", s_days[wday], mday, s_months[mon]);
sys_gfx_draw_str_3x5(14, 23, sub_str, COLOR_WHITE);
} else {
snprintf(sub_str, sizeof(sub_str), "UP:%luh %lum (SYNC..)", (unsigned long)hrs, (unsigned long)min);
sys_gfx_draw_str_3x5(4, 23, sub_str, COLOR_WHITE);
}
sys_gfx_draw_action_bar("C:MODE", "H:HOME");
} else {
snprintf(sub_str, sizeof(sub_str), "UP:%02lu:%02lu:%02lu", (unsigned long)hrs, (unsigned long)min, (unsigned long)sec);
sys_gfx_draw_str_3x5(3, 10, sub_str, COLOR_WHITE);
// Mode 2: Detailed System Clock & Telemetry Diagnostics
if (is_synced) {
snprintf(sub_str, sizeof(sub_str), "TIME:%02lu:%02lu:%02lu", (unsigned long)hrs, (unsigned long)min, (unsigned long)sec);
sys_gfx_draw_str_3x5(3, 10, sub_str, COLOR_WHITE);
snprintf(sub_str, sizeof(sub_str), "HEAP:%lu B", (unsigned long)status.free_heap);
sys_gfx_draw_str_3x5(3, 17, sub_str, COLOR_WHITE);
int year = (tm_info.tm_year + 1900) % 10000;
int mon = (tm_info.tm_mon + 1) % 100;
int mday = tm_info.tm_mday % 100;
snprintf(sub_str, sizeof(sub_str), "DATE:%04d-%02d-%02d", year, mon, mday);
sys_gfx_draw_str_3x5(3, 17, sub_str, COLOR_WHITE);
} else {
snprintf(sub_str, sizeof(sub_str), "NTP: NOT SYNCED");
sys_gfx_draw_str_3x5(3, 10, sub_str, COLOR_WHITE);
snprintf(sub_str, sizeof(sub_str), "MINH:%lu B", (unsigned long)status.min_free_heap);
snprintf(sub_str, sizeof(sub_str), "HEAP:%lu KB", (unsigned long)(status.free_heap / 1024));
sys_gfx_draw_str_3x5(3, 17, sub_str, COLOR_WHITE);
}
uint32_t up_sec = status.uptime_sec % 60;
uint32_t up_min = (status.uptime_sec / 60) % 60;
uint32_t up_hrs = (status.uptime_sec / 3600);
snprintf(sub_str, sizeof(sub_str), "UP: %02lu:%02lu:%02lu", (unsigned long)up_hrs, (unsigned long)up_min, (unsigned long)up_sec);
sys_gfx_draw_str_3x5(3, 24, sub_str, COLOR_WHITE);
sys_gfx_draw_action_bar("C:MODE", "H:HOME");
+3 -1
View File
@@ -1,4 +1,4 @@
#include <stdio.h>
#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@@ -12,6 +12,7 @@
/* OS Subsystems */
#include "os_event.h"
#include "os_status.h"
#include "sys_time.h"
#include "os_gfx.h"
#include "os_input.h"
#include "os_app.h"
@@ -87,6 +88,7 @@ void app_main(void)
// 1. Core Services & Telemetry
sys_event_init();
sys_status_init();
sys_time_init();
esp_err_t err;
// 1b. Wi-Fi and provisioning services