Fix GPS modem selection and add a GPS-only time source
This commit is contained in:
1 parent
eaf08abcd4
commit
a50c01b416
18 files changed
+682
-16
No files matched your search
@@ -1213,6 +1213,10 @@ clear_all_notifications_now(void)
|
||||
"sxmo_hook_statusbar.sh notifications >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
/* Defined with the Config-menu helpers below; used by the time source toggle. */
|
||||
static void time_source_path(char *path, size_t len);
|
||||
static const char *read_time_source(void);
|
||||
|
||||
static void
|
||||
handle_builtin_toggle(const char *toggle_name)
|
||||
{
|
||||
@@ -1322,6 +1326,25 @@ handle_builtin_toggle(const char *toggle_name)
|
||||
} else if (strcmp(toggle_name, "ext_logging") == 0) {
|
||||
int rc = system("doas -n /usr/bin/bananarchy-engmenu-ctl logging toggle >/dev/null 2>&1 || /usr/bin/bananarchy-engmenu-ctl logging toggle >/dev/null 2>&1");
|
||||
(void)rc;
|
||||
} else if (strcmp(toggle_name, "time_source") == 0) {
|
||||
/* Config -> Time source: switch between NTP and GPS-only datetime sync. */
|
||||
char path[256], dir[256], value[16];
|
||||
const char *home = getenv("HOME");
|
||||
const char *next = strcmp(read_time_source(), "gps") == 0 ? "network" : "gps";
|
||||
if (!home || !home[0])
|
||||
home = "/home/user";
|
||||
snprintf(dir, sizeof(dir), "%s/.config/sxmo", home);
|
||||
mkdir(dir, 0755);
|
||||
time_source_path(path, sizeof(path));
|
||||
snprintf(value, sizeof(value), "%s\n", next);
|
||||
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
if (fd >= 0) {
|
||||
(void)!write(fd, value, strlen(value));
|
||||
close(fd);
|
||||
spawn_detached_sh(
|
||||
"doas -n /usr/bin/bananarchy-gps-time-sync.sh apply >/dev/null 2>&1 || "
|
||||
"/usr/bin/bananarchy-gps-time-sync.sh apply >/dev/null 2>&1 || true");
|
||||
}
|
||||
} else if (strcmp(toggle_name, "notif_clear_all") == 0) {
|
||||
clear_all_notifications_now();
|
||||
}
|
||||
@@ -2516,6 +2539,26 @@ idle_blank_label(int secs)
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Config-menu time source (NTP network vs GNSS only) helpers. */
|
||||
static void
|
||||
time_source_path(char *path, size_t len)
|
||||
{
|
||||
const char *home = getenv("HOME");
|
||||
if (!home || !home[0])
|
||||
home = "/home/user";
|
||||
snprintf(path, len, "%s/.config/sxmo/time_source", home);
|
||||
}
|
||||
|
||||
static const char *
|
||||
read_time_source(void)
|
||||
{
|
||||
char path[256], buf[32] = "";
|
||||
time_source_path(path, sizeof(path));
|
||||
if (read_first_line(path, buf, sizeof(buf)) && strcmp(buf, "gps") == 0)
|
||||
return "gps";
|
||||
return "network";
|
||||
}
|
||||
|
||||
static void
|
||||
populate_timezone_menu(void)
|
||||
{
|
||||
@@ -2982,6 +3025,13 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
snprintf(label, sizeof(label), "%s Sync net time", ICON_CLK);
|
||||
add_menu_item(label, "/usr/bin/bananarchy-sync-net-time.sh", 0);
|
||||
|
||||
/* Time source: NTP or GNSS only; Sync GPS time works in either mode. */
|
||||
snprintf(label, sizeof(label), "%s Time source: %s", ICON_CLK,
|
||||
strcmp(read_time_source(), "gps") == 0 ? "GPS only" : "Network (NTP)");
|
||||
add_menu_item(label, "@toggle:time_source", 1);
|
||||
snprintf(label, sizeof(label), "%s Sync GPS time", ICON_CLK);
|
||||
add_menu_item(label, "/usr/bin/bananarchy-sync-gps-time.sh", 0);
|
||||
|
||||
snprintf(label, sizeof(label), "%s Screen blank: %s", ICON_CLK,
|
||||
idle_blank_label(read_idle_blank_secs()));
|
||||
add_menu_item(label, "@menu:idle_blank", 1);
|
||||
|
||||
Reference in new issue
Block a user