mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-10-23 07:42:24 +00:00
wire up RTC to out-of-the-box capable nodes
This commit is contained in:
1 parent
9ef6774d6a
commit
01fd56a573
16 files changed
+474
No files matched your search
@@ -21,6 +21,7 @@ LOG_MODULE_REGISTER(zephcore_main, CONFIG_ZEPHCORE_MAIN_LOG_LEVEL);
|
||||
|
||||
#include <ZephyrDataStore.h>
|
||||
#include <adapters/clock/ZephyrRTCClock.h>
|
||||
#include <adapters/clock/ZephyrRTCDiscover.h>
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/drivers/hwinfo.h>
|
||||
#include <zephyr/sys/reboot.h>
|
||||
@@ -754,6 +755,7 @@ static void gps_fix_callback(double lat, double lon, int64_t utc_time)
|
||||
LOG_INF("GPS fix: RTC sync time=%lld", utc_time);
|
||||
rtc_clock.setCurrentTime((uint32_t)utc_time);
|
||||
time_sync_report(TIME_SYNC_GPS);
|
||||
zephcore_rtc_save((uint32_t)utc_time); /* persist to hardware RTC */
|
||||
}
|
||||
|
||||
#ifdef ZEPHCORE_LORA
|
||||
@@ -855,6 +857,16 @@ int main(void)
|
||||
/* Initialize sensor manager (GPS, environment sensors) */
|
||||
sensor_manager_init();
|
||||
|
||||
/* Restore wall-clock time from a battery-backed hardware RTC if one is
|
||||
* present on I2C. Shown tagged "L" (local) until the next GPS/app/CLI
|
||||
* sync; no-op on boards without an RTC. */
|
||||
{
|
||||
uint32_t rtc_epoch;
|
||||
if (zephcore_rtc_restore(&rtc_epoch)) {
|
||||
rtc_clock.setCurrentTime(rtc_epoch);
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize UI subsystem (buttons, buzzer, display).
|
||||
* If display is present, ui_init() handles display init + auto-off.
|
||||
* If no display, fall back to raw OLED sleep for power saving. */
|
||||
|
||||
@@ -51,6 +51,7 @@ extern "C" void bt_ctlr_assert_handle(char *file, uint32_t line)
|
||||
#include <app/RepeaterDataStore.h>
|
||||
#include <app/RepeaterMesh.h>
|
||||
#include <adapters/clock/ZephyrRTCClock.h>
|
||||
#include <adapters/clock/ZephyrRTCDiscover.h>
|
||||
#include <ZephyrSensorManager.h>
|
||||
|
||||
/* UI subsystem (display, buttons, buzzer) */
|
||||
@@ -271,6 +272,7 @@ static void gps_fix_callback(double lat, double lon, int64_t utc_time)
|
||||
if (utc_time > 0) {
|
||||
LOG_INF("GPS fix: RTC sync time=%lld", utc_time);
|
||||
rtc_clock.setCurrentTime((uint32_t)utc_time);
|
||||
zephcore_rtc_save((uint32_t)utc_time); /* persist to hardware RTC */
|
||||
}
|
||||
|
||||
int lat_deg = (int)lat;
|
||||
@@ -431,6 +433,15 @@ int main(void)
|
||||
/* Initialize sensor manager */
|
||||
sensor_manager_init();
|
||||
|
||||
/* Restore wall-clock time from a battery-backed hardware RTC if present
|
||||
* (shown tagged "L" until the next GPS/CLI sync; no-op if no RTC). */
|
||||
{
|
||||
uint32_t rtc_epoch;
|
||||
if (zephcore_rtc_restore(&rtc_epoch)) {
|
||||
rtc_clock.setCurrentTime(rtc_epoch);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set GPS to repeater mode: power off now, wake every 48h for time sync only.
|
||||
* This prevents GPS from draining power on boards that have it (e.g., Wio Tracker). */
|
||||
if (gps_is_available()) {
|
||||
|
||||
@@ -51,6 +51,7 @@ extern "C" void bt_ctlr_assert_handle(char *file, uint32_t line)
|
||||
#include <app/RepeaterDataStore.h>
|
||||
#include <app/RoomServerMesh.h>
|
||||
#include <adapters/clock/ZephyrRTCClock.h>
|
||||
#include <adapters/clock/ZephyrRTCDiscover.h>
|
||||
#include <ZephyrSensorManager.h>
|
||||
|
||||
/* UI subsystem (display, buttons, buzzer) */
|
||||
@@ -284,6 +285,7 @@ static void gps_fix_callback(double lat, double lon, int64_t utc_time)
|
||||
if (utc_time > 0) {
|
||||
LOG_INF("GPS fix: RTC sync time=%lld", utc_time);
|
||||
rtc_clock.setCurrentTime((uint32_t)utc_time);
|
||||
zephcore_rtc_save((uint32_t)utc_time); /* persist to hardware RTC */
|
||||
}
|
||||
|
||||
int lat_deg = (int)lat;
|
||||
@@ -449,6 +451,15 @@ int main(void)
|
||||
/* Initialize sensor manager */
|
||||
sensor_manager_init();
|
||||
|
||||
/* Restore wall-clock time from a battery-backed hardware RTC if present
|
||||
* (shown tagged "L" until the next GPS/CLI sync; no-op if no RTC). */
|
||||
{
|
||||
uint32_t rtc_epoch;
|
||||
if (zephcore_rtc_restore(&rtc_epoch)) {
|
||||
rtc_clock.setCurrentTime(rtc_epoch);
|
||||
}
|
||||
}
|
||||
|
||||
/* Set GPS to repeater mode: power off now, wake every 48h for time sync only.
|
||||
* This prevents GPS from draining power on boards that have it (e.g., Wio Tracker). */
|
||||
if (gps_is_available()) {
|
||||
|
||||
Reference in new issue
Block a user