From 2eefdf6325ef1cca63699ea7e8696e200b92ff90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 15 Jun 2023 00:57:33 +0200 Subject: [PATCH] some work on screens --- CMakeLists.txt | 5 +- src/app_config.c | 21 ++++ src/app_config.h | 33 ++++++ src/lcd/cgram.c | 202 ++++++++++++++++++++++++++++++++++++ src/screens/app_gui.h | 3 + src/screens/screen_cyklus.c | 37 +++++++ src/screens/screen_home.c | 32 +++++- 7 files changed, 327 insertions(+), 6 deletions(-) create mode 100644 src/app_config.c create mode 100644 src/app_config.h create mode 100644 src/screens/screen_cyklus.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9132a78..3b5a1c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,10 @@ add_executable(zavlaha src/lcd/cgrom.c src/lcd/lcdbuf.c src/screens/app_gui.c - src/screens/screen_home.c src/app_io.c) + src/screens/screen_home.c + src/app_io.c + src/app_config.c + src/screens/screen_cyklus.c) # Add pico_stdlib library which aggregates commonly used features target_link_libraries(zavlaha pico_stdlib hardware_i2c hardware_adc hardware_irq) diff --git a/src/app_config.c b/src/app_config.c new file mode 100644 index 0000000..11a3cee --- /dev/null +++ b/src/app_config.c @@ -0,0 +1,21 @@ +/** + * TODO file description + */ + +#include "app_config.h" + +// TODO sensible defaults, loading and saving to/from EE +struct AppConfig app_config = { + .circuit_base_time_s = 10, // for a test + .circuit_time_percent = {30, 60, 90, 100}, // for a test + .schedules = { + {6, 45}, + {255, 0}, + {255, 0}, + {255, 0} + }, + .moisture_enable = true, + .moisture_dry = 2800, + .moisture_wet = 1600, + .moisture_threshold_percent = 70, +}; diff --git a/src/app_config.h b/src/app_config.h new file mode 100644 index 0000000..7eb28fd --- /dev/null +++ b/src/app_config.h @@ -0,0 +1,33 @@ +/** + * TODO file description + */ + +#ifndef ZAVLAHA_APP_CONFIG_H +#define ZAVLAHA_APP_CONFIG_H + +#include +#include + +#define CIRCUIT_COUNT 4 +#define SCHEDULE_COUNT 4 + +#define UNUSED_SCHEDULE_HOUR 0xFF + +struct ScheduleTime { + uint8_t h; + uint8_t m; +}; + +struct AppConfig { + uint16_t circuit_base_time_s; + uint8_t circuit_time_percent[CIRCUIT_COUNT]; // 0% can be used to disable a branch + struct ScheduleTime schedules[SCHEDULE_COUNT]; // 0xFF hour is used to disable the slot + bool moisture_enable; + uint16_t moisture_dry; + uint16_t moisture_wet; + uint8_t moisture_threshold_percent; +}; + +extern struct AppConfig app_config; + +#endif //ZAVLAHA_APP_CONFIG_H diff --git a/src/lcd/cgram.c b/src/lcd/cgram.c index 9a14aea..ce7df59 100644 --- a/src/lcd/cgram.c +++ b/src/lcd/cgram.c @@ -372,6 +372,208 @@ const struct LcdBuf_CGRAM_Symbol CGRAM_CZ[] = { }, }, + // GUI symbols + + { + .symbol = "🌢", // Humidity + .fallback = 'H', + .data = { + 0b00100, + 0b01110, + 0b01110, + 0b11111, + 0b10111, + 0b11111, + 0b01110, + }, + }, + + // Some useful glyphs for GUI with a keypad + + { + .symbol = "🅰", + .fallback = 'A', + .data = { + 0b11111, + 0b11011, + 0b10101, + 0b10001, + 0b10101, + 0b10101, + 0b11111, + }, + }, + { + .symbol = "🅱", + .fallback = 'B', + .data = { + 0b11111, + 0b10011, + 0b10101, + 0b10011, + 0b10101, + 0b10011, + 0b11111, + }, + }, + { + .symbol = "🅲", + .fallback = 'C', + .data = { + 0b11111, + 0b11011, + 0b10101, + 0b10111, + 0b10101, + 0b11011, + 0b11111, + }, + }, + { + .symbol = "🅳", + .fallback = 'D', + .data = { + 0b11111, + 0b10011, + 0b10101, + 0b10101, + 0b10101, + 0b10011, + 0b11111, + }, + }, + { + .symbol = "❶", + .fallback = '1', + .data = { + 0b11111, + 0b11011, + 0b10011, + 0b11011, + 0b11011, + 0b10001, + 0b11111, + }, + }, + { + .symbol = "❷", + .fallback = '2', + .data = { + 0b11111, + 0b11001, + 0b10101, + 0b11101, + 0b11011, + 0b10001, + 0b11111, + }, + }, + { + .symbol = "❸", + .fallback = '3', + .data = { + 0b11111, + 0b10011, + 0b11101, + 0b10011, + 0b11101, + 0b10011, + 0b11111, + }, + }, + { + .symbol = "❹", + .fallback = '4', + .data = { + 0b11111, + 0b10101, + 0b10101, + 0b10001, + 0b11101, + 0b11101, + 0b11111, + }, + }, + { + .symbol = "⊛", + .fallback = '*', + .data = { + 0b11111, + 0b01010, + 0b10001, + 0b00000, + 0b10001, + 0b01010, + 0b11111, + }, + }, + { + .symbol = "¤", + .fallback = '#', + .data = { + 0b11111, + 0b10101, + 0b00000, + 0b10101, + 0b00000, + 0b10101, + 0b11111, + }, + }, + { + .symbol = "▌", + .fallback = ' ', + .data = { + 0b11100, + 0b11100, + 0b11100, + 0b11100, + 0b11100, + 0b11100, + 0b11100, + 0b11100, + }, + }, + { + .symbol = "↑", + .fallback = '^', + .data = { + 0b00100, + 0b01110, + 0b10101, + 0b00100, + 0b00100, + 0b00100, + 0b00100, + }, + }, + { + .symbol = "↓", + .fallback = 'v', + .data = { + 0b00100, + 0b00100, + 0b00100, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + }, + }, + { + .symbol = "✔", + .fallback = 0xE8, + .data = { + 0b00000, + 0b00000, + 0b00001, + 0b10011, + 0b11110, + 0b01100, + 0b00000, + }, + }, + {}, /* end mark */ }; diff --git a/src/screens/app_gui.h b/src/screens/app_gui.h index 77e00c6..c81b0b9 100644 --- a/src/screens/app_gui.h +++ b/src/screens/app_gui.h @@ -11,6 +11,8 @@ #include "gui_event.h" #include "lcd/lcdbuf.h" +// 🌢🅰🅱🅲🅳❶❷❸❹⊛¤▌↑↓✔ + /// Temporary scratch buffer extern char stmp[100]; @@ -46,6 +48,7 @@ void request_paint(); // prototypes for screen handlers void screen_home(GuiEvent event); +void screen_cyklus(GuiEvent event); // XXX other prototypes struct State { diff --git a/src/screens/screen_cyklus.c b/src/screens/screen_cyklus.c new file mode 100644 index 0000000..6a4cec5 --- /dev/null +++ b/src/screens/screen_cyklus.c @@ -0,0 +1,37 @@ +/** + * Zavlahovy cuklus + */ +// +// Created by MightyPork on 2023/04/09. +// + +#include +#include +#include "app_gui.h" +#include "gui_event.h" +#include "ds_rtc.h" +#include "app_io.h" + + +void screen_cyklus(GuiEvent event) +{ + uint32_t now = timestamp(); + + switch (event) { + case GUI_EVENT_SCREEN_INIT: + case GUI_EVENT_SCREEN_TICK: + // + break; + + case GUI_EVENT_PAINT: + LcdBuffer_Write(&lcd, 0, 0, "==ZÁVLAHOVÝ CYKLUS=="); + LcdBuffer_Write(&lcd, 1, 0, "Okruh 2/4 30/200s"); + LcdBuffer_Write(&lcd, 2, 0, "█████████▌"); + LcdBuffer_Write(&lcd, 3, 0, "🅳 Přerušit"); + break; + + case GUI_EVENT_KEY_D: + switch_screen(screen_home, true); + return; + } +} diff --git a/src/screens/screen_home.c b/src/screens/screen_home.c index 44e47cd..133f26c 100644 --- a/src/screens/screen_home.c +++ b/src/screens/screen_home.c @@ -37,14 +37,36 @@ void screen_home(GuiEvent event) } break; - case GUI_EVENT_PAINT:; + case GUI_EVENT_PAINT: LcdBuffer_Write(&lcd, 0, 0, showbuf); - sprintf(stmp, "Čas: %02d:%02d:%02d", rtc_time.hour, rtc_time.minute, rtc_time.second); - LcdBuffer_Write(&lcd, 1, 0, stmp); + uint32_t moisture_pt = ((uint32_t)(moisture > 2800 ? 0 : (2800 - moisture)) * 100) / (2800 - 1600); - sprintf(stmp, "Vlhkost: %4d", moisture); - LcdBuffer_Write(&lcd, 2, 0, stmp); + sprintf(stmp, " %2d:%02d:%02d %3d%% 🌢 ", rtc_time.hour, rtc_time.minute, rtc_time.second, moisture_pt); + LcdBuffer_Write(&lcd, 0, 0, stmp); + + LcdBuffer_Write(&lcd, 1, 0, "Plán. závlaha 7:15"); + LcdBuffer_Write(&lcd, 2, 0, "❶Spustit ❷Přeskočit"); + LcdBuffer_Write(&lcd, 3, 0, "🅰Nastavení"); + +// LcdBuffer_Write(&lcd, 1, 0, "❶ Spustit cyklus"); +// LcdBuffer_Write(&lcd, 2, 0, "❷ Ruční řízení"); +// LcdBuffer_Write(&lcd, 3, 0, "🅰 Nastavení"); + +// LcdBuffer_Write(&lcd, 1, 0, "🅰Program 🅱Poměry"); +// LcdBuffer_Write(&lcd, 2, 0, "🅲Vlhkoměr 🅳Čas"); + break; + + case GUI_EVENT_KEY_1: + switch_screen(screen_cyklus, true); + break; + + case GUI_EVENT_KEY_2: + // TODO + break; + + case GUI_EVENT_KEY_A: + // TODO break; default: