You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
zavlaha-kzk/src/screens/screen_program_edit.c

100 lines
3.3 KiB

#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)
{
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(sbuf, sbuf_len, "Denní slot %d", 1 + pgm_edit_slot);
LcdBuffer_Write(&lcd, 0, 0, sbuf);
if (time.enable) {
LcdBuffer_SetCursor(&lcd, 1, cursor + (cursor >= 2), (cursor < 4) ? CURSOR_BOTH : CURSOR_NONE);
snprintf(sbuf, sbuf_len, "%02d:%02d", time.h, time.m);
LcdBuffer_Write(&lcd, 1, 0, sbuf);
} 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 (!time.enable) {
time.enable = true;
// make sure there is no old content
LcdBuffer_Clear(&lcd);
}
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();
}
}
}
}