mirror of
https://github.com/skoelle/wt32sc01-dashboard.git
synced 2026-09-17 17:30:25 +00:00
Phase 0: minimal main.cpp (WiFi + display + LVGL test button) + carry over hardware-independent helpers
- src/main.cpp rewritten for ESP32-S3: Serial + display_init + WiFi
connect (logic ported from old main.cpp, M5.Lcd prints -> Serial),
LVGL test button screen to verify touch in Phase 1
- include/text_utils.h, date_utils.h: kept 1:1 (no M5Stack dependency)
- include/secrets.h.example, .gitignore, scripts/{build,deploy}.sh,
.github/workflows/build.yml: kept 1:1 (hardware-independent)
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
// No NTP/network time used, purely computed from date strings coming from
|
||||
// the calendar API itself, as specified.
|
||||
namespace DateUtils {
|
||||
|
||||
inline const char *weekdayShortDE(int isoWeekday /* 0=Mon..6=Sun */) {
|
||||
static const char *names[7] = {"Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"};
|
||||
if (isoWeekday < 0 || isoWeekday > 6) return "??";
|
||||
return names[isoWeekday];
|
||||
}
|
||||
|
||||
// Sakamoto's algorithm, returns 0=Monday..6=Sunday
|
||||
inline int computeWeekdayMonBased(int year, int month, int day) {
|
||||
static const int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
|
||||
int y = year;
|
||||
if (month < 3) y -= 1;
|
||||
int w = (y + y / 4 - y / 100 + y / 400 + t[month - 1] + day) % 7; // 0=Sun
|
||||
return (w + 6) % 7; // convert to 0=Mon
|
||||
}
|
||||
|
||||
struct ParsedDateTime {
|
||||
bool valid = false;
|
||||
int year = 0, month = 0, day = 0, hour = 0, minute = 0;
|
||||
};
|
||||
|
||||
inline ParsedDateTime parseIso(const String &iso) {
|
||||
ParsedDateTime r;
|
||||
if (iso.length() < 10) return r;
|
||||
|
||||
int y = iso.substring(0, 4).toInt();
|
||||
int mo = iso.substring(5, 7).toInt();
|
||||
int d = iso.substring(8, 10).toInt();
|
||||
|
||||
int h = 0, mi = 0;
|
||||
int tIdx = iso.indexOf('T');
|
||||
if (tIdx > 0 && iso.length() >= tIdx + 6) {
|
||||
h = iso.substring(tIdx + 1, tIdx + 3).toInt();
|
||||
mi = iso.substring(tIdx + 4, tIdx + 6).toInt();
|
||||
}
|
||||
|
||||
if (y == 0 || mo == 0 || d == 0) return r;
|
||||
|
||||
r.valid = true;
|
||||
r.year = y; r.month = mo; r.day = d; r.hour = h; r.minute = mi;
|
||||
return r;
|
||||
}
|
||||
|
||||
// "Mo 3.8. 14:00" for timed events, "Mo 3.8." for all-day events.
|
||||
inline String formatShortDE(const String &iso, bool allDay) {
|
||||
ParsedDateTime p = parseIso(iso);
|
||||
if (!p.valid) return iso;
|
||||
|
||||
int wd = computeWeekdayMonBased(p.year, p.month, p.day);
|
||||
String out = String(weekdayShortDE(wd)) + " " + String(p.day) + "." + String(p.month) + ".";
|
||||
|
||||
if (!allDay) {
|
||||
char buf[8];
|
||||
snprintf(buf, sizeof(buf), " %02d:%02d", p.hour, p.minute);
|
||||
out += buf;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace DateUtils
|
||||
Reference in New Issue
Block a user