optional RTC 3231 integration
This commit is contained in:
10
src/main.cpp
10
src/main.cpp
@@ -22,6 +22,7 @@ static bool g_ap_mode = false;
|
||||
static WifiMqttConfig g_cfg;
|
||||
static uint32_t g_last_timesync_ms = 0;
|
||||
static constexpr uint32_t TIME_SYNC_OFFSET_MS = 15000;
|
||||
static uint32_t g_boot_ms = 0;
|
||||
|
||||
static constexpr size_t BATCH_HEADER_SIZE = 6;
|
||||
static constexpr size_t BATCH_CHUNK_PAYLOAD = LORA_MAX_PAYLOAD - BATCH_HEADER_SIZE;
|
||||
@@ -244,11 +245,14 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(200);
|
||||
|
||||
g_boot_ms = millis();
|
||||
g_role = detect_role();
|
||||
init_device_ids(g_short_id, g_device_id, sizeof(g_device_id));
|
||||
|
||||
lora_init();
|
||||
display_init();
|
||||
time_rtc_init();
|
||||
time_try_load_from_rtc();
|
||||
display_set_role(g_role);
|
||||
display_set_self_ids(g_short_id, g_device_id);
|
||||
|
||||
@@ -381,7 +385,11 @@ static void receiver_loop() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!g_ap_mode && millis() - g_last_timesync_ms > TIME_SYNC_INTERVAL_SEC * 1000UL) {
|
||||
uint32_t interval_sec = TIME_SYNC_INTERVAL_SEC;
|
||||
if (time_rtc_present() && millis() - g_boot_ms >= TIME_SYNC_FAST_WINDOW_MS) {
|
||||
interval_sec = TIME_SYNC_SLOW_INTERVAL_SEC;
|
||||
}
|
||||
if (!g_ap_mode && millis() - g_last_timesync_ms > interval_sec * 1000UL) {
|
||||
g_last_timesync_ms = millis();
|
||||
time_send_timesync(g_short_id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user