diff --git a/Core/Src/Gui/app_gui.c b/Core/Src/Gui/app_gui.c index 0d29f05..ba7c188 100644 --- a/Core/Src/Gui/app_gui.c +++ b/Core/Src/Gui/app_gui.c @@ -13,6 +13,7 @@ #include "ufb/framebuffer.h" #include "ufb/fb_text.h" #include "app_safety.h" +#include "app_heater.h" struct State s_app = {}; @@ -134,10 +135,10 @@ void switch_screen(screen_t pScreen, bool init) { /** Draw GUI common to all screens */ static void draw_common_overlay() { - SPRINTF(stmp, "%5.1f°C →%3d°C", s_app.oven_temp, s_app.set_temp); + SPRINTF(stmp, "%5.1f°C →%3d°C", app_temp_read_oven(), (int) app_heater_get_target()); fb_text(3, 3, stmp, FONT_3X5, 1); - if (s_app.heater_enabled) { + if (app_heater_get_state()) { fb_frame(0, 0, FBW, 11, 1, 1); } } diff --git a/Core/Src/Gui/screen_calibration.c b/Core/Src/Gui/screen_calibration.c index 71a4be1..a17a17c 100644 --- a/Core/Src/Gui/screen_calibration.c +++ b/Core/Src/Gui/screen_calibration.c @@ -30,6 +30,17 @@ enum Phase { PH_DONE, }; +static void stop_heater() { + app_heater_set_target(0); + app_heater_enable(false); +} + +static void calib_abort() { + app_temp_restore_calib(); + stop_heater(); + switch_screen(screen_home, true); +} + static void next_phase() { PUTS("Phase++\r\n"); s_calib.phase++; @@ -47,11 +58,12 @@ static void hello_menu_cb(int opt) { // Continue next_phase(); request_paint(); - app_heater_manual_override(100); + app_heater_set_target(100); + app_heater_enable(true); break; case 1: - switch_screen(screen_home, true); + calib_abort(); break; } } @@ -70,12 +82,11 @@ static void sample1_menu_cb(int opt) { next_phase(); request_paint(); s_calib.sample1 = app_temp_read_oven_raw(); - app_heater_manual_override(0); + app_heater_enable(false); break; case 1: - app_heater_manual_override(-1); - switch_screen(screen_home, true); + calib_abort(); break; } } @@ -94,12 +105,11 @@ static void sample2_menu_cb(int opt) { next_phase(); request_paint(); s_calib.sample2 = app_temp_read_oven_raw(); - app_heater_manual_override(0); + app_heater_enable(false); break; case 1: - app_heater_manual_override(-1); - switch_screen(screen_home, true); + calib_abort(); break; } } @@ -107,6 +117,8 @@ static void sample2_menu_cb(int opt) { void screen_calibration(GuiEvent event) { if (event == GUI_EVENT_SCREEN_INIT) { + app_temp_backup_calib(); + app_temp_set_calib_temporary(1, 0); memset(&s_calib, 0, sizeof(s_calib)); // continue to the rest - so the menu can be inited } @@ -121,17 +133,20 @@ void screen_calibration(GuiEvent event) screen_menu_offset(event, hello_menu_opts, hello_menu_cb, 30); break; - case PH_SAMPLE1: // Heater is active, waiting for mark - case PH_SAMPLE2: + case PH_SAMPLE1: if (event == GUI_EVENT_PAINT) { - fb_text(FBW/2, 16, "Zapiš", TEXT_CENTER, 1); - fb_text(FBW/2, 26, "teplotu", TEXT_CENTER, 1); + fb_text(FBW/2, 16, "Vyčkej", TEXT_CENTER, 1); + fb_text(FBW/2, 26, "ustálení", TEXT_CENTER, 1); } - if (s_calib.phase == PH_SAMPLE1) { - screen_menu_offset(event, sample1_menu_opts, sample1_menu_cb, 30); - } else { - screen_menu_offset(event, sample2_menu_opts, sample2_menu_cb, 30); + screen_menu_offset(event, sample1_menu_opts, sample1_menu_cb, 30); + break; + + case PH_SAMPLE2: + if (event == GUI_EVENT_PAINT) { + fb_text(FBW/2, 16, "Vyčkej", TEXT_CENTER, 1); + fb_text(FBW/2, 26, "ustálení", TEXT_CENTER, 1); } + screen_menu_offset(event, sample2_menu_opts, sample2_menu_cb, 30); break; case PH_TEMP1: @@ -144,8 +159,7 @@ void screen_calibration(GuiEvent event) if (push_time() > pdMS_TO_TICKS(500)) { input_sound_effect(); - app_heater_manual_override_clear(); - switch_screen(screen_home, true); + calib_abort(); return; } @@ -184,7 +198,9 @@ void screen_calibration(GuiEvent event) request_paint(); if (s_calib.phase == PH_DONE) { - app_heater_manual_override(-1); + app_heater_set_target(0); + app_heater_enable(false); + // 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); @@ -195,10 +211,13 @@ void screen_calibration(GuiEvent event) float a = (corrected1 - corrected2) / (s_calib.sample1 - s_calib.sample2); float b = corrected1 - a * s_calib.sample1; - app_temp_set_calib(a, b); - } else { - // for the next phase - app_heater_manual_override(100); + app_temp_set_persistent_calib(a, b); + } else if (s_calib.phase == PH_SAMPLE1) { + app_heater_set_target(100); + app_heater_enable(true); + } else if (s_calib.phase == PH_SAMPLE2) { + app_heater_set_target(200); + app_heater_enable(true); } break; } @@ -211,6 +230,7 @@ void screen_calibration(GuiEvent event) fb_text(FBW/2, 36, "→Hlavní menu", TEXT_CENTER, 1); } if (event == GUI_EVENT_KNOB_RELEASE) { + stop_heater(); switch_screen(screen_home, 1); } break; diff --git a/Core/Src/app_heater.c b/Core/Src/app_heater.c index 64b81a3..1e8ed5d 100644 --- a/Core/Src/app_heater.c +++ b/Core/Src/app_heater.c @@ -98,6 +98,14 @@ void app_heater_set_target(float target) { heaterExitCritical(); } +bool app_heater_get_state() { + return state.pid.ctlMode == PID_AUTOMATIC; +} + +float app_heater_get_target() { + return state.pid.Setpoint; +} + // emergency shutdown, this must not block use RTOS since it can be called from fault handlers or interrupt void app_heater_emergency_shutdown() { // Stop pwm diff --git a/Core/Src/app_heater.h b/Core/Src/app_heater.h index edcc9ba..5b912a1 100644 --- a/Core/Src/app_heater.h +++ b/Core/Src/app_heater.h @@ -36,4 +36,9 @@ void app_heater_set_target(float target); /// Shutdown the heater; This function does not use mutex and just disables the PWM via register access. void app_heater_emergency_shutdown(); + +bool app_heater_get_state(); + +float app_heater_get_target(); + #endif //BLUEPILLTROUBA_APP_HEATER_H diff --git a/Core/Src/app_temp.c b/Core/Src/app_temp.c index 1d57aa2..62336ee 100644 --- a/Core/Src/app_temp.c +++ b/Core/Src/app_temp.c @@ -30,6 +30,8 @@ static struct App { float soc_temp; float cal_a; float cal_b; + float saved_cal_a; + float saved_cal_b; float oventemp_history[OVENTEMP_HISTORY_DEPTH]; // raw temp uint16_t adc_averagebuf[AVERAGEBUF_DEPTH * 4]; uint8_t averagebuf_ptr; @@ -158,7 +160,7 @@ static void correct_invalid_calib() { } /// Set and persist calibration constants -void app_temp_set_calib(float a, float b) { +void app_temp_set_persistent_calib(float a, float b) { s_analog.cal_a = a; s_analog.cal_b = b; correct_invalid_calib(); @@ -177,6 +179,21 @@ void app_temp_set_calib(float a, float b) { } } +void app_temp_backup_calib() { + s_analog.saved_cal_a = s_analog.cal_a; + s_analog.saved_cal_b = s_analog.cal_b; +} + +void app_temp_set_calib_temporary(float a, float b) { + s_analog.cal_a = a; + s_analog.cal_b = b; +} + +void app_temp_restore_calib() { + s_analog.cal_a = s_analog.saved_cal_a; + s_analog.cal_b = s_analog.saved_cal_b; +} + void app_analog_init() { // read calibration constants diff --git a/Core/Src/app_temp.h b/Core/Src/app_temp.h index 85425ee..a11554d 100644 --- a/Core/Src/app_temp.h +++ b/Core/Src/app_temp.h @@ -10,7 +10,13 @@ void app_analog_init(); float val_to_c(float val); float c_to_val(float c); -void app_temp_set_calib(float a, float b); +void app_temp_set_persistent_calib(float a, float b); + +void app_temp_backup_calib(); + +void app_temp_set_calib_temporary(float a, float b); + +void app_temp_restore_calib(); /** * Update temperature measurement. diff --git a/Lib/ufb/Src/font_57.inc.c b/Lib/ufb/Src/font_57.inc.c index 47cde97..b9b43b3 100644 --- a/Lib/ufb/Src/font_57.inc.c +++ b/Lib/ufb/Src/font_57.inc.c @@ -106,5 +106,6 @@ static const struct utf_glyph5x PROGMEM font57_extra[] = { {.utf={.symbol="í"}, {{0x00, 0x44, 0x7d, 0x41, 0x00}}}, {.utf={.symbol="ž"}, {{0x44, 0x65, 0x56, 0x4d, 0x44}}}, {.utf={.symbol="ď"}, {{0x38, 0x44, 0x45, 0x48, 0x7f}}}, + {.utf={.symbol="á"}, {{0x20, 0x54, 0x54, 0x55, 0x79}}}, {.utf={.symbol="»"}, {{0x22, 0x14, 0x2a, 0x14, 0x08}}}, }; diff --git a/Lib/ufb/Src/fontedit_57.c b/Lib/ufb/Src/fontedit_57.c index 1545880..8262322 100644 --- a/Lib/ufb/Src/fontedit_57.c +++ b/Lib/ufb/Src/fontedit_57.c @@ -935,6 +935,14 @@ const char *font_extras[] = { "# #", "# #", " ####", + // 97 "a" + " xx", + " ", + " ### ", + " #", + " ####", + "# #", + " ####", // » " ", "x x ", @@ -967,6 +975,7 @@ const char *font_extras_utf[] = { "í", "ž", "ď", + "á", "»", };