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.
63 lines
1.8 KiB
63 lines
1.8 KiB
2 years ago
|
#include <stdio.h>
|
||
|
#include "app_gui.h"
|
||
|
#include "gui_event.h"
|
||
|
#include "app_io.h"
|
||
|
#include "app_config.h"
|
||
|
|
||
|
static int phase = 0;
|
||
|
static int tick_counter = 0;
|
||
|
static uint16_t last_moisture = 0;
|
||
|
|
||
|
static uint16_t sample_dry = 0;
|
||
|
|
||
|
void screen_moisture_calib(GuiEvent event)
|
||
|
{
|
||
|
char buf[100];
|
||
|
|
||
|
switch (event) {
|
||
|
case GUI_EVENT_SCREEN_INIT:
|
||
|
phase = 0;
|
||
|
tick_counter = 0;
|
||
|
// pass through
|
||
|
case GUI_EVENT_SCREEN_TICK_10MS:
|
||
|
tick_counter++;
|
||
|
if (tick_counter == 25) {
|
||
|
request_paint(); // will read new measurement
|
||
|
tick_counter = 0;
|
||
|
}
|
||
|
last_moisture = moisture_read();
|
||
|
break;
|
||
|
|
||
|
case GUI_EVENT_PAINT:
|
||
|
if (phase == 0) {
|
||
|
LcdBuffer_Write(&lcd, 0, 0, "Dej čidlo do vyschlé");
|
||
|
LcdBuffer_Write(&lcd, 1, 0, "půdy (vlhkost 0%)");
|
||
|
} else {
|
||
|
LcdBuffer_Write(&lcd, 0, 0, "Dej čidlo do mokré");
|
||
|
LcdBuffer_Write(&lcd, 1, 0, "půdy (vlhkost 100%)");
|
||
|
}
|
||
|
|
||
|
snprintf(buf, 100, "Vlhkost %4d/4095", last_moisture);
|
||
|
LcdBuffer_Write(&lcd, 2, 0, buf);
|
||
|
|
||
|
LcdBuffer_Write(&lcd, 3, 0, "🅳Zrušit 🅰Potvrdit");
|
||
|
break;
|
||
|
|
||
|
case GUI_EVENT_KEY_A: // Confirm
|
||
|
if (phase == 0) {
|
||
|
sample_dry = last_moisture;
|
||
|
phase++;
|
||
|
LcdBuffer_Clear(&lcd); // make sure there isnt overlap with previous step
|
||
|
} else {
|
||
|
settings_scratch.moisture_dry = sample_dry;
|
||
|
settings_scratch.moisture_wet = last_moisture;
|
||
|
switch_screen(screen_settings, false);
|
||
|
}
|
||
|
break;
|
||
|
|
||
|
case GUI_EVENT_KEY_D: // CANCEL
|
||
|
switch_screen(screen_settings, false);
|
||
|
break;
|
||
|
}
|
||
|
}
|