From 5deac33949003f63b2940d0313a8a4f9fdc2ee00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 4 Apr 2021 17:43:31 +0200 Subject: [PATCH] Implement basic gui for profile selection. Still doesn't do anything --- stm-firmware/.gitignore | 1 + stm-firmware/shell.c | 2 +- stm-firmware/temp-profile-executer.c | 133 ++++++++++++++------------- stm-firmware/ui/gui.c | 45 +++++++-- 4 files changed, 107 insertions(+), 74 deletions(-) diff --git a/stm-firmware/.gitignore b/stm-firmware/.gitignore index 1e70134..bcb7a46 100644 --- a/stm-firmware/.gitignore +++ b/stm-firmware/.gitignore @@ -15,3 +15,4 @@ reflow-controller.includes *.config *.files *.user.* +*.user diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index 5da09a8..f881b63 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -942,7 +942,7 @@ static shellmatta_cmd_t cmd[21] = { .cmd = "execute", .cmdAlias = NULL, .helpText = "Execute Temp Profile", - .usageText = "", + .usageText = "execute /path/to/script.tpr", .cmdFct = shell_cmd_execute, .next = NULL, } diff --git a/stm-firmware/temp-profile-executer.c b/stm-firmware/temp-profile-executer.c index 0fcde02..f785b78 100644 --- a/stm-firmware/temp-profile-executer.c +++ b/stm-firmware/temp-profile-executer.c @@ -27,15 +27,15 @@ #include static struct tpe_current_state IN_SECTION(.ccm.data) state = { - .status = TPE_OFF, - .start_timestamp = 0, -}; + .status = TPE_OFF, + .start_timestamp = 0, + }; static bool IN_SECTION(.ccm.bss) pid_should_run; struct pid_controller IN_SECTION(.ccm.bss) pid; static struct pl_command IN_SECTION(.ccm.bss) cmd_list[MAX_PROFILE_LENGTH]; -static void abort(void) +static void tpe_abort(void) { temp_profile_executer_stop(); state.status = TPE_ABORT; @@ -54,6 +54,8 @@ enum pl_ret_val temp_profile_executer_start(const char *filename) oven_pid_stop(); pid_should_run = false; + state.status = TPE_OFF; + state.profile_steps = 0; res = temp_profile_parse_from_file(filename, cmd_list, MAX_PROFILE_LENGTH, &parsed_count); if (res == PL_RET_SUCCESS) { @@ -74,7 +76,7 @@ static bool cmd_wait_temp(struct pl_command *cmd, bool cmd_continue) res = adc_pt1000_get_current_resistance(&resistance); if (res < 0) { - abort(); + tpe_abort(); return false; } @@ -137,7 +139,7 @@ static bool cmd_ramp(struct pl_command *cmd, bool cmd_continue) } else { secs_passed = ((float)(systick_get_global_tick() - start_timestamp)) / 1000.0f; if ((state.setpoint <= cmd->params[0] && start_temp < cmd->params[0]) || - (state.setpoint >= cmd->params[0] && start_temp > cmd->params[0])) { + (state.setpoint >= cmd->params[0] && start_temp > cmd->params[0])) { state.setpoint = start_temp + secs_passed * slope; } else { state.setpoint = cmd->params[0]; @@ -158,74 +160,79 @@ int temp_profile_executer_handle(void) uint32_t next_step; + /* Return if no profile is currently executed */ if (state.status != TPE_RUNNING) return -1; + + /* Abort profile execution if oven PID is aborted. This is most likely due to some error flags */ if (oven_pid_get_status() == OVEN_PID_ABORTED && pid_should_run) { - abort(); + tpe_abort(); oven_pid_stop(); return -1; } - if (systick_ticks_have_passed(last_tick, 100)) { - current_cmd = &cmd_list[state.step]; - next_step = state.step; + /* Execute Temp Profile every 100 ms. If not yet due, return */ + if (!systick_ticks_have_passed(last_tick, 100)) + return 0; - switch (current_cmd->cmd) { - case PL_WAIT_FOR_TIME: - advance = cmd_wait_time(current_cmd, cmd_continue); - break; - case PL_WAIT_FOR_TEMP: - advance = cmd_wait_temp(current_cmd, cmd_continue); - break; - case PL_SET_TEMP: - advance = cmd_set_temp(current_cmd, cmd_continue); - break; - case PL_LOUDSPEAKER_SET: - loudspeaker_set((uint16_t)current_cmd->params[0]); - advance = true; - break; - case PL_OFF: - oven_pid_stop(); - pid_should_run = false; - advance = true; - break; - case PL_PID_CONF: - pid_init(&pid, current_cmd->params[0], /* Kd */ - current_cmd->params[1], /* Ki */ - current_cmd->params[2], /* Kp */ - 0.0f, 0.0f, - current_cmd->params[3], /* Int max */ - current_cmd->params[4], /* Kd tau */ - current_cmd->params[5]); /* Period */ - oven_pid_init(&pid); - advance = true; - pid_should_run = true; - break; - case PL_SET_RAMP: - advance = cmd_ramp(current_cmd, cmd_continue); - break; - default: - abort(); - advance = true; - break; - } + current_cmd = &cmd_list[state.step]; + next_step = state.step; - if (advance) - next_step++; - - if (next_step != state.step) { - state.step = next_step; - if (next_step >= state.profile_steps) { - (void)temp_profile_executer_stop(); - } else { - cmd_continue = false; - } - } else { - cmd_continue = true; - } - last_tick = systick_get_global_tick(); + switch (current_cmd->cmd) { + case PL_WAIT_FOR_TIME: + advance = cmd_wait_time(current_cmd, cmd_continue); + break; + case PL_WAIT_FOR_TEMP: + advance = cmd_wait_temp(current_cmd, cmd_continue); + break; + case PL_SET_TEMP: + advance = cmd_set_temp(current_cmd, cmd_continue); + break; + case PL_LOUDSPEAKER_SET: + loudspeaker_set((uint16_t)current_cmd->params[0]); + advance = true; + break; + case PL_OFF: + oven_pid_stop(); + pid_should_run = false; + advance = true; + break; + case PL_PID_CONF: + pid_init(&pid, current_cmd->params[0], /* Kd */ + current_cmd->params[1], /* Ki */ + current_cmd->params[2], /* Kp */ + 0.0f, 0.0f, + current_cmd->params[3], /* Int max */ + current_cmd->params[4], /* Kd tau */ + current_cmd->params[5]); /* Period */ + oven_pid_init(&pid); + advance = true; + pid_should_run = true; + break; + case PL_SET_RAMP: + advance = cmd_ramp(current_cmd, cmd_continue); + break; + default: + tpe_abort(); + advance = true; + break; } + if (advance) + next_step++; + + if (next_step != state.step) { + state.step = next_step; + if (next_step >= state.profile_steps) { + (void)temp_profile_executer_stop(); + } else { + cmd_continue = false; + } + } else { + cmd_continue = true; + } + last_tick = systick_get_global_tick(); + return 0; } diff --git a/stm-firmware/ui/gui.c b/stm-firmware/ui/gui.c index 04e897a..681a9f5 100644 --- a/stm-firmware/ui/gui.c +++ b/stm-firmware/ui/gui.c @@ -37,6 +37,7 @@ #include #include #include +#include static char IN_SECTION(.ccm.bss) display_buffer[4][21] = {0}; static struct lcd_menu IN_SECTION(.ccm.bss) reflow_menu; @@ -417,9 +418,12 @@ static void gui_menu_temp_profile_select(struct lcd_menu *menu, enum menu_entry_ static void *my_parent; static char profile_list[10][17]; static bool file_error = false; + static enum pl_ret_val profile_ret_val = PL_RET_SUCCESS; static uint8_t currently_selected = 0U; - static uint8_t current_scroll_offset = 0U; static uint8_t loaded; + int16_t delta; + enum button_state button; + int res; if (entry_type == MENU_ENTRY_FIRST_ENTER) { @@ -431,7 +435,7 @@ static void gui_menu_temp_profile_select(struct lcd_menu *menu, enum menu_entry_ if (res < 0) { file_error = true; } - current_scroll_offset = 0u; + currently_selected = 0u; loaded = (uint32_t)res; menu_lcd_outputf(menu, 0, "Select:"); @@ -441,28 +445,49 @@ static void gui_menu_temp_profile_select(struct lcd_menu *menu, enum menu_entry_ } if (menu_get_button_ready_state(menu)) { - if (menu_get_button_state(menu) == BUTTON_LONG) { + delta = menu_get_rotary_delta(menu); + button = menu_get_button_state(menu); + + if (button == BUTTON_LONG) { menu_entry_dropback(menu, my_parent); } if (file_error) { menu_lcd_outputf(menu, 0, "Disk Error"); menu_lcd_outputf(menu, 1, "SD inserted?"); - if (menu_get_button_state(menu) == BUTTON_SHORT_RELEASED) + if (button == BUTTON_SHORT_RELEASED) menu_entry_dropback(menu, my_parent); return; - } - - if (loaded == 0) { + } else if (loaded == 0) { menu_lcd_outputf(menu, 0, "No profiles"); menu_lcd_outputf(menu, 1, "found"); - if (menu_get_button_state(menu) == BUTTON_SHORT_RELEASED) + if (button == BUTTON_SHORT_RELEASED) menu_entry_dropback(menu, my_parent); return; + } else if (profile_ret_val != PL_RET_SUCCESS) { + menu_lcd_outputf(menu, 0, "Profile Error"); + if (button == BUTTON_SHORT_RELEASED) + menu_entry_dropback(menu, my_parent); + return; + } else if (currently_selected < loaded) { + /* Show currently selected profile */ + menu_lcd_outputf(menu, 1, "%s", &profile_list[currently_selected][0]); + + if (button == BUTTON_SHORT_RELEASED) { + /* Execute selected profile */ + } + + if (delta >= 4) { + menu_ack_rotary_delta(menu); + if (currently_selected < (loaded - 1)) + currently_selected++; + } else if (delta <= -4) { + menu_ack_rotary_delta(menu); + if (currently_selected > 0) + currently_selected--; + } } } - - } static void gui_menu_constant_temperature_driver_setup(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void *parent)