Settings: cleanup menu
All checks were successful
ESP32 Build & Release / build (push) Successful in 1m13s

This commit is contained in:
2026-09-14 09:30:32 +02:00
parent a30ea5429f
commit dd04016fc3
6 changed files with 11 additions and 120 deletions

View File

@@ -12,6 +12,5 @@ idf_component_register(SRCS
"app_state.c" "app_state.c"
"ota_manager.c" "ota_manager.c"
"dns_server.c" "dns_server.c"
"board_led.c"
INCLUDE_DIRS "." INCLUDE_DIRS "."
) )

View File

@@ -1,57 +0,0 @@
#include "board_led.h"
#include "hw_pins.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "nvs.h"
static const char *TAG = "board_led";
static bool s_led_enabled = false;
esp_err_t board_led_init(void)
{
/* Configure GPIO */
gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << HW_STATUS_LED_GPIO),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE,
};
gpio_config(&io_conf);
/* Load persisted preference from NVS (default: false / OFF) */
nvs_handle_t h;
if (nvs_open("mtg_cfg", NVS_READONLY, &h) == ESP_OK) {
uint8_t val = 0;
if (nvs_get_u8(h, "led_en", &val) == ESP_OK) {
s_led_enabled = (val != 0);
}
nvs_close(h);
}
gpio_set_level(HW_STATUS_LED_GPIO, s_led_enabled ? 1 : 0);
ESP_LOGI(TAG, "Onboard status LED initialized on GPIO %d (state: %s)",
HW_STATUS_LED_GPIO, s_led_enabled ? "ON" : "OFF");
return ESP_OK;
}
bool board_led_get_enabled(void)
{
return s_led_enabled;
}
void board_led_set_enabled(bool enabled)
{
s_led_enabled = enabled;
gpio_set_level(HW_STATUS_LED_GPIO, s_led_enabled ? 1 : 0);
/* Persist to NVS */
nvs_handle_t h;
if (nvs_open("mtg_cfg", NVS_READWRITE, &h) == ESP_OK) {
nvs_set_u8(h, "led_en", enabled ? 1 : 0);
nvs_commit(h);
nvs_close(h);
}
ESP_LOGI(TAG, "Onboard status LED set to %s", enabled ? "ON" : "OFF");
}

View File

@@ -1,27 +0,0 @@
#pragma once
#include <stdbool.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialize onboard LED GPIO and apply saved NVS state (default: OFF).
*/
esp_err_t board_led_init(void);
/**
* @brief Get current onboard LED enabled state.
*/
bool board_led_get_enabled(void);
/**
* @brief Set onboard LED state and persist to NVS.
*/
void board_led_set_enabled(bool enabled);
#ifdef __cplusplus
}
#endif

View File

@@ -47,7 +47,4 @@
#define HW_ENC_SW_GPIO (GPIO_NUM_25) #define HW_ENC_SW_GPIO (GPIO_NUM_25)
/* Piezo buzzer */ /* Piezo buzzer */
#define HW_BUZZER_GPIO (GPIO_NUM_14) #define HW_BUZZER_GPIO (GPIO_NUM_14)
/* Onboard status LED (GPIO 2 on standard ESP32 DevKit boards) */
#define HW_STATUS_LED_GPIO (GPIO_NUM_2)

View File

@@ -10,7 +10,6 @@
#include "scryfall_client.h" #include "scryfall_client.h"
#include "web_server.h" #include "web_server.h"
#include "ota_manager.h" #include "ota_manager.h"
#include "board_led.h"
static const char *TAG = "MAIN"; static const char *TAG = "MAIN";
@@ -18,9 +17,6 @@ void app_main(void)
{ {
ESP_LOGI(TAG, "MTG RFID Companion booting..."); ESP_LOGI(TAG, "MTG RFID Companion booting...");
/* Initialize onboard status LED early (turns off red LED per user setting) */
board_led_init();
/* Validate OTA partition & cancel rollback if just updated */ /* Validate OTA partition & cancel rollback if just updated */
ota_manager_init(); ota_manager_init();

View File

@@ -21,7 +21,6 @@
#include "buzzer.h" #include "buzzer.h"
#include "jpeg_decoder.h" #include "jpeg_decoder.h"
#include "ota_manager.h" #include "ota_manager.h"
#include "board_led.h"
#include "ui_task.h" #include "ui_task.h"
static const char *TAG = "ui"; static const char *TAG = "ui";
@@ -56,15 +55,14 @@ static const char *s_menu_labels[MAIN_MENU_ITEM_COUNT] = {
"6. SETTINGS & TOOLS" "6. SETTINGS & TOOLS"
}; };
#define SETTINGS_MENU_ITEM_COUNT 6 #define SETTINGS_MENU_ITEM_COUNT 5
static int s_settings_idx = 0; static int s_settings_idx = 0;
static const char *s_settings_labels[SETTINGS_MENU_ITEM_COUNT] = { static const char *s_settings_labels[SETTINGS_MENU_ITEM_COUNT] = {
"< BACK TO MAIN MENU", "< BACK TO MAIN MENU",
"1. AUDIO: CHIPTUNE", "1. AUDIO: CHIPTUNE",
"2. RED LED: OFF", "2. DECK STORAGE",
"3. DECK STORAGE", "3. DEVICE & WIFI INFO",
"4. DEVICE & WIFI INFO", "4. UPDATE FIRMWARE"
"5. UPDATE FIRMWARE"
}; };
/* Life & Counters */ /* Life & Counters */
@@ -383,12 +381,9 @@ static void view_settings_menu(void)
char audio_lbl_buf[36]; char audio_lbl_buf[36];
snprintf(audio_lbl_buf, sizeof(audio_lbl_buf), "1. AUDIO: %s", buzzer_get_profile_name(buzzer_get_profile())); snprintf(audio_lbl_buf, sizeof(audio_lbl_buf), "1. AUDIO: %s", buzzer_get_profile_name(buzzer_get_profile()));
char led_lbl_buf[36]; int start_y = 50;
snprintf(led_lbl_buf, sizeof(led_lbl_buf), "2. RED LED: %s", board_led_get_enabled() ? "ON" : "OFF");
int start_y = 44;
int row_height = 34; int row_height = 34;
int row_gap = 7; int row_gap = 8;
for (int i = 0; i < SETTINGS_MENU_ITEM_COUNT; i++) { for (int i = 0; i < SETTINGS_MENU_ITEM_COUNT; i++) {
bool selected = (i == s_settings_idx); bool selected = (i == s_settings_idx);
@@ -409,12 +404,7 @@ static void view_settings_menu(void)
lv_obj_set_style_border_width(item_box, 1, 0); lv_obj_set_style_border_width(item_box, 1, 0);
} }
const char *item_txt = s_settings_labels[i]; const char *item_txt = (i == 1) ? audio_lbl_buf : s_settings_labels[i];
if (i == 1) {
item_txt = audio_lbl_buf;
} else if (i == 2) {
item_txt = led_lbl_buf;
}
lv_obj_t *lbl = lv_label_create(item_box); lv_obj_t *lbl = lv_label_create(item_box);
if (i == 0) { if (i == 0) {
/* Back button item */ /* Back button item */
@@ -2030,24 +2020,17 @@ static void handle_encoder_click(void)
view_settings_menu(); view_settings_menu();
break; break;
} }
case 2: { /* RED LED inline toggle */ case 2: /* DECK STORAGE */
bool new_state = !board_led_get_enabled();
board_led_set_enabled(new_state);
buzzer_sound_tick();
view_settings_menu();
break;
}
case 3: /* DECK STORAGE */
app_set_view(APP_STATE_STORAGE_MANAGER); app_set_view(APP_STATE_STORAGE_MANAGER);
s_storage_confirm_dialog = false; s_storage_confirm_dialog = false;
s_storage_option_idx = 0; s_storage_option_idx = 0;
view_storage(); view_storage();
break; break;
case 4: /* DEVICE & WIFI INFO */ case 3: /* DEVICE & WIFI INFO */
app_set_view(APP_STATE_DEVICE_INFO); app_set_view(APP_STATE_DEVICE_INFO);
view_device_info(); view_device_info();
break; break;
case 5: /* UPDATE FIRMWARE */ case 4: /* UPDATE FIRMWARE */
app_set_view(APP_STATE_OTA_UPDATE); app_set_view(APP_STATE_OTA_UPDATE);
buzzer_chirp(988, 40); buzzer_chirp(988, 40);
ota_manager_check_update_async(); ota_manager_check_update_async();