ui to set moisture threshold

master
Ondřej Hruška 1 year ago
parent 26cbbd6f9b
commit f1d32b2835
  1. 1
      CMakeLists.txt
  2. 2
      src/screens/app_gui.h
  3. 60
      src/screens/screen_set_moisture_threshold.c
  4. 8
      src/screens/screen_set_time.c
  5. 21
      src/screens/screen_settings.c

@ -25,6 +25,7 @@ add_executable(zavlaha
src/screens/screen_settings.c src/screens/screen_settings.c
src/screens/screen_cyklus.c src/screens/screen_cyklus.c
src/screens/screen_set_time.c src/screens/screen_set_time.c
src/screens/screen_set_moisture_threshold.c
src/app_io.c src/app_io.c
src/app_config.c) src/app_config.c)

@ -49,8 +49,10 @@ void request_paint();
void screen_home(GuiEvent event); void screen_home(GuiEvent event);
void screen_cyklus(GuiEvent event); void screen_cyklus(GuiEvent event);
extern struct AppConfig settings_scratch;
void screen_settings(GuiEvent event); void screen_settings(GuiEvent event);
void screen_set_time(GuiEvent event); void screen_set_time(GuiEvent event);
void screen_set_moisture_threshold(GuiEvent event);
// XXX other prototypes // XXX other prototypes
struct State { struct State {

@ -0,0 +1,60 @@
#include <stdio.h>
#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();
}
}
}
}

@ -28,12 +28,14 @@ void screen_set_time(GuiEvent event)
snprintf(buf, 100, "%02d:%02d", time.hour, time.minute); snprintf(buf, 100, "%02d:%02d", time.hour, time.minute);
LcdBuffer_Write(&lcd, 1, 0, buf); LcdBuffer_Write(&lcd, 1, 0, buf);
LcdBuffer_Write(&lcd, 3, 0, "🅰Uložit 🅳Zrušit"); LcdBuffer_Write(&lcd, 3, 0, cursor < 4 ? "🅳Zrušit" : "🅳Zrušit 🅰Uložit");
break; break;
case GUI_EVENT_KEY_A: // Confirm case GUI_EVENT_KEY_A: // Confirm
rtc_set_time(&time); if (cursor == 4) {
switch_screen(screen_settings, false); rtc_set_time(&time);
switch_screen(screen_settings, false);
}
break; break;
case GUI_EVENT_KEY_D: // CANCEL case GUI_EVENT_KEY_D: // CANCEL

@ -17,7 +17,7 @@ static int page = 1;
#define PAGECOUNT 3 #define PAGECOUNT 3
static struct AppConfig scratch; struct AppConfig settings_scratch;
/** Clear the top 3 lines in the LCD - this fixes some problems with utf8 allocations /** Clear the top 3 lines in the LCD - this fixes some problems with utf8 allocations
* (char still held by a line later overwritten) */ * (char still held by a line later overwritten) */
@ -29,13 +29,13 @@ void screen_settings(GuiEvent event)
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
page = 1; page = 1;
memcpy(&scratch, &app_config, APPCONFIG_SIZE); memcpy(&settings_scratch, &app_config, APPCONFIG_SIZE);
break; break;
case GUI_EVENT_PAINT: case GUI_EVENT_PAINT:
switch (page) { switch (page) {
case 1: case 1:
snprintf(buf, 100, "1. Program=%s", scratch.scheduler_enable ? "ZAP" : "VYP"); snprintf(buf, 100, "1. Program=%s", settings_scratch.scheduler_enable ? "ZAP" : "VYP");
LcdBuffer_Write(&lcd, 0, 0, buf); LcdBuffer_Write(&lcd, 0, 0, buf);
LcdBuffer_Write(&lcd, 1, 0, "2. Upravit program"); LcdBuffer_Write(&lcd, 1, 0, "2. Upravit program");
LcdBuffer_Write(&lcd, 2, 0, "3. Nastavit čas"); LcdBuffer_Write(&lcd, 2, 0, "3. Nastavit čas");
@ -47,14 +47,15 @@ void screen_settings(GuiEvent event)
break; break;
case 3: case 3:
snprintf(buf, 100, "1. Blok.vlhkostí=%s", scratch.moisture_enable ? "ZAP" : "VYP"); snprintf(buf, 100, "1. Blok.vlhkostí=%s", settings_scratch.moisture_enable ? "ZAP" : "VYP");
LcdBuffer_Write(&lcd, 0, 0, buf); LcdBuffer_Write(&lcd, 0, 0, buf);
LcdBuffer_Write(&lcd, 1, 0, "2. Kalibrace vlhkom."); LcdBuffer_Write(&lcd, 1, 0, "2. Kalibrace vlhkom.");
LcdBuffer_Write(&lcd, 2, 0, "3. Nastavit práh"); snprintf(buf, 100, "3. Práh vlh.=%d%%", settings_scratch.moisture_threshold_percent);
LcdBuffer_Write(&lcd, 2, 0, buf);
break; break;
} }
snprintf(buf, 100, "⊛←%d/%d→¤ 🅰Ulož 🅳Zruš", page, PAGECOUNT); snprintf(buf, 100, "⊛←%d/%d→¤ 🅳Zruš 🅰Ulož", page, PAGECOUNT);
LcdBuffer_Write(&lcd, 3, 0, buf); LcdBuffer_Write(&lcd, 3, 0, buf);
break; break;
@ -77,7 +78,7 @@ void screen_settings(GuiEvent event)
break; break;
case GUI_EVENT_KEY_A: // SAVE case GUI_EVENT_KEY_A: // SAVE
memcpy(&app_config, &scratch, APPCONFIG_SIZE); memcpy(&app_config, &settings_scratch, APPCONFIG_SIZE);
appconfig_save(); appconfig_save();
switch_screen(screen_home, true); switch_screen(screen_home, true);
break; break;
@ -91,7 +92,7 @@ void screen_settings(GuiEvent event)
case 1: case 1:
switch (event) { switch (event) {
case GUI_EVENT_KEY_1: // Program Zap/VYP case GUI_EVENT_KEY_1: // Program Zap/VYP
scratch.scheduler_enable ^= 1; settings_scratch.scheduler_enable ^= 1;
request_paint(); request_paint();
break; break;
@ -119,7 +120,7 @@ void screen_settings(GuiEvent event)
case 3: case 3:
switch (event) { switch (event) {
case GUI_EVENT_KEY_1: // Blokace vlhkosti Zap/VYP case GUI_EVENT_KEY_1: // Blokace vlhkosti Zap/VYP
scratch.moisture_enable ^= 1; settings_scratch.moisture_enable ^= 1;
request_paint(); request_paint();
break; break;
@ -128,7 +129,7 @@ void screen_settings(GuiEvent event)
break; break;
case GUI_EVENT_KEY_3: // Nastavit prah case GUI_EVENT_KEY_3: // Nastavit prah
// TODO switch_screen(screen_set_moisture_threshold, true);
break; break;
} }
break; break;

Loading…
Cancel
Save