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

82 lines
2.2 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 "ds_rtc.h"
#include "app_io.h"
static uint32_t last_time = 0;
static struct rtc_time rtc_time = {};
static uint16_t moisture = 0;
static char showbuf[20];
static uint8_t showbuf_wp = 0;
void screen_home(GuiEvent event)
{
uint32_t now = timestamp();
uint32_t elapsed = now - last_time;
switch (event) {
case GUI_EVENT_SCREEN_INIT:
memset(showbuf, ' ', sizeof(showbuf));
// pass
case GUI_EVENT_SCREEN_TICK:
if (elapsed >= 100) {
last_time = now;
rtc_get_time(&rtc_time);
moisture = moisture_read();
request_paint();
}
break;
case GUI_EVENT_PAINT:
LcdBuffer_Write(&lcd, 0, 0, showbuf);
uint32_t moisture_pt = ((uint32_t)(moisture > 2800 ? 0 : (2800 - moisture)) * 100) / (2800 - 1600);
sprintf(stmp, " %2d:%02d:%02d %3d%% 🌢 ", rtc_time.hour, rtc_time.minute, rtc_time.second, moisture_pt);
LcdBuffer_Write(&lcd, 0, 0, stmp);
LcdBuffer_Write(&lcd, 1, 0, "Plán. závlaha 7:15");
LcdBuffer_Write(&lcd, 2, 0, "❶Spustit ❷Přeskočit");
LcdBuffer_Write(&lcd, 3, 0, "🅰Nastavení");
// LcdBuffer_Write(&lcd, 1, 0, "❶ Spustit cyklus");
// LcdBuffer_Write(&lcd, 2, 0, "❷ Ruční řízení");
// LcdBuffer_Write(&lcd, 3, 0, "🅰 Nastavení");
// LcdBuffer_Write(&lcd, 1, 0, "🅰Program 🅱Poměry");
// LcdBuffer_Write(&lcd, 2, 0, "🅲Vlhkoměr 🅳Čas");
break;
case GUI_EVENT_KEY_1:
switch_screen(screen_cyklus, true);
break;
case GUI_EVENT_KEY_2:
// TODO
break;
case GUI_EVENT_KEY_A:
// TODO
break;
default:
if (event >= 32) {
showbuf[showbuf_wp++] = event;
if (showbuf_wp == 20) {
showbuf_wp = 0;
}
request_paint();
}
}
}