parent
7e9d9aa9bc
commit
dc27d8bc83
@ -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; |
||||
} |
||||
} |
Loading…
Reference in new issue