diff options
author | Nick <nick.win999@gmail.com> | 2020-12-02 17:00:57 -0600 |
---|---|---|
committer | Pete Johanson <peter@peterjohanson.com> | 2020-12-14 22:46:49 -0500 |
commit | 2204a5dce47a5d3f5f8b32f316dbf0d9a8eea201 (patch) | |
tree | 61248ffaf34696513d348237e16bc0e1073fba63 /app/src/ble.c | |
parent | 69d48c5715885facee84259bfff3e277fa56bc2c (diff) |
refactor(settings): Debounce BLE/endpoint settings saves
Diffstat (limited to 'app/src/ble.c')
-rw-r--r-- | app/src/ble.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/app/src/ble.c b/app/src/ble.c index 1f311a0..9cfef4b 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -228,6 +228,23 @@ int zmk_ble_clear_bonds() { int zmk_ble_active_profile_index() { return active_profile; } +#if IS_ENABLED(CONFIG_SETTINGS) +static void ble_save_profile_work(struct k_work *work) { + settings_save_one("ble/active_profile", &active_profile, sizeof(active_profile)); +} + +static struct k_delayed_work ble_save_work; +#endif + +static int ble_save_profile() { +#if IS_ENABLED(CONFIG_SETTINGS) + k_delayed_work_cancel(&ble_save_work); + return k_delayed_work_submit(&ble_save_work, K_MSEC(CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE)); +#else + return 0; +#endif +} + int zmk_ble_prof_select(uint8_t index) { LOG_DBG("profile %d", index); if (active_profile == index) { @@ -235,7 +252,7 @@ int zmk_ble_prof_select(uint8_t index) { } active_profile = index; - settings_save_one("ble/active_profile", &active_profile, sizeof(active_profile)); + ble_save_profile(); update_advertising(); @@ -526,6 +543,8 @@ static int zmk_ble_init(const struct device *_arg) { return err; } + k_delayed_work_init(&ble_save_work, ble_save_profile_work); + settings_load_subtree("ble"); settings_load_subtree("bt"); |