// // Created by MightyPork on 2023/04/09. // #include #include "app_gui.h" #include "app_heater.h" #include "screen_menu.h" #include "ufb/fb_text.h" #include "app_temp.h" #include "snprintf.h" #include "FreeRTOS.h" static const char* calib0_opts[] = { "Pokračovat", "Zrušit", NULL }; static void calib0_cb(int opt) { switch (opt) { case 0: // Continue s_app.calib.phase++; request_paint(); app_heater_manual_override(100); break; case 1: switch_screen(screen_home, true); break; } } static const char* calib1_opts[] = { "Vzorek 1", "Zrušit", NULL }; static void calib1_cb(int opt) { switch (opt) { case 0: // Continue s_app.calib.phase++; request_paint(); s_app.calib.sample1 = app_temp_read_oven_raw(); app_heater_manual_override(0); break; case 1: app_heater_manual_override(-1); switch_screen(screen_home, true); break; } } static const char* calib3_opts[] = { "Vzorek 2", "Zrušit", NULL }; static void calib3_cb(int opt) { switch (opt) { case 0: // Continue s_app.calib.phase++; request_paint(); s_app.calib.sample2 = app_temp_read_oven_raw(); app_heater_manual_override(0); break; case 1: app_heater_manual_override(-1); switch_screen(screen_home, true); break; } } void screen_manual_menu(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; } int phase = s_app.calib.phase; int *pT; switch (phase) { case 0: if (event == GUI_EVENT_PAINT) { fb_text(FBW/2, 14, "Vychlaďte", TEXT_CENTER, 1); fb_text(FBW/2, 24, "troubu", TEXT_CENTER, 1); } screen_menu(event, calib1_opts, calib1_cb); break; case 1: // Heater is active, waiting for mark case 3: if (event == GUI_EVENT_PAINT) { fb_text(FBW/2, 14, "Zapiš teplotu", TEXT_CENTER, 1); } if (phase == 1) { 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; } 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; } if (push_time() > pdMS_TO_TICKS(500)) { input_sound_effect(); app_heater_manual_override_clear(); switch_screen(screen_home, true); return; } if (event == GUI_EVENT_KNOB_PLUS) { if (*pT < 500) { *pT += 1; input_sound_effect(); request_paint(); } } else if (event == GUI_EVENT_KNOB_MINUS) { if (*pT > 0) { input_sound_effect(); *pT -= 1; request_paint(); } } 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); float corrected1 = c_to_val((float) s_app.calib.temp1); float corrected2 = c_to_val((float) s_app.calib.temp2); float a = ; float b = ; // TODO set and persist calibration } } break; case 5: if (event == GUI_EVENT_PAINT) { fb_text(FBW/2, 14, "Hotovo", TEXT_CENTER, 1); fb_text(FBW/2, 36, "→Hlavní menu", TEXT_CENTER, 1); } if (event == GUI_EVENT_KNOB_RELEASE) { switch_screen(screen_home, 1); } break; } }