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_home.c

94 lines
2.8 KiB

/**
* TODO file description
*/
//
// Created by MightyPork on 2023/04/09.
//
#include <stdio.h>
#include <string.h>
#include "app_gui.h"
#include "gui_event.h"
#include "app_io.h"
#include "app_config.h"
void screen_home(GuiEvent event)
{
switch (event) {
case GUI_EVENT_SCREEN_INIT:
// pass
case GUI_EVENT_SCREEN_TICK_100MS:
if (app_config.moisture_enable) {
gui_read_moisture();
}
request_paint();
break;
case GUI_EVENT_PAINT:
if (app_config.moisture_enable) {
sprintf(sbuf, " %2d:%02d:%02d %3d%% 🌢%s",
s_app.rtc_time.hour,
s_app.rtc_time.minute,
s_app.rtc_time.second,
s_app.moisture_pt,
s_app.moisture_pt > app_config.moisture_threshold_percent ? "" : " "
);
} else {
sprintf(sbuf, " %2d:%02d:%02d",
s_app.rtc_time.hour,
s_app.rtc_time.minute,
s_app.rtc_time.second);
}
LcdBuffer_Write(&lcd, 0, 0, sbuf);
// Find the next due schedule
if (!app_config.scheduler_enable) {
LcdBuffer_Write(&lcd, 1, 0, "Čas. program vypnutý");
} else {
int found = -1;
int first = -1;
uint16_t m_now = s_app.rtc_time.hour * 60 + s_app.rtc_time.minute;
for (int i = 0; i < SCHEDULE_COUNT; i++) {
if (!app_config.schedules[i].enable) {
continue;
}
if (first == -1) {
first = i;
}
uint16_t m = app_config.schedules[i].h * 60 + app_config.schedules[i].m;
if (m >= m_now) {
found = i;
break;
}
}
if (found == -1) {
found = first;
}
if (found == -1) {
LcdBuffer_Write(&lcd, 1, 0, "Program nenastaven!");
} else {
snprintf(sbuf, sbuf_len, "Další závlaha %d:%02d ",
app_config.schedules[found].h, app_config.schedules[found].m);
LcdBuffer_Write(&lcd, 1, 0, sbuf);
}
}
LcdBuffer_Write(&lcd, 2, 0, "🅰Spustit cyklus");
LcdBuffer_Write(&lcd, 3, 0, "🅱Nastavení");
break;
case GUI_EVENT_KEY_A:
switch_screen(screen_cyklus, true); // fake cycle
break;
case GUI_EVENT_KEY_B:
switch_screen(screen_settings, true);
break;
}
}