From 7e9d9aa9bc152e9e9d7fd73cf2a90714a6ec95fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Mon, 19 Jun 2023 23:21:07 +0200 Subject: [PATCH] fixes, add compensation screen & more --- CMakeLists.txt | 2 + src/app_config.h | 2 +- src/screens/app_gui.h | 2 + src/screens/screen_delka_zalivky.c | 66 +++++++++++++++++ src/screens/screen_kompenzace_tlaku.c | 80 +++++++++++++++++++++ src/screens/screen_set_moisture_threshold.c | 9 ++- src/screens/screen_settings.c | 3 +- 7 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 src/screens/screen_delka_zalivky.c create mode 100644 src/screens/screen_kompenzace_tlaku.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 29ea741..04c0c84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,8 @@ add_executable(zavlaha src/screens/screen_set_time.c src/screens/screen_set_moisture_threshold.c src/screens/screen_moisture_calib.c + src/screens/screen_delka_zalivky.c + src/screens/screen_kompenzace_tlaku.c src/app_io.c src/app_config.c) diff --git a/src/app_config.h b/src/app_config.h index f0878ef..4e72695 100644 --- a/src/app_config.h +++ b/src/app_config.h @@ -20,7 +20,7 @@ struct __attribute__((packed)) ScheduleTime { struct __attribute__((packed)) AppConfig { uint8_t magic_version; uint16_t circuit_base_time_s; - uint8_t circuit_time_percent[CIRCUIT_COUNT]; // 0% can be used to disable a branch + uint16_t circuit_time_percent[CIRCUIT_COUNT]; // 0% can be used to disable a branch bool scheduler_enable; struct ScheduleTime schedules[SCHEDULE_COUNT]; bool moisture_enable; diff --git a/src/screens/app_gui.h b/src/screens/app_gui.h index 58a019f..de9cabf 100644 --- a/src/screens/app_gui.h +++ b/src/screens/app_gui.h @@ -54,6 +54,8 @@ void screen_settings(GuiEvent event); void screen_set_time(GuiEvent event); void screen_set_moisture_threshold(GuiEvent event); void screen_moisture_calib(GuiEvent event); +void screen_delka_zalivky(GuiEvent event); +void screen_kompenzace_tlaku(GuiEvent event); // XXX other prototypes struct State { diff --git a/src/screens/screen_delka_zalivky.c b/src/screens/screen_delka_zalivky.c new file mode 100644 index 0000000..c47e6e0 --- /dev/null +++ b/src/screens/screen_delka_zalivky.c @@ -0,0 +1,66 @@ +#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 value; +static int cursor; + +void screen_delka_zalivky(GuiEvent event) +{ + char buf[100]; + + switch (event) { + case GUI_EVENT_SCREEN_INIT: + value = 0; + cursor = 0; + break; + + case GUI_EVENT_PAINT: + LcdBuffer_Write(&lcd, 0, 0, "Zadej základní délku"); + LcdBuffer_Write(&lcd, 1, 0, "zálivky (1 okruh)"); + + LcdBuffer_SetCursor(&lcd, 2, cursor, CURSOR_BOTH); + + if (cursor > 0) { + snprintf(buf, 100, "%d s", value); + LcdBuffer_Write(&lcd, 2, 0, buf); + } else { + // show orig value + snprintf(buf, 100, "%d s", settings_scratch.circuit_base_time_s); + LcdBuffer_Write(&lcd, 2, 0, buf); + } + + 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.circuit_base_time_s = value; + 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 = value * 10 + digit; + if (th2 <= 10000) { // just some sensible big number that doesn't overflow the LCD row + value = th2; + if (cursor == 0) { + // clear the line + LcdBuffer_Write(&lcd, 2, 0, " "); + } + cursor++; + request_paint(); + } + } + } +} diff --git a/src/screens/screen_kompenzace_tlaku.c b/src/screens/screen_kompenzace_tlaku.c new file mode 100644 index 0000000..fa2f5a4 --- /dev/null +++ b/src/screens/screen_kompenzace_tlaku.c @@ -0,0 +1,80 @@ +#include +#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 uint16_t ratios[CIRCUIT_COUNT]; +static int cursor; + +void screen_kompenzace_tlaku(GuiEvent event) +{ + char buf[100]; + + switch (event) { + case GUI_EVENT_SCREEN_INIT: + cursor = 0; + memcpy(ratios, settings_scratch.circuit_time_percent, sizeof(settings_scratch.circuit_time_percent)); + break; + + case GUI_EVENT_PAINT: + LcdBuffer_Write(&lcd, 0, 0, "Relativní čas okruhů"); + + snprintf(buf, 100, "1. %3d%% 3. %3d%%", ratios[0], ratios[2]); + LcdBuffer_Write(&lcd, 1, 0, buf); + snprintf(buf, 100, "2. %3d%% 4. %3d%%", ratios[1], ratios[3]); + LcdBuffer_Write(&lcd, 2, 0, buf); + + switch (cursor) { + case 0: + LcdBuffer_SetCursor(&lcd, 1, 0, CURSOR_BOTH); + break; + case 1: + LcdBuffer_SetCursor(&lcd, 2, 0, CURSOR_BOTH); + break; + case 2: + LcdBuffer_SetCursor(&lcd, 1, 10, CURSOR_BOTH); + break; + case 3: + LcdBuffer_SetCursor(&lcd, 2, 10, CURSOR_BOTH); + break; + } + + LcdBuffer_Write(&lcd, 3, 0, "⊛- ¤+ 🅳Zruš 🅰Ulož"); + break; + + case GUI_EVENT_KEY_A: // Confirm + memcpy(settings_scratch.circuit_time_percent, ratios, sizeof(settings_scratch.circuit_time_percent)); + switch_screen(screen_settings, false); + break; + + case GUI_EVENT_KEY_D: // CANCEL + switch_screen(screen_settings, false); + break; + + case GUI_EVENT_KEY_1: + case GUI_EVENT_KEY_2: + case GUI_EVENT_KEY_3: + case GUI_EVENT_KEY_4: + cursor = event - '1'; + request_paint(); + break; + + case GUI_EVENT_KEY_STAR: + if (ratios[cursor] >= 5) { + ratios[cursor] -= 5; + request_paint(); + } + break; + + case GUI_EVENT_KEY_HASH: + if (ratios[cursor] < 65535) { + ratios[cursor] += 5; + request_paint(); + } + break; + } +} diff --git a/src/screens/screen_set_moisture_threshold.c b/src/screens/screen_set_moisture_threshold.c index 1bad130..0cc2165 100644 --- a/src/screens/screen_set_moisture_threshold.c +++ b/src/screens/screen_set_moisture_threshold.c @@ -23,13 +23,14 @@ void screen_set_moisture_threshold(GuiEvent event) 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); + LcdBuffer_SetCursor(&lcd, 2, cursor, (cursor < 3) ? CURSOR_BLINK : CURSOR_NONE); if (cursor > 0) { snprintf(buf, 100, "%d %%", threshold); LcdBuffer_Write(&lcd, 2, 0, buf); } else { - LcdBuffer_Write(&lcd, 2, 0, " %"); + snprintf(buf, 100, "%d %%", settings_scratch.moisture_threshold_percent); + LcdBuffer_Write(&lcd, 2, 0, buf); } LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰Uložit"); @@ -51,6 +52,10 @@ void screen_set_moisture_threshold(GuiEvent event) int digit = event - '0'; int th2 = threshold * 10 + digit; if (th2 <= 100) { + if (cursor == 0) { + // clear the line + LcdBuffer_Write(&lcd, 2, 0, " "); + } threshold = th2; cursor++; request_paint(); diff --git a/src/screens/screen_settings.c b/src/screens/screen_settings.c index 0532bd7..8ba2f3d 100644 --- a/src/screens/screen_settings.c +++ b/src/screens/screen_settings.c @@ -109,10 +109,11 @@ void screen_settings(GuiEvent event) case 2: switch (event) { case GUI_EVENT_KEY_1: // Délka zálivky + switch_screen(screen_delka_zalivky, true); break; case GUI_EVENT_KEY_2: // Kompenzace tlaku - // TODO + switch_screen(screen_kompenzace_tlaku, true); break; } break;