#include "apps.h" #include "os_gfx.h" #include "os_status.h" #include "os_oled.h" #include #include "esp_system.h" #define SETTINGS_COUNT 4 static const char *s_menu_items[SETTINGS_COUNT] = { "Contrast", "Invert", "Status Bar", "Reboot" }; static size_t s_selected_idx = 0; static uint8_t s_contrast_level = 3; static bool s_inverted = false; static void apply_contrast(void) { uint8_t val = 255; if (s_contrast_level == 0) val = 30; else if (s_contrast_level == 1) val = 100; else if (s_contrast_level == 2) val = 180; oled_driver_set_contrast(val); } static void settings_init(void) { s_selected_idx = 0; s_contrast_level = 3; s_inverted = false; } static void settings_enter(void) { } static void settings_update(uint32_t delta_ms) { sys_status_t status; sys_status_get(&status); sys_gfx_draw_status_bar(&status); sys_gfx_draw_menu(9, s_menu_items, SETTINGS_COUNT, s_selected_idx); sys_gfx_draw_action_bar("C:NEXT", "H:TOGGLE"); } static void settings_handle_input(input_action_t action) { if (action == INPUT_ACTION_CLICK) { s_selected_idx = (s_selected_idx + 1) % SETTINGS_COUNT; } else if (action == INPUT_ACTION_DOUBLE_CLICK) { if (s_selected_idx == 0) s_selected_idx = SETTINGS_COUNT - 1; else s_selected_idx--; } else if (action == INPUT_ACTION_LONG_PRESS) { switch (s_selected_idx) { case 0: s_contrast_level = (s_contrast_level + 1) % 4; apply_contrast(); sys_gfx_show_toast("Contrast Chg", 600); break; case 1: s_inverted = !s_inverted; oled_driver_set_invert(s_inverted); sys_gfx_show_toast(s_inverted ? "Inverted" : "Normal", 600); break; case 2: { bool vis = sys_status_is_status_bar_visible(); sys_status_set_status_bar_visible(!vis); sys_gfx_show_toast(!vis ? "Bar: ON" : "Bar: OFF", 600); } break; case 3: sys_gfx_show_toast("Rebooting...", 1000); sys_gfx_flush(); esp_restart(); break; default: break; } } } static void settings_exit(void) { } const sys_app_t g_app_settings = { .id = "settings", .name = "Settings", .init = settings_init, .enter = settings_enter, .update = settings_update, .handle_input = settings_handle_input, .exit = settings_exit, };