feat: 实现摇一摇导航功能
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "settings_store.h"
|
||||
|
||||
#include "display.h"
|
||||
#include "motion_gesture.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "nvs.h"
|
||||
@@ -15,6 +16,8 @@ static const settings_data_t SETTINGS_DEFAULTS = {
|
||||
.brightness_pct = 70,
|
||||
.volume_pct = 50,
|
||||
.mute = false,
|
||||
.shake_nav_enabled = true,
|
||||
.shake_sensitivity = SHAKE_SENS_MED,
|
||||
};
|
||||
|
||||
static settings_data_t s_data;
|
||||
@@ -48,6 +51,10 @@ void settings_store_load(void)
|
||||
load_key_u8(handle, "vol", &s_data.volume_pct, SETTINGS_DEFAULTS.volume_pct);
|
||||
load_key_u8(handle, "mute", &val, SETTINGS_DEFAULTS.mute);
|
||||
s_data.mute = val != 0;
|
||||
load_key_u8(handle, "shake_en", &val, SETTINGS_DEFAULTS.shake_nav_enabled);
|
||||
s_data.shake_nav_enabled = val != 0;
|
||||
load_key_u8(handle, "shake_sens", &val, SETTINGS_DEFAULTS.shake_sensitivity);
|
||||
s_data.shake_sensitivity = (shake_sensitivity_t)val;
|
||||
|
||||
nvs_close(handle);
|
||||
ESP_LOGI(TAG, "Settings loaded (bright=%u vol=%u)", s_data.brightness_pct,
|
||||
@@ -83,6 +90,12 @@ esp_err_t settings_store_commit(void)
|
||||
if (err == ESP_OK) {
|
||||
err = nvs_set_u8(handle, "mute", s_data.mute ? 1 : 0);
|
||||
}
|
||||
if (err == ESP_OK) {
|
||||
err = nvs_set_u8(handle, "shake_en", s_data.shake_nav_enabled ? 1 : 0);
|
||||
}
|
||||
if (err == ESP_OK) {
|
||||
err = nvs_set_u8(handle, "shake_sens", (uint8_t)s_data.shake_sensitivity);
|
||||
}
|
||||
if (err == ESP_OK) {
|
||||
err = nvs_commit(handle);
|
||||
}
|
||||
@@ -118,4 +131,7 @@ void settings_store_apply(void)
|
||||
{
|
||||
uint16_t duty = (uint16_t)((s_data.brightness_pct * 1023U) / 100U);
|
||||
display_backlight_set_brightness(duty);
|
||||
|
||||
motion_gesture_set_enabled(s_data.shake_nav_enabled);
|
||||
motion_gesture_set_sensitivity(s_data.shake_sensitivity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user