master
Ondřej Hruška 1 year ago
parent dc27d8bc83
commit 9905033ca9
  1. 1
      src/app_io.h
  2. 2
      src/screens/app_gui.c
  3. 3
      src/screens/app_gui.h
  4. 66
      src/screens/screen_cyklus.c
  5. 10
      src/screens/screen_delka_zalivky.c
  6. 4
      src/screens/screen_home.c
  7. 10
      src/screens/screen_kompenzace_tlaku.c
  8. 6
      src/screens/screen_moisture_calib.c
  9. 10
      src/screens/screen_program_edit.c
  10. 22
      src/screens/screen_program_prehled.c
  11. 10
      src/screens/screen_set_moisture_threshold.c
  12. 6
      src/screens/screen_set_time.c
  13. 17
      src/screens/screen_settings.c

@ -10,6 +10,7 @@
void set_relays(bool one, bool two, bool three, bool four); void set_relays(bool one, bool two, bool three, bool four);
/** Open valve, 1,2,3,4; 0=close all */
void open_valve(uint8_t num); void open_valve(uint8_t num);
uint16_t moisture_read(); uint16_t moisture_read();

@ -20,7 +20,7 @@ void request_paint() {
/** Draw the common overlay / HUD (with temperatures and heater status) */ /** Draw the common overlay / HUD (with temperatures and heater status) */
static void draw_common_overlay(); static void draw_common_overlay();
char stmp[100]; char sbuf[100];
/** Main loop */ /** Main loop */
void gui_init() void gui_init()

@ -14,7 +14,8 @@
// 🌢🅰🅱🅲🅳❶❷❸❹⊛¤▌↑↓✔ // 🌢🅰🅱🅲🅳❶❷❸❹⊛¤▌↑↓✔
/// Temporary scratch buffer /// Temporary scratch buffer
extern char stmp[100]; extern char sbuf[100];
#define sbuf_len 100
extern struct LcdBuffer lcd; extern struct LcdBuffer lcd;

@ -6,33 +6,81 @@
// //
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "app_gui.h" #include "app_gui.h"
#include "gui_event.h" #include "gui_event.h"
#include "ds_rtc.h"
#include "app_io.h" #include "app_io.h"
#include "app_config.h"
#include "ds_rtc.h"
static int phase = 0;
static uint32_t phase_seconds = 0;
static uint32_t phase_seconds_max = 0;
// TODO static uint8_t last_secs = 0;
static struct rtc_time time;
static void end_cycle() {
open_valve(0);
}
static void start_branch() {
phase_seconds_max = ((uint32_t) app_config.circuit_base_time_s * (uint32_t) app_config.circuit_time_percent[phase]) / 100;
open_valve(phase + 1);
}
void screen_cyklus(GuiEvent event) void screen_cyklus(GuiEvent event)
{ {
uint32_t now = timestamp();
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
phase = 0;
phase_seconds = 0;
start_branch();
break;
case GUI_EVENT_SCREEN_TICK_10MS: case GUI_EVENT_SCREEN_TICK_10MS:
// last_secs = time.second;
rtc_get_time(&time);
if (time.second != last_secs) {
phase_seconds += 1;
if (phase_seconds >= phase_seconds_max) {
phase += 1;
if (phase >= CIRCUIT_COUNT) {
end_cycle();
switch_screen(screen_home, true);
return;
}
start_branch();
phase_seconds = 0;
}
request_paint();
}
break; break;
case GUI_EVENT_PAINT: case GUI_EVENT_PAINT:
LcdBuffer_Write(&lcd, 0, 0, "==ZÁVLAHOVÝ CYKLUS=="); LcdBuffer_Write(&lcd, 0, 0, "==ZÁVLAHOVÝ CYKLUS==");
LcdBuffer_Write(&lcd, 1, 0, "Okruh 2/4 30/200s");
LcdBuffer_Write(&lcd, 2, 0, "█████████▌"); snprintf(sbuf, sbuf_len, "Okruh %d/%d %3d/%d s ", phase + 1, 4, phase_seconds, phase_seconds_max);
LcdBuffer_Write(&lcd, 3, 0, "🅳 Přerušit"); LcdBuffer_Write(&lcd, 1, 0, sbuf);
uint32_t pieces = (phase_seconds * 40) / phase_seconds_max;
char *buf = sbuf;
for (int i = 0; i < 20; i++) {
if ((i*2 + 1) == pieces) {
buf += sprintf(buf, "");
} else if (i * 2 < pieces) {
buf += sprintf(buf, "");
} else {
buf += sprintf(buf, " ");
}
}
LcdBuffer_Write(&lcd, 2, 0, sbuf);
LcdBuffer_Write(&lcd, 3, 0, "🅳 Ukončit");
break; break;
case GUI_EVENT_KEY_D: case GUI_EVENT_KEY_D:
end_cycle();
switch_screen(screen_home, true); switch_screen(screen_home, true);
return; return;
} }

@ -11,8 +11,6 @@ static int cursor;
void screen_delka_zalivky(GuiEvent event) void screen_delka_zalivky(GuiEvent event)
{ {
char buf[100];
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
value = 0; value = 0;
@ -26,12 +24,12 @@ void screen_delka_zalivky(GuiEvent event)
LcdBuffer_SetCursor(&lcd, 2, cursor, CURSOR_BOTH); LcdBuffer_SetCursor(&lcd, 2, cursor, CURSOR_BOTH);
if (cursor > 0) { if (cursor > 0) {
snprintf(buf, 100, "%d s", value); snprintf(sbuf, sbuf_len, "%d s", value);
LcdBuffer_Write(&lcd, 2, 0, buf); LcdBuffer_Write(&lcd, 2, 0, sbuf);
} else { } else {
// show orig value // show orig value
snprintf(buf, 100, "%d s", settings_scratch.circuit_base_time_s); snprintf(sbuf, sbuf_len, "%d s", settings_scratch.circuit_base_time_s);
LcdBuffer_Write(&lcd, 2, 0, buf); LcdBuffer_Write(&lcd, 2, 0, sbuf);
} }
LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰OK"); LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰OK");

@ -39,8 +39,8 @@ void screen_home(GuiEvent event)
case GUI_EVENT_PAINT:; case GUI_EVENT_PAINT:;
// TODO // TODO
sprintf(stmp, " %2d:%02d:%02d %3d%% 🌢 ", rtc_time.hour, rtc_time.minute, rtc_time.second, moisture_pt); sprintf(sbuf, " %2d:%02d:%02d %3d%% 🌢 ", rtc_time.hour, rtc_time.minute, rtc_time.second, moisture_pt);
LcdBuffer_Write(&lcd, 0, 0, stmp); LcdBuffer_Write(&lcd, 0, 0, sbuf);
LcdBuffer_Write(&lcd, 1, 0, "Plán. závlaha 7:15"); LcdBuffer_Write(&lcd, 1, 0, "Plán. závlaha 7:15");
LcdBuffer_Write(&lcd, 2, 0, "❶Spustit ❷Přeskočit"); LcdBuffer_Write(&lcd, 2, 0, "❶Spustit ❷Přeskočit");

@ -12,8 +12,6 @@ static int cursor;
void screen_kompenzace_tlaku(GuiEvent event) void screen_kompenzace_tlaku(GuiEvent event)
{ {
char buf[100];
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
cursor = 0; cursor = 0;
@ -23,10 +21,10 @@ void screen_kompenzace_tlaku(GuiEvent event)
case GUI_EVENT_PAINT: case GUI_EVENT_PAINT:
LcdBuffer_Write(&lcd, 0, 0, "Relativní čas okruhů"); LcdBuffer_Write(&lcd, 0, 0, "Relativní čas okruhů");
snprintf(buf, 100, "1. %3d%% 3. %3d%%", ratios[0], ratios[2]); snprintf(sbuf, sbuf_len, "1. %3d%% 3. %3d%%", ratios[0], ratios[2]);
LcdBuffer_Write(&lcd, 1, 0, buf); LcdBuffer_Write(&lcd, 1, 0, sbuf);
snprintf(buf, 100, "2. %3d%% 4. %3d%%", ratios[1], ratios[3]); snprintf(sbuf, sbuf_len, "2. %3d%% 4. %3d%%", ratios[1], ratios[3]);
LcdBuffer_Write(&lcd, 2, 0, buf); LcdBuffer_Write(&lcd, 2, 0, sbuf);
switch (cursor) { switch (cursor) {
case 0: case 0:

@ -12,8 +12,6 @@ static uint16_t sample_dry = 0;
void screen_moisture_calib(GuiEvent event) void screen_moisture_calib(GuiEvent event)
{ {
char buf[100];
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
phase = 0; phase = 0;
@ -37,8 +35,8 @@ void screen_moisture_calib(GuiEvent event)
LcdBuffer_Write(&lcd, 1, 0, "půdy (vlhkost 100%)"); LcdBuffer_Write(&lcd, 1, 0, "půdy (vlhkost 100%)");
} }
snprintf(buf, 100, "Vlhkost %4d/4095", last_moisture); snprintf(sbuf, sbuf_len, "Vlhkost %4d/4095", last_moisture);
LcdBuffer_Write(&lcd, 2, 0, buf); LcdBuffer_Write(&lcd, 2, 0, sbuf);
LcdBuffer_Write(&lcd, 3, 0, "🅳Zrušit 🅰Potvrdit"); LcdBuffer_Write(&lcd, 3, 0, "🅳Zrušit 🅰Potvrdit");
break; break;

@ -13,8 +13,6 @@ int pgm_edit_slot; // set from the program overview screen
void screen_program_edit(GuiEvent event) void screen_program_edit(GuiEvent event)
{ {
char buf[100];
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
memcpy(&time, &settings_scratch.schedules[pgm_edit_slot], sizeof(time)); memcpy(&time, &settings_scratch.schedules[pgm_edit_slot], sizeof(time));
@ -22,13 +20,13 @@ void screen_program_edit(GuiEvent event)
break; break;
case GUI_EVENT_PAINT: case GUI_EVENT_PAINT:
snprintf(buf, 100, "Denní slot %d", 1 + pgm_edit_slot); snprintf(sbuf, sbuf_len, "Denní slot %d", 1 + pgm_edit_slot);
LcdBuffer_Write(&lcd, 0, 0, buf); LcdBuffer_Write(&lcd, 0, 0, sbuf);
if (time.enable) { if (time.enable) {
LcdBuffer_SetCursor(&lcd, 1, cursor + (cursor >= 2), (cursor < 4) ? CURSOR_BOTH : CURSOR_NONE); LcdBuffer_SetCursor(&lcd, 1, cursor + (cursor >= 2), (cursor < 4) ? CURSOR_BOTH : CURSOR_NONE);
snprintf(buf, 100, "%02d:%02d", time.h, time.m); snprintf(sbuf, sbuf_len, "%02d:%02d", time.h, time.m);
LcdBuffer_Write(&lcd, 1, 0, buf); LcdBuffer_Write(&lcd, 1, 0, sbuf);
} else { } else {
LcdBuffer_SetCursor(&lcd, 0, 0, CURSOR_NONE); LcdBuffer_SetCursor(&lcd, 0, 0, CURSOR_NONE);
LcdBuffer_Write(&lcd, 1, 0, "--:-- (slot vypnutý)"); LcdBuffer_Write(&lcd, 1, 0, "--:-- (slot vypnutý)");

@ -9,8 +9,6 @@
void screen_program_prehled(GuiEvent event) void screen_program_prehled(GuiEvent event)
{ {
char buf[100];
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
break; break;
@ -19,28 +17,28 @@ void screen_program_prehled(GuiEvent event)
LcdBuffer_Write(&lcd, 0, 0, "Zvolte slot ke změně"); LcdBuffer_Write(&lcd, 0, 0, "Zvolte slot ke změně");
if (settings_scratch.schedules[0].enable) { if (settings_scratch.schedules[0].enable) {
snprintf(buf, 100, "1. %02d:%02d ", settings_scratch.schedules[0].h, settings_scratch.schedules[0].m); snprintf(sbuf, sbuf_len, "1. %02d:%02d ", settings_scratch.schedules[0].h, settings_scratch.schedules[0].m);
} else { } else {
snprintf(buf, 100, "1. --:-- "); snprintf(sbuf, sbuf_len, "1. --:-- ");
} }
if (settings_scratch.schedules[2].enable) { if (settings_scratch.schedules[2].enable) {
snprintf(buf+10, 90, "3. %02d:%02d ", settings_scratch.schedules[2].h, settings_scratch.schedules[2].m); snprintf(sbuf+10, sbuf_len-10, "3. %02d:%02d ", settings_scratch.schedules[2].h, settings_scratch.schedules[2].m);
} else { } else {
snprintf(buf+10, 90, "3. --:-- "); snprintf(sbuf+10, sbuf_len-10, "3. --:-- ");
} }
LcdBuffer_Write(&lcd, 1, 0, buf); LcdBuffer_Write(&lcd, 1, 0, sbuf);
if (settings_scratch.schedules[1].enable) { if (settings_scratch.schedules[1].enable) {
snprintf(buf, 100, "2. %02d:%02d ", settings_scratch.schedules[1].h, settings_scratch.schedules[1].m); snprintf(sbuf, sbuf_len, "2. %02d:%02d ", settings_scratch.schedules[1].h, settings_scratch.schedules[1].m);
} else { } else {
snprintf(buf, 100, "2. --:-- "); snprintf(sbuf, sbuf_len, "2. --:-- ");
} }
if (settings_scratch.schedules[3].enable) { if (settings_scratch.schedules[3].enable) {
snprintf(buf+10, 90, "4. %02d:%02d ", settings_scratch.schedules[3].h, settings_scratch.schedules[3].m); snprintf(sbuf+10, sbuf_len-10, "4. %02d:%02d ", settings_scratch.schedules[3].h, settings_scratch.schedules[3].m);
} else { } else {
snprintf(buf+10, 90, "4. --:-- "); snprintf(sbuf+10, sbuf_len-10, "4. --:-- ");
} }
LcdBuffer_Write(&lcd, 2, 0, buf); LcdBuffer_Write(&lcd, 2, 0, sbuf);
LcdBuffer_Write(&lcd, 3, 0, "🅳Zpět"); LcdBuffer_Write(&lcd, 3, 0, "🅳Zpět");
break; break;

@ -11,8 +11,6 @@ static int cursor;
void screen_set_moisture_threshold(GuiEvent event) void screen_set_moisture_threshold(GuiEvent event)
{ {
char buf[100];
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
threshold = 0; threshold = 0;
@ -26,11 +24,11 @@ void screen_set_moisture_threshold(GuiEvent event)
LcdBuffer_SetCursor(&lcd, 2, cursor, (cursor < 3) ? CURSOR_BLINK : CURSOR_NONE); LcdBuffer_SetCursor(&lcd, 2, cursor, (cursor < 3) ? CURSOR_BLINK : CURSOR_NONE);
if (cursor > 0) { if (cursor > 0) {
snprintf(buf, 100, "%d %%", threshold); snprintf(sbuf, sbuf_len, "%d %%", threshold);
LcdBuffer_Write(&lcd, 2, 0, buf); LcdBuffer_Write(&lcd, 2, 0, sbuf);
} else { } else {
snprintf(buf, 100, "%d %%", settings_scratch.moisture_threshold_percent); snprintf(sbuf, sbuf_len, "%d %%", settings_scratch.moisture_threshold_percent);
LcdBuffer_Write(&lcd, 2, 0, buf); LcdBuffer_Write(&lcd, 2, 0, sbuf);
} }
LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰OK"); LcdBuffer_Write(&lcd, 3, 0, cursor == 0 ? "🅳Zrušit" : "🅳Zrušit 🅰OK");

@ -10,8 +10,6 @@ static int cursor;
void screen_set_time(GuiEvent event) void screen_set_time(GuiEvent event)
{ {
char buf[100];
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
rtc_get_time(&time); // so it's shown in the preview rtc_get_time(&time); // so it's shown in the preview
@ -26,8 +24,8 @@ void screen_set_time(GuiEvent event)
LcdBuffer_SetCursor(&lcd, 1, cursor + (cursor >= 2), (cursor < 4) ? CURSOR_BOTH : CURSOR_NONE); LcdBuffer_SetCursor(&lcd, 1, cursor + (cursor >= 2), (cursor < 4) ? CURSOR_BOTH : CURSOR_NONE);
snprintf(buf, 100, "%02d:%02d", time.hour, time.minute); snprintf(sbuf, sbuf_len, "%02d:%02d", time.hour, time.minute);
LcdBuffer_Write(&lcd, 1, 0, buf); LcdBuffer_Write(&lcd, 1, 0, sbuf);
LcdBuffer_Write(&lcd, 3, 0, cursor < 4 ? "🅳Zrušit" : "🅳Zrušit 🅰Nastavit"); LcdBuffer_Write(&lcd, 3, 0, cursor < 4 ? "🅳Zrušit" : "🅳Zrušit 🅰Nastavit");
break; break;

@ -25,7 +25,6 @@ static void clear_menu_lines();
void screen_settings(GuiEvent event) void screen_settings(GuiEvent event)
{ {
char buf[100];
switch (event) { switch (event) {
case GUI_EVENT_SCREEN_INIT: case GUI_EVENT_SCREEN_INIT:
page = 1; page = 1;
@ -35,8 +34,8 @@ void screen_settings(GuiEvent event)
case GUI_EVENT_PAINT: case GUI_EVENT_PAINT:
switch (page) { switch (page) {
case 1: case 1:
snprintf(buf, 100, "1. Program=%s", settings_scratch.scheduler_enable ? "ZAP" : "VYP"); snprintf(sbuf, sbuf_len, "1. Program=%s", settings_scratch.scheduler_enable ? "ZAP" : "VYP");
LcdBuffer_Write(&lcd, 0, 0, buf); LcdBuffer_Write(&lcd, 0, 0, sbuf);
LcdBuffer_Write(&lcd, 1, 0, "2. Upravit program"); LcdBuffer_Write(&lcd, 1, 0, "2. Upravit program");
LcdBuffer_Write(&lcd, 2, 0, "3. Nastavit čas"); LcdBuffer_Write(&lcd, 2, 0, "3. Nastavit čas");
break; break;
@ -47,16 +46,16 @@ void screen_settings(GuiEvent event)
break; break;
case 3: case 3:
snprintf(buf, 100, "1. Blok.vlhkostí=%s", settings_scratch.moisture_enable ? "ZAP" : "VYP"); snprintf(sbuf, sbuf_len, "1. Blok.vlhkostí=%s", settings_scratch.moisture_enable ? "ZAP" : "VYP");
LcdBuffer_Write(&lcd, 0, 0, buf); LcdBuffer_Write(&lcd, 0, 0, sbuf);
LcdBuffer_Write(&lcd, 1, 0, "2. Kalibrace vlhkom."); LcdBuffer_Write(&lcd, 1, 0, "2. Kalibrace vlhkom.");
snprintf(buf, 100, "3. Práh vlh.=%d%%", settings_scratch.moisture_threshold_percent); snprintf(sbuf, sbuf_len, "3. Práh vlh.=%d%%", settings_scratch.moisture_threshold_percent);
LcdBuffer_Write(&lcd, 2, 0, buf); LcdBuffer_Write(&lcd, 2, 0, sbuf);
break; break;
} }
snprintf(buf, 100, "⊛←%d/%d→¤ 🅳Zruš 🅰Ulož", page, PAGECOUNT); snprintf(sbuf, sbuf_len, "⊛←%d/%d→¤ 🅳Zruš 🅰Ulož", page, PAGECOUNT);
LcdBuffer_Write(&lcd, 3, 0, buf); LcdBuffer_Write(&lcd, 3, 0, sbuf);
break; break;
case GUI_EVENT_KEY_B: case GUI_EVENT_KEY_B:

Loading…
Cancel
Save