From dc27d8bc83423d00bc22ba98936cab1548763c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Tue, 20 Jun 2023 00:20:40 +0200 Subject: [PATCH] program editor --- CMakeLists.txt | 2 + src/app_config.c | 6 +- src/screens/app_gui.h | 4 + src/screens/screen_delka_zalivky.c | 2 +- src/screens/screen_kompenzace_tlaku.c | 2 +- src/screens/screen_program_edit.c | 96 +++++++++++++++++++++ src/screens/screen_program_prehled.c | 60 +++++++++++++ src/screens/screen_set_moisture_threshold.c | 2 +- src/screens/screen_set_time.c | 13 ++- src/screens/screen_settings.c | 2 +- 10 files changed, 179 insertions(+), 10 deletions(-) create mode 100644 src/screens/screen_program_edit.c create mode 100644 src/screens/screen_program_prehled.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 04c0c84..192da2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,8 @@ add_executable(zavlaha src/screens/screen_moisture_calib.c src/screens/screen_delka_zalivky.c src/screens/screen_kompenzace_tlaku.c + src/screens/screen_program_prehled.c + src/screens/screen_program_edit.c src/app_io.c src/app_config.c) diff --git a/src/app_config.c b/src/app_config.c index 2b280b9..8bdef49 100644 --- a/src/app_config.c +++ b/src/app_config.c @@ -17,9 +17,9 @@ static const struct AppConfig DEFAULTS = { .circuit_time_percent = {30, 60, 90, 100}, // for a test .schedules = { {true, 6, 45}, - {false, 255, 0}, - {false, 255, 0}, - {false, 255, 0} + {false, 0, 0}, + {false, 0, 0}, + {false, 0, 0} }, .moisture_enable = true, .moisture_dry = 2800, diff --git a/src/screens/app_gui.h b/src/screens/app_gui.h index de9cabf..ad3e53c 100644 --- a/src/screens/app_gui.h +++ b/src/screens/app_gui.h @@ -56,6 +56,10 @@ 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); +void screen_program_prehled(GuiEvent event); + +extern int pgm_edit_slot; +void screen_program_edit(GuiEvent event); // XXX other prototypes struct State { diff --git a/src/screens/screen_delka_zalivky.c b/src/screens/screen_delka_zalivky.c index c47e6e0..b3e892b 100644 --- a/src/screens/screen_delka_zalivky.c +++ b/src/screens/screen_delka_zalivky.c @@ -34,7 +34,7 @@ void screen_delka_zalivky(GuiEvent event) LcdBuffer_Write(&lcd, 2, 0, buf); } - LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰Uložit"); + LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰OK"); break; case GUI_EVENT_KEY_A: // Confirm diff --git a/src/screens/screen_kompenzace_tlaku.c b/src/screens/screen_kompenzace_tlaku.c index fa2f5a4..2aa1aa2 100644 --- a/src/screens/screen_kompenzace_tlaku.c +++ b/src/screens/screen_kompenzace_tlaku.c @@ -43,7 +43,7 @@ void screen_kompenzace_tlaku(GuiEvent event) break; } - LcdBuffer_Write(&lcd, 3, 0, "⊛- ¤+ 🅳Zruš 🅰Ulož"); + LcdBuffer_Write(&lcd, 3, 0, "⊛- ¤+ 🅳Zruš 🅰OK"); break; case GUI_EVENT_KEY_A: // Confirm diff --git a/src/screens/screen_program_edit.c b/src/screens/screen_program_edit.c new file mode 100644 index 0000000..c407491 --- /dev/null +++ b/src/screens/screen_program_edit.c @@ -0,0 +1,96 @@ +#include +#include +#include "app_gui.h" +#include "gui_event.h" +#include "app_io.h" +#include "lcd.h" +#include "app_config.h" + +static struct ScheduleTime time; +static int cursor; + +int pgm_edit_slot; // set from the program overview screen + +void screen_program_edit(GuiEvent event) +{ + char buf[100]; + + switch (event) { + case GUI_EVENT_SCREEN_INIT: + memcpy(&time, &settings_scratch.schedules[pgm_edit_slot], sizeof(time)); + cursor = 0; + break; + + case GUI_EVENT_PAINT: + snprintf(buf, 100, "Denní slot %d", 1 + pgm_edit_slot); + LcdBuffer_Write(&lcd, 0, 0, buf); + + if (time.enable) { + LcdBuffer_SetCursor(&lcd, 1, cursor + (cursor >= 2), (cursor < 4) ? CURSOR_BOTH : CURSOR_NONE); + snprintf(buf, 100, "%02d:%02d", time.h, time.m); + LcdBuffer_Write(&lcd, 1, 0, buf); + } else { + LcdBuffer_SetCursor(&lcd, 0, 0, CURSOR_NONE); + LcdBuffer_Write(&lcd, 1, 0, "--:-- (slot vypnutý)"); + } + + if (!time.enable) { + LcdBuffer_Write(&lcd, 3, 0, "🅱Zapnout 🅳Zruš 🅰OK"); + } else { + LcdBuffer_Write(&lcd, 3, 0, (cursor < 4) ? "🅱Vypnout 🅳Zruš" : "🅱Vypnout 🅳Zruš 🅰OK"); + } + break; + + case GUI_EVENT_KEY_A: // Confirm + if (!time.enable || cursor == 4) { + memcpy(&settings_scratch.schedules[pgm_edit_slot], &time, sizeof(time)); + switch_screen(screen_program_prehled, false); + } + break; + + case GUI_EVENT_KEY_B: // Zap/Vyp + time.enable = !time.enable; + cursor = 0; + LcdBuffer_Clear(&lcd); + request_paint(); + break; + + case GUI_EVENT_KEY_D: // CANCEL + switch_screen(screen_program_prehled, false); + break; + + default: + if (event >= '0' && event <= '9') { + if (cursor == 0) { + // it showed the current time, but now we are entering something, so it must be reset! + time.h = 0; + time.m = 0; + } + + int digit = event - '0'; + if (cursor == 0) { + if (digit <= 2) { + time.h += digit * 10; + cursor++; + request_paint(); + } + } else if (cursor == 1) { + if (time.h < 20 || digit <= 3) { + time.h += digit; + cursor++; + request_paint(); + } + } else if (cursor == 2) { + if (digit <= 5) { + time.m += digit * 10; + cursor++; + request_paint(); + } + } else if (cursor == 3) { + time.m += digit; + cursor++; // cursor disappears + request_paint(); + } + } + } +} diff --git a/src/screens/screen_program_prehled.c b/src/screens/screen_program_prehled.c new file mode 100644 index 0000000..f86225a --- /dev/null +++ b/src/screens/screen_program_prehled.c @@ -0,0 +1,60 @@ +#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" + +void screen_program_prehled(GuiEvent event) +{ + char buf[100]; + + switch (event) { + case GUI_EVENT_SCREEN_INIT: + break; + + case GUI_EVENT_PAINT: + LcdBuffer_Write(&lcd, 0, 0, "Zvolte slot ke změně"); + + if (settings_scratch.schedules[0].enable) { + snprintf(buf, 100, "1. %02d:%02d ", settings_scratch.schedules[0].h, settings_scratch.schedules[0].m); + } else { + snprintf(buf, 100, "1. --:-- "); + } + if (settings_scratch.schedules[2].enable) { + snprintf(buf+10, 90, "3. %02d:%02d ", settings_scratch.schedules[2].h, settings_scratch.schedules[2].m); + } else { + snprintf(buf+10, 90, "3. --:-- "); + } + LcdBuffer_Write(&lcd, 1, 0, buf); + + if (settings_scratch.schedules[1].enable) { + snprintf(buf, 100, "2. %02d:%02d ", settings_scratch.schedules[1].h, settings_scratch.schedules[1].m); + } else { + snprintf(buf, 100, "2. --:-- "); + } + if (settings_scratch.schedules[3].enable) { + snprintf(buf+10, 90, "4. %02d:%02d ", settings_scratch.schedules[3].h, settings_scratch.schedules[3].m); + } else { + snprintf(buf+10, 90, "4. --:-- "); + } + LcdBuffer_Write(&lcd, 2, 0, buf); + + LcdBuffer_Write(&lcd, 3, 0, "🅳Zpět"); + 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: + pgm_edit_slot = event - '1'; // 0-3 + switch_screen(screen_program_edit, true); + break; + } +} diff --git a/src/screens/screen_set_moisture_threshold.c b/src/screens/screen_set_moisture_threshold.c index 0cc2165..0fbcbcb 100644 --- a/src/screens/screen_set_moisture_threshold.c +++ b/src/screens/screen_set_moisture_threshold.c @@ -33,7 +33,7 @@ void screen_set_moisture_threshold(GuiEvent event) LcdBuffer_Write(&lcd, 2, 0, buf); } - LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰Uložit"); + LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰OK"); break; case GUI_EVENT_KEY_A: // Confirm diff --git a/src/screens/screen_set_time.c b/src/screens/screen_set_time.c index 803802b..d7f5109 100644 --- a/src/screens/screen_set_time.c +++ b/src/screens/screen_set_time.c @@ -14,8 +14,9 @@ void screen_set_time(GuiEvent event) switch (event) { case GUI_EVENT_SCREEN_INIT: - time.hour = 0; - time.minute = 0; + rtc_get_time(&time); // so it's shown in the preview +// time.hour = 0; +// time.minute = 0; time.second = 0; cursor = 0; break; @@ -28,7 +29,7 @@ void screen_set_time(GuiEvent event) snprintf(buf, 100, "%02d:%02d", time.hour, time.minute); LcdBuffer_Write(&lcd, 1, 0, buf); - LcdBuffer_Write(&lcd, 3, 0, cursor < 4 ? "🅳Zrušit" : "🅳Zrušit 🅰Uložit"); + LcdBuffer_Write(&lcd, 3, 0, cursor < 4 ? "🅳Zrušit" : "🅳Zrušit 🅰Nastavit"); break; case GUI_EVENT_KEY_A: // Confirm @@ -44,6 +45,12 @@ void screen_set_time(GuiEvent event) default: if (event >= '0' && event <= '9') { + if (cursor == 0) { + // it showed the current time, but now we are entering something, so it must be reset! + time.hour = 0; + time.minute = 0; + } + int digit = event - '0'; if (cursor == 0) { if (digit <= 2) { diff --git a/src/screens/screen_settings.c b/src/screens/screen_settings.c index 8ba2f3d..3638e74 100644 --- a/src/screens/screen_settings.c +++ b/src/screens/screen_settings.c @@ -97,7 +97,7 @@ void screen_settings(GuiEvent event) break; case GUI_EVENT_KEY_2: // Upravit program - // TODO + switch_screen(screen_program_prehled, true); break; case GUI_EVENT_KEY_3: // Nastavit cas