Refactor temperature profile executer

This commit is contained in:
2021-10-23 21:00:21 +02:00
parent 73606bf7a0
commit fe0e8136d4
5 changed files with 35 additions and 35 deletions

View File

@@ -33,7 +33,7 @@
#include <reflow-controller/safety/safety-controller.h>
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 &current_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();
}