program editor
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
+3
-3
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#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"
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user