refactor(settings): Debounce BLE/endpoint settings saves

This commit is contained in:
Nick
2020-12-02 17:00:57 -06:00
committed by Pete Johanson
parent 69d48c5715
commit 2204a5dce4
2 changed files with 40 additions and 4 deletions

View File

@@ -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");