mirror of
https://github.com/liquidraver/ZephCore.git
synced 2026-09-01 21:08:19 +00:00
joystick UI:
make UI show actual time source
This commit is contained in:
@@ -430,6 +430,7 @@ target_sources(app PRIVATE
|
||||
adapters/sensors/ZephyrEnvSensors.cpp
|
||||
helpers/AdvertDataHelpers.cpp
|
||||
helpers/oled_power.c
|
||||
helpers/time_sync.c
|
||||
)
|
||||
|
||||
# ========== Radio Driver Selection ==========
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <ZephyrSensorManager.h>
|
||||
#include <adapters/sensors/SimpleLPP.h>
|
||||
#include <adapters/ble/ZephyrBLE.h>
|
||||
#include <adapters/gps/ZephyrGPSManager.h>
|
||||
#include <helpers/time_sync.h>
|
||||
#if IS_ENABLED(CONFIG_ZEPHCORE_UI_DESIGN_BUTTON) || IS_ENABLED(CONFIG_ZEPHCORE_UI_DESIGN_JOYSTICK)
|
||||
#include <ui_task.h>
|
||||
#define ZEPHCORE_HAS_UI_TASK 1
|
||||
@@ -2239,6 +2241,7 @@ bool CompanionMesh::handleProtocolFrame(const uint8_t *data, size_t len)
|
||||
// Arduino: only allow setting time forward (prevents time attacks)
|
||||
if (secs >= curr) {
|
||||
getRTCClock()->setCurrentTime(secs);
|
||||
time_sync_report(TIME_SYNC_APP);
|
||||
sendPacketOk();
|
||||
} else {
|
||||
sendPacketError(ERR_ILLEGAL_ARG);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <adapters/sensors/SimpleLPP.h>
|
||||
#include <adapters/sensors/ZephyrEnvSensors.h>
|
||||
#include <adapters/gps/ZephyrGPSManager.h>
|
||||
#include <helpers/time_sync.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
@@ -53,6 +54,7 @@ static void uplink_time_sync_cb(uint32_t unix_ts)
|
||||
{
|
||||
if (s_uplink_mesh) {
|
||||
s_uplink_mesh->getRTCClock()->setCurrentTime(unix_ts);
|
||||
time_sync_report(TIME_SYNC_WIFI);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/sys/ring_buffer.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <helpers/time_sync.h>
|
||||
|
||||
#define CLI_REPLY_SIZE 256
|
||||
|
||||
@@ -222,6 +222,7 @@ static mesh::ZephyrRTCClock s_rtc_clock;
|
||||
static void time_sync_cb(uint32_t unix_ts)
|
||||
{
|
||||
s_rtc_clock.setCurrentTime(unix_ts);
|
||||
time_sync_report(TIME_SYNC_WIFI);
|
||||
LOG_INF("RTC synced from SNTP: %u", unix_ts);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
#include "CommonCLI.h"
|
||||
#include <helpers/time_sync.h>
|
||||
#include <helpers/TxtDataHelpers.h>
|
||||
#include <helpers/AdvertDataHelpers.h>
|
||||
#include <adapters/board/ZephyrBoard.h>
|
||||
@@ -327,6 +328,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
||||
uint32_t curr = getRTCClock()->getCurrentTime();
|
||||
if (sender_timestamp > curr) {
|
||||
getRTCClock()->setCurrentTime(sender_timestamp + 1);
|
||||
time_sync_report(TIME_SYNC_CLI);
|
||||
uint32_t now = getRTCClock()->getCurrentTime();
|
||||
time_t t = (time_t)now;
|
||||
struct tm *tm = gmtime(&t);
|
||||
@@ -346,6 +348,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
|
||||
uint32_t curr = getRTCClock()->getCurrentTime();
|
||||
if (secs > curr) {
|
||||
getRTCClock()->setCurrentTime(secs);
|
||||
time_sync_report(TIME_SYNC_CLI);
|
||||
time_t t = (time_t)secs;
|
||||
struct tm *tm = gmtime(&t);
|
||||
snprintf(reply, CLI_REPLY_SIZE, "OK - clock set: %02d:%02d - %d/%d/%d UTC",
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "time_sync.h"
|
||||
#include <adapters/gps/ZephyrGPSManager.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static enum time_sync_source s_last = TIME_SYNC_NONE;
|
||||
|
||||
static const char *source_short_name(enum time_sync_source src)
|
||||
{
|
||||
switch (src) {
|
||||
case TIME_SYNC_GPS: return "GPS";
|
||||
case TIME_SYNC_APP: return "App";
|
||||
case TIME_SYNC_WIFI: return "WiFi";
|
||||
case TIME_SYNC_CLI: return "CLI";
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void time_sync_report(enum time_sync_source src)
|
||||
{
|
||||
s_last = src;
|
||||
}
|
||||
|
||||
const char *time_sync_display_label(void)
|
||||
{
|
||||
if (gps_has_time_sync()) {
|
||||
return "GPS";
|
||||
}
|
||||
|
||||
const char *src = source_short_name(s_last);
|
||||
if (!src) {
|
||||
return "None";
|
||||
}
|
||||
|
||||
if (s_last != TIME_SYNC_GPS) {
|
||||
return src;
|
||||
}
|
||||
|
||||
static char label[20];
|
||||
snprintf(label, sizeof(label), "Local (%s)", src);
|
||||
return label;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Track which source last set the RTC for UI display.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum time_sync_source {
|
||||
TIME_SYNC_NONE = 0,
|
||||
TIME_SYNC_GPS,
|
||||
TIME_SYNC_APP,
|
||||
TIME_SYNC_WIFI,
|
||||
TIME_SYNC_CLI,
|
||||
};
|
||||
|
||||
/** Record a successful RTC set from @p src. */
|
||||
void time_sync_report(enum time_sync_source src);
|
||||
|
||||
/** Label for System > Info > Time. GPS authority wins while gps_has_time_sync(). */
|
||||
const char *time_sync_display_label(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "../joystick_ui_task.h"
|
||||
#include "screen_helpers.h"
|
||||
#include <adapters/gps/ZephyrGPSManager.h>
|
||||
#include <helpers/time_sync.h>
|
||||
#include <helpers/ui/ui_mesh_actions.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/random/random.h>
|
||||
@@ -303,7 +304,7 @@ int SystemTimeScreen::render(JoystickDisplay &display)
|
||||
|
||||
const char *labels[4] = { "Time:", "Date:", "TZ:", "Source:" };
|
||||
const char *values[4] = { timeText, dateText, "UTC",
|
||||
_task->getGPSState() ? "GPS" : "App" };
|
||||
time_sync_display_label() };
|
||||
int y = kContentY + 2;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
display.setColor(JoystickDisplay::GREEN);
|
||||
|
||||
@@ -23,6 +23,7 @@ LOG_MODULE_REGISTER(zephcore_main, CONFIG_ZEPHCORE_MAIN_LOG_LEVEL);
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/drivers/hwinfo.h>
|
||||
#include <ZephyrSensorManager.h>
|
||||
#include <helpers/time_sync.h>
|
||||
#include "ui_task.h"
|
||||
#include "ui_mesh_actions.h"
|
||||
#include "oled_power.h"
|
||||
@@ -461,6 +462,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);
|
||||
time_sync_report(TIME_SYNC_GPS);
|
||||
}
|
||||
|
||||
#ifdef ZEPHCORE_LORA
|
||||
|
||||
@@ -41,6 +41,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 <helpers/time_sync.h>
|
||||
#include <ZephyrSensorManager.h>
|
||||
|
||||
/* UI subsystem (display, buttons, buzzer) */
|
||||
@@ -261,6 +262,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);
|
||||
time_sync_report(TIME_SYNC_GPS);
|
||||
}
|
||||
|
||||
int lat_deg = (int)lat;
|
||||
|
||||
Reference in New Issue
Block a user