fixes, add compensation screen & more

master
Ondřej Hruška 2 years ago
parent f9ffe8b366
commit 7e9d9aa9bc
  1. 2
      CMakeLists.txt
  2. 2
      src/app_config.h
  3. 2
      src/screens/app_gui.h
  4. 66
      src/screens/screen_delka_zalivky.c
  5. 80
      src/screens/screen_kompenzace_tlaku.c
  6. 9
      src/screens/screen_set_moisture_threshold.c
  7. 3
      src/screens/screen_settings.c

@ -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)

@ -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;

@ -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 {

@ -0,0 +1,66 @@
#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 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();
}
}
}
}

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

@ -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();

@ -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;

Loading…
Cancel
Save