/* * 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; ivalue->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; }