aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2026-06-10 20:55:46 +0200
committerReiner Herrmann <reiner@reiner-h.de>2026-06-10 20:57:40 +0200
commit4d03f4370b3052949acfe7cc589d82adc427b8fb (patch)
tree9df3898b10830472fff79da98c8717771ded41f1 /src
parent338df4088001869f83de45cf628b4ec43824a499 (diff)
make shown extensions configurable via phone app
Diffstat (limited to 'src')
-rw-r--r--src/c/config.c79
-rw-r--r--src/c/config.h15
-rw-r--r--src/c/event.c6
-rw-r--r--src/c/gw2et.c10
-rw-r--r--src/pkjs/config.json30
-rw-r--r--src/pkjs/index.js3
6 files changed, 139 insertions, 4 deletions
diff --git a/src/c/config.c b/src/c/config.c
new file mode 100644
index 0000000..1d3f3ac
--- /dev/null
+++ b/src/c/config.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2026 Reiner Herrmann
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "event.h"
+
+struct Configuration {
+ uint8_t version;
+ uint32_t enabled_extensions;
+} __attribute__((__packed__));
+
+#define SETTINGS_KEY 1
+#define CONFIG_VERSION 1
+#define NUM_EXTENSIONS 12
+
+static struct Configuration configuration;
+
+extern void reload_data();
+
+static void config_persist() {
+ persist_write_data(SETTINGS_KEY, &configuration, sizeof(configuration));
+
+ /* recalculate events based on updated configuration */
+ init_events();
+ reload_data();
+}
+
+static void config_load_defaults() {
+ configuration.version = CONFIG_VERSION;
+ configuration.enabled_extensions = 0xffffffff;
+}
+
+static void config_load() {
+ config_load_defaults();
+
+ /* buffer remains unchanged if no data is persisted */
+ persist_read_data(SETTINGS_KEY, &configuration, sizeof(configuration));
+
+ if (configuration.version != CONFIG_VERSION) {
+ /* unknown persisted configuration format */
+ config_load_defaults();
+ }
+}
+
+static void config_inbox_received_handler(DictionaryIterator *iter, void *context) {
+ uint32_t old_enabled_extensions = configuration.enabled_extensions;
+
+ for (int i=0; i<NUM_EXTENSIONS; i++) {
+ Tuple *enabled_extension = dict_find(iter, MESSAGE_KEY_enabled_extensions + i);
+ if (enabled_extension) {
+ bool val = enabled_extension->value->uint8;
+ /* clear bit */
+ configuration.enabled_extensions &= ~(1 << i);
+ /* set value into bit */
+ configuration.enabled_extensions |= (val << i);
+ }
+ }
+
+ if (old_enabled_extensions != configuration.enabled_extensions) {
+ /* only persist if something changed */
+ config_persist();
+ }
+}
+
+void config_init() {
+ config_load();
+
+ app_message_register_inbox_received(config_inbox_received_handler);
+ app_message_open(128, 128);
+}
+
+void config_deinit() {
+ app_message_deregister_callbacks();
+}
+
+uint32_t config_get_enabled_extensions() {
+ return configuration.enabled_extensions;
+}
diff --git a/src/c/config.h b/src/c/config.h
new file mode 100644
index 0000000..fcd21fb
--- /dev/null
+++ b/src/c/config.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2026 Reiner Herrmann
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#include <pebble.h>
+
+void config_init();
+void config_deinit();
+uint32_t config_get_enabled_extensions();
+
+#endif
diff --git a/src/c/event.c b/src/c/event.c
index 36b0529..59fdb98 100644
--- a/src/c/event.c
+++ b/src/c/event.c
@@ -4,6 +4,7 @@
*/
#include "event.h"
+#include "config.h"
#define TIME2MIN(hh,mm) (hh * 60 + mm)
@@ -589,9 +590,8 @@ static struct Gw2Event *all_events = NULL;
static int all_events_count = 0;
static int event_index = 0;
-static inline uint16_t enabled_categories() {
- /* TODO: make this mask configurable */
- return 0xffff;
+static inline uint32_t enabled_categories() {
+ return config_get_enabled_extensions();
}
static inline bool is_category_enabled(enum Category category) {
diff --git a/src/c/gw2et.c b/src/c/gw2et.c
index e591868..42e67df 100644
--- a/src/c/gw2et.c
+++ b/src/c/gw2et.c
@@ -4,6 +4,7 @@
*/
#include <pebble.h>
+#include "config.h"
#include "event.h"
#define DEFAULT_NUM_EVENTS 30
@@ -101,12 +102,18 @@ static void main_window_unload(Window *window) {
menu_layer_destroy(main_menu);
}
+void reload_data() {
+ menu_layer_reload_data(main_menu);
+}
+
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
update_event_index();
- menu_layer_reload_data(main_menu);
+ reload_data();
}
static void init() {
+ config_init();
+
main_window = window_create();
window_set_window_handlers(main_window, (WindowHandlers) {
.load = main_window_load,
@@ -119,6 +126,7 @@ static void init() {
}
static void deinit() {
+ config_deinit();
tick_timer_service_unsubscribe();
window_destroy(main_window);
cleanup_events();
diff --git a/src/pkjs/config.json b/src/pkjs/config.json
new file mode 100644
index 0000000..d1f73f7
--- /dev/null
+++ b/src/pkjs/config.json
@@ -0,0 +1,30 @@
+[
+ {
+ "type": "checkboxgroup",
+ "messageKey": "enabled_extensions",
+ "label": "Shown Extensions",
+ "descriptions": "Choose the extensions for which events should be displayed in the watch app",
+ "defaultValue": [
+ true, true, true, true, true, true,
+ true, true, true, true, true, true
+ ],
+ "options": [
+ "Core",
+ "Living World Season 1",
+ "Living World Season 2",
+ "Living World Season 3",
+ "Living World Season 4",
+ "Icebrood Saga",
+ "Heart of Thorns",
+ "Path of Fire",
+ "End of Dragons",
+ "Secrets of the Obscure",
+ "Janthir Wilds",
+ "Visions of Eternity"
+ ]
+ },
+ {
+ "type": "submit",
+ "defaultValue": "Save"
+ }
+]
diff --git a/src/pkjs/index.js b/src/pkjs/index.js
new file mode 100644
index 0000000..3f7cff9
--- /dev/null
+++ b/src/pkjs/index.js
@@ -0,0 +1,3 @@
+var Clay = require('@rebble/clay');
+var clayConfig = require('./config.json');
+var clay = new Clay(clayConfig);