ui to set moisture threshold

master
Ondřej Hruška 2 years 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_cyklus.c
src/screens/screen_set_time.c
src/screens/screen_set_moisture_threshold.c
src/app_io.c
src/app_config.c)

@ -49,8 +49,10 @@ void request_paint();
void screen_home(GuiEvent event);
void screen_cyklus(GuiEvent event);
extern struct AppConfig settings_scratch;
void screen_settings(GuiEvent event);
void screen_set_time(GuiEvent event);
void screen_set_moisture_threshold(GuiEvent event);
// XXX other prototypes
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);
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;
case GUI_EVENT_KEY_A: // Confirm
rtc_set_time(&time);
switch_screen(screen_settings, false);
if (cursor == 4) {
rtc_set_time(&time);
switch_screen(screen_settings, false);
}
break;
case GUI_EVENT_KEY_D: // CANCEL

@ -17,7 +17,7 @@ static int page = 1;
#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
* (char still held by a line later overwritten) */
@ -29,13 +29,13 @@ void screen_settings(GuiEvent event)
switch (event) {
case GUI_EVENT_SCREEN_INIT:
page = 1;
memcpy(&scratch, &app_config, APPCONFIG_SIZE);
memcpy(&settings_scratch, &app_config, APPCONFIG_SIZE);
break;
case GUI_EVENT_PAINT:
switch (page) {
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, 1, 0, "2. Upravit program");
LcdBuffer_Write(&lcd, 2, 0, "3. Nastavit čas");
@ -47,14 +47,15 @@ void screen_settings(GuiEvent event)
break;
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, 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;
}
snprintf(buf, 100, "⊛←%d/%d→¤ 🅰Ulož 🅳Zruš", page, PAGECOUNT);
snprintf(buf, 100, "⊛←%d/%d→¤ 🅳Zruš 🅰Ulož", page, PAGECOUNT);
LcdBuffer_Write(&lcd, 3, 0, buf);
break;
@ -77,7 +78,7 @@ void screen_settings(GuiEvent event)
break;
case GUI_EVENT_KEY_A: // SAVE
memcpy(&app_config, &scratch, APPCONFIG_SIZE);
memcpy(&app_config, &settings_scratch, APPCONFIG_SIZE);
appconfig_save();
switch_screen(screen_home, true);
break;
@ -91,7 +92,7 @@ void screen_settings(GuiEvent event)
case 1:
switch (event) {
case GUI_EVENT_KEY_1: // Program Zap/VYP
scratch.scheduler_enable ^= 1;
settings_scratch.scheduler_enable ^= 1;
request_paint();
break;
@ -119,7 +120,7 @@ void screen_settings(GuiEvent event)
case 3:
switch (event) {
case GUI_EVENT_KEY_1: // Blokace vlhkosti Zap/VYP
scratch.moisture_enable ^= 1;
settings_scratch.moisture_enable ^= 1;
request_paint();
break;
@ -128,7 +129,7 @@ void screen_settings(GuiEvent event)
break;
case GUI_EVENT_KEY_3: // Nastavit prah
// TODO
switch_screen(screen_set_moisture_threshold, true);
break;
}
break;

Loading…
Cancel
Save