#include #include "app_gui.h" #include "gui_event.h" #include "ds_rtc.h" #include "app_io.h" #include "lcd.h" #include "app_config.h" static int threshold; static int cursor; void screen_set_moisture_threshold(GuiEvent event) { char buf[100]; switch (event) { case GUI_EVENT_SCREEN_INIT: threshold = 0; cursor = 0; break; case GUI_EVENT_PAINT: LcdBuffer_Write(&lcd, 0, 0, "Blokuj zálivku pokud"); LcdBuffer_Write(&lcd, 1, 0, "je vlhkost vyšší než"); LcdBuffer_SetCursor(&lcd, 2, cursor, (cursor < 3) ? CURSOR_BOTH : CURSOR_NONE); if (cursor > 0) { snprintf(buf, 100, "%d %%", threshold); LcdBuffer_Write(&lcd, 2, 0, buf); } else { LcdBuffer_Write(&lcd, 2, 0, " %"); } LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰Uložit"); break; case GUI_EVENT_KEY_A: // Confirm if (cursor > 0) { settings_scratch.moisture_threshold_percent = threshold; switch_screen(screen_settings, false); } break; case GUI_EVENT_KEY_D: // CANCEL switch_screen(screen_settings, false); break; default: if (event >= '0' && event <= '9') { int digit = event - '0'; int th2 = threshold * 10 + digit; if (th2 <= 100) { threshold = th2; cursor++; request_paint(); } } } }