feat: 实现设置页面及其功能
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
#include "ui_handlers.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ble_hid.h"
|
||||
#include "boot_button.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_system.h"
|
||||
#include "screens/ui_Settings.h"
|
||||
#include "settings/settings_store.h"
|
||||
#include "settings/settings_tabs.h"
|
||||
#include "ui_events.h"
|
||||
|
||||
static const char *TAG = "ui_handlers";
|
||||
@@ -37,6 +42,83 @@ void ui_handlers_init(void)
|
||||
boot_button_init(on_boot_press);
|
||||
}
|
||||
|
||||
void settings_on_tab_clicked(lv_event_t *e)
|
||||
{
|
||||
settings_tab_t tab = (settings_tab_t)(intptr_t)lv_event_get_user_data(e);
|
||||
ui_Settings_switch_tab(tab);
|
||||
}
|
||||
|
||||
void settings_on_save_clicked(lv_event_t *e)
|
||||
{
|
||||
(void)e;
|
||||
settings_data_t buf = *settings_store_get();
|
||||
settings_tabs_collect(ui_Settings_get_active_tab(), &buf);
|
||||
settings_store_update(&buf);
|
||||
esp_err_t err = settings_store_commit();
|
||||
if (err == ESP_OK) {
|
||||
settings_store_apply();
|
||||
ESP_LOGI(TAG, "Settings saved");
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Settings save failed");
|
||||
}
|
||||
}
|
||||
|
||||
void settings_on_factory_reset(lv_event_t *e)
|
||||
{
|
||||
(void)e;
|
||||
ESP_LOGW(TAG, "Factory reset");
|
||||
settings_store_factory_reset();
|
||||
settings_store_apply();
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
void settings_on_brightness_changed(lv_event_t *e)
|
||||
{
|
||||
lv_obj_t *slider = lv_event_get_target(e);
|
||||
uint8_t pct = (uint8_t)lv_slider_get_value(slider);
|
||||
|
||||
settings_data_t buf = *settings_store_get();
|
||||
buf.brightness_pct = pct;
|
||||
settings_store_update(&buf);
|
||||
settings_store_apply();
|
||||
|
||||
lv_obj_t *pct_label = lv_obj_get_user_data(slider);
|
||||
if (pct_label != NULL) {
|
||||
lv_label_set_text_fmt(pct_label, "%u%%", pct);
|
||||
}
|
||||
}
|
||||
|
||||
void settings_on_value_changed(lv_event_t *e)
|
||||
{
|
||||
settings_field_t field =
|
||||
(settings_field_t)(intptr_t)lv_event_get_user_data(e);
|
||||
lv_obj_t *target = lv_event_get_target(e);
|
||||
settings_data_t buf = *settings_store_get();
|
||||
|
||||
switch (field) {
|
||||
case SETTINGS_FIELD_NOTIFICATION:
|
||||
buf.notification_enabled = lv_obj_has_state(target, LV_STATE_CHECKED);
|
||||
break;
|
||||
case SETTINGS_FIELD_VOLUME:
|
||||
buf.volume_pct = (uint8_t)lv_slider_get_value(target);
|
||||
break;
|
||||
case SETTINGS_FIELD_MUTE:
|
||||
buf.mute = lv_obj_has_state(target, LV_STATE_CHECKED);
|
||||
break;
|
||||
default:
|
||||
LV_ASSERT_MSG(false, "unexpected settings_field_t");
|
||||
break;
|
||||
}
|
||||
|
||||
settings_store_update(&buf);
|
||||
}
|
||||
|
||||
void settings_on_network_scan_clicked(lv_event_t *e)
|
||||
{
|
||||
(void)e;
|
||||
ESP_LOGI(TAG, "Not available");
|
||||
}
|
||||
|
||||
void update_year_action(lv_event_t * e)
|
||||
{
|
||||
(void)e;
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "lvgl.h"
|
||||
|
||||
/* UI event callbacks declared in ui_events.h are implemented in ui_handlers.c */
|
||||
void ui_handlers_init(void);
|
||||
|
||||
void settings_on_tab_clicked(lv_event_t *e);
|
||||
void settings_on_save_clicked(lv_event_t *e);
|
||||
void settings_on_factory_reset(lv_event_t *e);
|
||||
void settings_on_brightness_changed(lv_event_t *e);
|
||||
void settings_on_value_changed(lv_event_t *e);
|
||||
void settings_on_network_scan_clicked(lv_event_t *e);
|
||||
|
||||
Reference in New Issue
Block a user