diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2026-06-10 20:55:46 +0200 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2026-06-10 20:57:40 +0200 |
| commit | 4d03f4370b3052949acfe7cc589d82adc427b8fb (patch) | |
| tree | 9df3898b10830472fff79da98c8717771ded41f1 | |
| parent | 338df4088001869f83de45cf628b4ec43824a499 (diff) | |
make shown extensions configurable via phone app
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | package.json | 17 | ||||
| -rw-r--r-- | src/c/config.c | 79 | ||||
| -rw-r--r-- | src/c/config.h | 15 | ||||
| -rw-r--r-- | src/c/event.c | 6 | ||||
| -rw-r--r-- | src/c/gw2et.c | 10 | ||||
| -rw-r--r-- | src/pkjs/config.json | 30 | ||||
| -rw-r--r-- | src/pkjs/index.js | 3 |
8 files changed, 153 insertions, 9 deletions
@@ -1,2 +1,4 @@ build/ +node_modules/ .lock-waf_linux_build +package-lock.json diff --git a/package.json b/package.json index 240124d..8263cbf 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,22 @@ { "name": "gw2et", "author": "Reiner Herrmann", - "version": "0.2.0", - "keywords": ["pebble-app"], + "version": "0.3.0", + "keywords": [ + "pebble-app" + ], "private": true, - "dependencies": {}, + "capabilities": [ + "configurable" + ], + "dependencies": { + "@rebble/clay": "^1.0.10" + }, "pebble": { "displayName": "GW2 Event Timers", "uuid": "0befcfd4-10e2-42e3-b7d8-95fef03c4ef1", "sdkVersion": "3", - "enableMultiJS": false, + "enableMultiJS": true, "targetPlatforms": [ "basalt", "chalk", @@ -22,7 +29,7 @@ "watchface": false }, "messageKeys": [ - "dummy" + "enabled_extensions[12]" ], "resources": { "media": [ 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); |
