From 46125ba752aa6b2bd799424e5cc60d0d0bd93172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 4 Apr 2021 19:34:04 +0200 Subject: [PATCH] Issue #28: Implement first working draft of temperature profile GUI --- stm-firmware/ui/gui.c | 69 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/stm-firmware/ui/gui.c b/stm-firmware/ui/gui.c index 681a9f5..04bb51a 100644 --- a/stm-firmware/ui/gui.c +++ b/stm-firmware/ui/gui.c @@ -413,6 +413,51 @@ static int load_temperature_file_list_from_sdcard(char (*list)[17], uint32_t len return (int)i; } +static void gui_menu_temp_profile_execute(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void* parent) +{ + static void *my_parent; + const struct tpe_current_state *state; + static uint64_t last_tick; + float temperature; + float resistance; + int res; + + if (entry_type == MENU_ENTRY_FIRST_ENTER) { + my_parent = parent; + menu_display_clear(menu); + last_tick = 0ULL; + } + + if (systick_ticks_have_passed(last_tick, 300)) { + state = temp_profile_executer_status(); + if (state->status == TPE_RUNNING) + menu_lcd_outputf(menu, 0, "Profile running"); + else if (state->status == TPE_OFF) { + menu_lcd_outputf(menu, 0, "Profile finished"); + } else { + menu_lcd_outputf(menu, 0, "Profile aborted!"); + } + menu_lcd_outputf(menu, 1, "Step %u/%u", state->step, state->profile_steps); + (void)adc_pt1000_get_current_resistance(&resistance); + res = temp_converter_convert_resistance_to_temp(resistance, &temperature); + menu_lcd_outputf(menu, 2, "Temp: %s%.0f", (res < 0 ? "<" : (res > 0 ? ">" : "")), temperature); + if (oven_pid_get_status() == OVEN_PID_RUNNING) { + menu_lcd_outputf(menu, 3, "Target: %.0f", state->setpoint); + } else { + menu_lcd_outputf(menu, 3, "Temp Off"); + } + + last_tick = systick_get_global_tick(); + } + + if (menu_get_button_ready_state(menu)) { + if (menu_get_button_state(menu) != BUTTON_IDLE) { + temp_profile_executer_stop(); + menu_entry_dropback(menu, my_parent); + } + } +} + static void gui_menu_temp_profile_select(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent) { static void *my_parent; @@ -437,6 +482,7 @@ static void gui_menu_temp_profile_select(struct lcd_menu *menu, enum menu_entry_ } currently_selected = 0u; + profile_ret_val = PL_RET_SUCCESS; loaded = (uint32_t)res; menu_lcd_outputf(menu, 0, "Select:"); } else if (entry_type == MENU_ENTRY_DROPBACK) { @@ -465,7 +511,23 @@ static void gui_menu_temp_profile_select(struct lcd_menu *menu, enum menu_entry_ menu_entry_dropback(menu, my_parent); return; } else if (profile_ret_val != PL_RET_SUCCESS) { - menu_lcd_outputf(menu, 0, "Profile Error"); + menu_lcd_outputf(menu, 0, "ERROR"); + switch (profile_ret_val) { + case PL_RET_SCRIPT_ERR: + menu_lcd_outputf(menu, 1, "Syntax Error"); + break; + case PL_RET_DISK_ERR: + menu_lcd_outputf(menu, 1, "Disk Error"); + break; + case PL_RET_LIST_FULL: + menu_lcd_output(menu, 1, "Too many com-"); + menu_lcd_output(menu, 2, "mands in file"); + break; + default: + menu_lcd_output(menu, 1, "Unknown error"); + break; + } + if (button == BUTTON_SHORT_RELEASED) menu_entry_dropback(menu, my_parent); return; @@ -475,6 +537,11 @@ static void gui_menu_temp_profile_select(struct lcd_menu *menu, enum menu_entry_ if (button == BUTTON_SHORT_RELEASED) { /* Execute selected profile */ + profile_ret_val = temp_profile_executer_start(&profile_list[currently_selected][0]); + if (profile_ret_val == PL_RET_SUCCESS) { + menu_entry_enter(menu, gui_menu_temp_profile_execute, true); + return; + } } if (delta >= 4) {