From fe0e8136d44e50e634621dbb1d1666d9179de83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 23 Oct 2021 21:00:21 +0200 Subject: [PATCH] Refactor temperature profile executer --- .../temp-profile/temp-profile-executer.h | 6 +- .../temp-profile/temp-profile-parser.h | 2 +- stm-firmware/shell.c | 2 +- .../temp-profile/temp-profile-executer.c | 58 +++++++++---------- stm-firmware/ui/gui.c | 2 +- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/stm-firmware/include/reflow-controller/temp-profile/temp-profile-executer.h b/stm-firmware/include/reflow-controller/temp-profile/temp-profile-executer.h index e646b6a..0dd56e8 100644 --- a/stm-firmware/include/reflow-controller/temp-profile/temp-profile-executer.h +++ b/stm-firmware/include/reflow-controller/temp-profile/temp-profile-executer.h @@ -44,9 +44,9 @@ enum tpe_status { }; /** - * @brief The current execution state of the temperature profile + * @brief The execution state of the temperature profile */ -struct tpe_current_state { +struct tpe_exec_state { enum tpe_status status; /**< @brief Execution status */ float setpoint; /**< @brief Temperature setpoint in degrees Celsius */ uint64_t start_timestamp; /**< @brief The millisicend tick timestamp, the profile execution was started */ @@ -78,7 +78,7 @@ int temp_profile_executer_handle(void); * @warning The returned state structure is static and used internally. You must not modify it. * @return Execution state */ -const struct tpe_current_state *temp_profile_executer_status(void); +const struct tpe_exec_state *temp_profile_executer_status(void); /** * @brief Stop the temperature profile execution. diff --git a/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h b/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h index a6f4c40..ed5092e 100644 --- a/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h +++ b/stm-firmware/include/reflow-controller/temp-profile/temp-profile-parser.h @@ -19,7 +19,7 @@ */ /** - * @addtogroup temp-profile + * @defgroup temp-profile Temperature Profile Parser and Executer * @{ */ diff --git a/stm-firmware/shell.c b/stm-firmware/shell.c index 6d42dd3..9947da8 100644 --- a/stm-firmware/shell.c +++ b/stm-firmware/shell.c @@ -725,7 +725,7 @@ shellmatta_retCode_t shell_cmd_overtemp_cfg(const shellmatta_handle_t handle, co shellmatta_retCode_t shell_cmd_execute(const shellmatta_handle_t handle, const char *args, uint32_t len) { enum pl_ret_val res; - const struct tpe_current_state *state; + const struct tpe_exec_state *state; static bool running = false; char *data; uint32_t dlen; diff --git a/stm-firmware/temp-profile/temp-profile-executer.c b/stm-firmware/temp-profile/temp-profile-executer.c index e78a366..f9b8fd8 100644 --- a/stm-firmware/temp-profile/temp-profile-executer.c +++ b/stm-firmware/temp-profile/temp-profile-executer.c @@ -33,7 +33,7 @@ #include -static struct tpe_current_state IN_SECTION(.ccm.data) state = { +static struct tpe_exec_state IN_SECTION(.ccm.data) current_state = { .status = TPE_OFF, .start_timestamp = 0, }; @@ -46,7 +46,7 @@ static SlList *command_list = NULL; static void tpe_abort(void) { temp_profile_executer_stop(); - state.status = TPE_ABORT; + current_state.status = TPE_ABORT; } enum pl_ret_val temp_profile_executer_start(const char *filename) @@ -54,16 +54,16 @@ enum pl_ret_val temp_profile_executer_start(const char *filename) uint32_t parsed_count = 0; enum pl_ret_val res; - state.setpoint = 0.0f; - state.start_timestamp = 0ULL; - state.setpoint = 0.0f; - state.step = 0; - state.profile_steps = 0; + current_state.setpoint = 0.0f; + current_state.start_timestamp = 0ULL; + current_state.setpoint = 0.0f; + current_state.step = 0; + current_state.profile_steps = 0; oven_pid_stop(); pid_should_run = false; - state.status = TPE_OFF; - state.profile_steps = 0; + current_state.status = TPE_OFF; + current_state.profile_steps = 0; cmd_continue = false; /* This should never happen... But who knows */ @@ -73,9 +73,9 @@ enum pl_ret_val temp_profile_executer_start(const char *filename) res = temp_profile_parse_from_file(filename, &command_list, MAX_PROFILE_LENGTH, &parsed_count); if (res == PL_RET_SUCCESS) { - state.profile_steps = parsed_count; - state.status = TPE_RUNNING; - state.start_timestamp = systick_get_global_tick(); + current_state.profile_steps = parsed_count; + current_state.status = TPE_RUNNING; + current_state.start_timestamp = systick_get_global_tick(); } else { if (command_list) temp_profile_free_command_list(&command_list); @@ -132,7 +132,7 @@ static bool cmd_set_temp(struct pl_command *cmd) { reactivate_pid_if_suspended(); oven_pid_set_target_temperature(cmd->params[0]); - state.setpoint = cmd->params[0]; + current_state.setpoint = cmd->params[0]; return true; } @@ -146,21 +146,21 @@ static bool cmd_ramp(struct pl_command *cmd, bool cmd_continue) if (!cmd_continue) { /* Init of command */ - start_temp = state.setpoint; + start_temp = current_state.setpoint; slope = (cmd->params[0] - start_temp) / cmd->params[1]; reactivate_pid_if_suspended(); oven_pid_set_target_temperature(start_temp); start_timestamp = systick_get_global_tick(); } 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 = start_temp + secs_passed * slope; + if ((current_state.setpoint <= cmd->params[0] && start_temp < cmd->params[0]) || + (current_state.setpoint >= cmd->params[0] && start_temp > cmd->params[0])) { + current_state.setpoint = start_temp + secs_passed * slope; } else { - state.setpoint = cmd->params[0]; + current_state.setpoint = cmd->params[0]; ret = true; } - oven_pid_set_target_temperature(state.setpoint); + oven_pid_set_target_temperature(current_state.setpoint); } return ret; @@ -195,7 +195,7 @@ int temp_profile_executer_handle(void) /* Return if no profile is currently executed */ - if (state.status != TPE_RUNNING) + if (current_state.status != TPE_RUNNING) return -1; /* Abort profile execution if oven PID is aborted. This is most likely due to some error flags */ @@ -209,8 +209,8 @@ int temp_profile_executer_handle(void) if (!systick_ticks_have_passed(last_tick, 100)) return 0; - current_cmd = (struct pl_command *)sl_list_nth(command_list, state.step)->data; - next_step = state.step; + current_cmd = (struct pl_command *)sl_list_nth(command_list, current_state.step)->data; + next_step = current_state.step; switch (current_cmd->cmd) { case PL_WAIT_FOR_TIME: @@ -259,9 +259,9 @@ int temp_profile_executer_handle(void) if (advance) next_step++; - if (next_step != state.step) { - state.step = next_step; - if (next_step >= state.profile_steps) { + if (next_step != current_state.step) { + current_state.step = next_step; + if (next_step >= current_state.profile_steps) { (void)temp_profile_executer_stop(); } else { cmd_continue = false; @@ -274,15 +274,15 @@ int temp_profile_executer_handle(void) return 0; } -const struct tpe_current_state *temp_profile_executer_status(void) +const struct tpe_exec_state *temp_profile_executer_status(void) { - return &state; + return ¤t_state; } int temp_profile_executer_stop(void) { - if (state.status == TPE_RUNNING) { - state.status = TPE_OFF; + if (current_state.status == TPE_RUNNING) { + current_state.status = TPE_OFF; oven_pid_stop(); } diff --git a/stm-firmware/ui/gui.c b/stm-firmware/ui/gui.c index 8275066..695610b 100644 --- a/stm-firmware/ui/gui.c +++ b/stm-firmware/ui/gui.c @@ -414,7 +414,7 @@ static SlList *load_file_list_from_sdcard(int *error, const char *file_pattern) 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; + const struct tpe_exec_state *state; static uint64_t last_tick; float temperature; float resistance;