|
|
|
@ -4,6 +4,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stddef.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include "app_gui.h" |
|
|
|
|
#include "app_heater.h" |
|
|
|
|
#include "screen_menu.h" |
|
|
|
@ -12,6 +13,28 @@ |
|
|
|
|
#include "snprintf.h" |
|
|
|
|
#include "FreeRTOS.h" |
|
|
|
|
|
|
|
|
|
struct calib_state { |
|
|
|
|
int phase; |
|
|
|
|
float sample1; |
|
|
|
|
float sample2; |
|
|
|
|
int temp1; |
|
|
|
|
int temp2; |
|
|
|
|
} s_calib; |
|
|
|
|
|
|
|
|
|
enum Phase { |
|
|
|
|
PH_HELLO = 0, |
|
|
|
|
PH_SAMPLE1, |
|
|
|
|
PH_TEMP1, |
|
|
|
|
PH_SAMPLE2, |
|
|
|
|
PH_TEMP2, |
|
|
|
|
PH_DONE, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static void next_phase() { |
|
|
|
|
PUTS("Phase++\r\n"); |
|
|
|
|
s_calib.phase++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static const char* calib0_opts[] = { |
|
|
|
|
"Pokračovat", |
|
|
|
|
"Zrušit", |
|
|
|
@ -22,7 +45,7 @@ static void calib0_cb(int opt) { |
|
|
|
|
switch (opt) { |
|
|
|
|
case 0: |
|
|
|
|
// Continue
|
|
|
|
|
s_app.calib.phase++; |
|
|
|
|
next_phase(); |
|
|
|
|
request_paint(); |
|
|
|
|
app_heater_manual_override(100); |
|
|
|
|
break; |
|
|
|
@ -41,13 +64,15 @@ static const char* calib1_opts[] = { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void calib1_cb(int opt) { |
|
|
|
|
switch (opt) { |
|
|
|
|
case 0: |
|
|
|
|
// Continue
|
|
|
|
|
s_app.calib.phase++; |
|
|
|
|
next_phase(); |
|
|
|
|
request_paint(); |
|
|
|
|
s_app.calib.sample1 = app_temp_read_oven_raw(); |
|
|
|
|
s_calib.sample1 = app_temp_read_oven_raw(); |
|
|
|
|
app_heater_manual_override(0); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
@ -69,9 +94,9 @@ static void calib3_cb(int opt) { |
|
|
|
|
switch (opt) { |
|
|
|
|
case 0: |
|
|
|
|
// Continue
|
|
|
|
|
s_app.calib.phase++; |
|
|
|
|
next_phase(); |
|
|
|
|
request_paint(); |
|
|
|
|
s_app.calib.sample2 = app_temp_read_oven_raw(); |
|
|
|
|
s_calib.sample2 = app_temp_read_oven_raw(); |
|
|
|
|
app_heater_manual_override(0); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
@ -82,54 +107,41 @@ static void calib3_cb(int opt) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void screen_manual_menu(GuiEvent event) |
|
|
|
|
void screen_calibration(GuiEvent event) |
|
|
|
|
{ |
|
|
|
|
if (event == GUI_EVENT_SCREEN_INIT) { |
|
|
|
|
s_app.calib.phase = 0; |
|
|
|
|
s_app.calib.sample1 = s_app.calib.sample2 = 0.0f; |
|
|
|
|
s_app.calib.temp1 = s_app.calib.temp2 = 0; |
|
|
|
|
memset(&s_calib, 0, sizeof(s_calib)); |
|
|
|
|
// continue to the rest - so the menu can be inited
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int phase = s_app.calib.phase; |
|
|
|
|
int *pT; |
|
|
|
|
switch (phase) { |
|
|
|
|
case 0: |
|
|
|
|
switch (s_calib.phase) { |
|
|
|
|
case PH_HELLO: |
|
|
|
|
if (event == GUI_EVENT_PAINT) { |
|
|
|
|
fb_text(FBW/2, 14, "Vychlaďte", TEXT_CENTER, 1); |
|
|
|
|
fb_text(FBW/2, 14, "Vychlaď", TEXT_CENTER, 1); |
|
|
|
|
fb_text(FBW/2, 24, "troubu", TEXT_CENTER, 1); |
|
|
|
|
} |
|
|
|
|
screen_menu(event, calib1_opts, calib1_cb); |
|
|
|
|
screen_menu(event, calib0_opts, calib0_cb); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 1: // Heater is active, waiting for mark
|
|
|
|
|
case 3: |
|
|
|
|
case PH_SAMPLE1: // Heater is active, waiting for mark
|
|
|
|
|
case PH_SAMPLE2: |
|
|
|
|
if (event == GUI_EVENT_PAINT) { |
|
|
|
|
fb_text(FBW/2, 14, "Zapiš teplotu", TEXT_CENTER, 1); |
|
|
|
|
} |
|
|
|
|
if (phase == 1) { |
|
|
|
|
if (s_calib.phase == PH_SAMPLE1) { |
|
|
|
|
screen_menu(event, calib1_opts, calib1_cb); |
|
|
|
|
} else { |
|
|
|
|
screen_menu(event, calib3_opts, calib3_cb); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 2: |
|
|
|
|
case 4: |
|
|
|
|
if (phase == 2) { |
|
|
|
|
pT = &s_app.calib.temp1; |
|
|
|
|
case PH_TEMP1: |
|
|
|
|
case PH_TEMP2: |
|
|
|
|
if (s_calib.phase == PH_TEMP1) { |
|
|
|
|
pT = &s_calib.temp1; |
|
|
|
|
} else { |
|
|
|
|
pT = &s_app.calib.temp2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (event == GUI_EVENT_PAINT) { |
|
|
|
|
fb_text(FBW/2, 14, phase == 2 ? "Teplota 1" : "Teplota 2", TEXT_CENTER, 1); |
|
|
|
|
SPRINTF(stmp, "%d°C", *pT); |
|
|
|
|
fb_text(FBW/2, 30, stmp, TEXT_CENTER | FONT_DOUBLE, 1); |
|
|
|
|
|
|
|
|
|
fb_text(2, FBH - 8 * 3, "←→Nastav", 0, 1); |
|
|
|
|
fb_text(2, FBH - 8 * 2, "> Potvrdit", 0, 1); |
|
|
|
|
fb_text(2, FBH - 8 * 1, "» Zrušit", 0, 1); |
|
|
|
|
return; |
|
|
|
|
pT = &s_calib.temp2; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (push_time() > pdMS_TO_TICKS(500)) { |
|
|
|
@ -139,40 +151,62 @@ void screen_manual_menu(GuiEvent event) |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (event == GUI_EVENT_KNOB_PLUS) { |
|
|
|
|
if (*pT < 500) { |
|
|
|
|
*pT += 1; |
|
|
|
|
input_sound_effect(); |
|
|
|
|
request_paint(); |
|
|
|
|
switch (event) { |
|
|
|
|
case GUI_EVENT_PAINT: { |
|
|
|
|
fb_text(FBW/2, 14, s_calib.phase == PH_TEMP1 ? "Teplota 1" : "Teplota 2", TEXT_CENTER, 1); |
|
|
|
|
SPRINTF(stmp, "%d°C", *pT); |
|
|
|
|
fb_text(FBW/2, 30, stmp, TEXT_CENTER | FONT_DOUBLE, 1); |
|
|
|
|
|
|
|
|
|
fb_text(2, FBH - 8 * 3, "←→Nastav", 0, 1); |
|
|
|
|
fb_text(2, FBH - 8 * 2, "> Potvrdit", 0, 1); |
|
|
|
|
fb_text(2, FBH - 8 * 1, "» Zrušit", 0, 1); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (event == GUI_EVENT_KNOB_MINUS) { |
|
|
|
|
if (*pT > 0) { |
|
|
|
|
input_sound_effect(); |
|
|
|
|
*pT -= 1; |
|
|
|
|
request_paint(); |
|
|
|
|
|
|
|
|
|
case GUI_EVENT_KNOB_PLUS: { |
|
|
|
|
if (*pT < 500) { |
|
|
|
|
*pT += 1; |
|
|
|
|
input_sound_effect(); |
|
|
|
|
request_paint(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} else if (event == GUI_EVENT_KNOB_RELEASE) { |
|
|
|
|
s_app.calib.phase++; |
|
|
|
|
request_paint(); |
|
|
|
|
|
|
|
|
|
if (s_app.calib.phase == 5) { |
|
|
|
|
// TODO do the math
|
|
|
|
|
PRINTF("Sample 1 %f, T1 %d\r\n", s_app.calib.sample1, s_app.calib.temp1); |
|
|
|
|
PRINTF("Sample 2 %f, T2 %d\r\n", s_app.calib.sample2, s_app.calib.temp2); |
|
|
|
|
case GUI_EVENT_KNOB_MINUS: { |
|
|
|
|
if (*pT > 0) { |
|
|
|
|
input_sound_effect(); |
|
|
|
|
*pT -= 1; |
|
|
|
|
request_paint(); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case GUI_EVENT_KNOB_RELEASE: { |
|
|
|
|
next_phase(); |
|
|
|
|
request_paint(); |
|
|
|
|
|
|
|
|
|
float corrected1 = c_to_val((float) s_app.calib.temp1); |
|
|
|
|
float corrected2 = c_to_val((float) s_app.calib.temp2); |
|
|
|
|
if (s_calib.phase == PH_DONE) { |
|
|
|
|
app_heater_manual_override(-1); |
|
|
|
|
// TODO do the math
|
|
|
|
|
PRINTF("Sample 1 %f, T1 %d\r\n", s_calib.sample1, s_calib.temp1); |
|
|
|
|
PRINTF("Sample 2 %f, T2 %d\r\n", s_calib.sample2, s_calib.temp2); |
|
|
|
|
|
|
|
|
|
float a = ; |
|
|
|
|
float b = ; |
|
|
|
|
float corrected1 = c_to_val((float) s_calib.temp1); |
|
|
|
|
float corrected2 = c_to_val((float) s_calib.temp2); |
|
|
|
|
|
|
|
|
|
// TODO set and persist calibration
|
|
|
|
|
float a = (corrected1 - corrected2) / (s_calib.sample1 - s_calib.sample2); |
|
|
|
|
float b = corrected1 - a * s_calib.sample1; |
|
|
|
|
|
|
|
|
|
app_temp_set_calib(a, b); |
|
|
|
|
} else { |
|
|
|
|
app_heater_manual_override(100); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 5: |
|
|
|
|
case PH_DONE: |
|
|
|
|
if (event == GUI_EVENT_PAINT) { |
|
|
|
|
fb_text(FBW/2, 14, "Hotovo", TEXT_CENTER, 1); |
|
|
|
|
fb_text(FBW/2, 36, "→Hlavní menu", TEXT_CENTER, 1); |
|
|
|
@ -182,5 +216,4 @@ void screen_manual_menu(GuiEvent event) |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|