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