Refactor temperature profile executer
This commit is contained in:
parent
73606bf7a0
commit
fe0e8136d4
@ -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 */
|
enum tpe_status status; /**< @brief Execution status */
|
||||||
float setpoint; /**< @brief Temperature setpoint in degrees Celsius */
|
float setpoint; /**< @brief Temperature setpoint in degrees Celsius */
|
||||||
uint64_t start_timestamp; /**< @brief The millisicend tick timestamp, the profile execution was started */
|
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.
|
* @warning The returned state structure is static and used internally. You must not modify it.
|
||||||
* @return Execution state
|
* @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.
|
* @brief Stop the temperature profile execution.
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup temp-profile
|
* @defgroup temp-profile Temperature Profile Parser and Executer
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -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)
|
shellmatta_retCode_t shell_cmd_execute(const shellmatta_handle_t handle, const char *args, uint32_t len)
|
||||||
{
|
{
|
||||||
enum pl_ret_val res;
|
enum pl_ret_val res;
|
||||||
const struct tpe_current_state *state;
|
const struct tpe_exec_state *state;
|
||||||
static bool running = false;
|
static bool running = false;
|
||||||
char *data;
|
char *data;
|
||||||
uint32_t dlen;
|
uint32_t dlen;
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
#include <reflow-controller/safety/safety-controller.h>
|
#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,
|
.status = TPE_OFF,
|
||||||
.start_timestamp = 0,
|
.start_timestamp = 0,
|
||||||
};
|
};
|
||||||
@ -46,7 +46,7 @@ static SlList *command_list = NULL;
|
|||||||
static void tpe_abort(void)
|
static void tpe_abort(void)
|
||||||
{
|
{
|
||||||
temp_profile_executer_stop();
|
temp_profile_executer_stop();
|
||||||
state.status = TPE_ABORT;
|
current_state.status = TPE_ABORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum pl_ret_val temp_profile_executer_start(const char *filename)
|
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;
|
uint32_t parsed_count = 0;
|
||||||
enum pl_ret_val res;
|
enum pl_ret_val res;
|
||||||
|
|
||||||
state.setpoint = 0.0f;
|
current_state.setpoint = 0.0f;
|
||||||
state.start_timestamp = 0ULL;
|
current_state.start_timestamp = 0ULL;
|
||||||
state.setpoint = 0.0f;
|
current_state.setpoint = 0.0f;
|
||||||
state.step = 0;
|
current_state.step = 0;
|
||||||
state.profile_steps = 0;
|
current_state.profile_steps = 0;
|
||||||
|
|
||||||
oven_pid_stop();
|
oven_pid_stop();
|
||||||
pid_should_run = false;
|
pid_should_run = false;
|
||||||
state.status = TPE_OFF;
|
current_state.status = TPE_OFF;
|
||||||
state.profile_steps = 0;
|
current_state.profile_steps = 0;
|
||||||
cmd_continue = false;
|
cmd_continue = false;
|
||||||
|
|
||||||
/* This should never happen... But who knows */
|
/* 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);
|
res = temp_profile_parse_from_file(filename, &command_list, MAX_PROFILE_LENGTH, &parsed_count);
|
||||||
if (res == PL_RET_SUCCESS) {
|
if (res == PL_RET_SUCCESS) {
|
||||||
state.profile_steps = parsed_count;
|
current_state.profile_steps = parsed_count;
|
||||||
state.status = TPE_RUNNING;
|
current_state.status = TPE_RUNNING;
|
||||||
state.start_timestamp = systick_get_global_tick();
|
current_state.start_timestamp = systick_get_global_tick();
|
||||||
} else {
|
} else {
|
||||||
if (command_list)
|
if (command_list)
|
||||||
temp_profile_free_command_list(&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();
|
reactivate_pid_if_suspended();
|
||||||
oven_pid_set_target_temperature(cmd->params[0]);
|
oven_pid_set_target_temperature(cmd->params[0]);
|
||||||
state.setpoint = cmd->params[0];
|
current_state.setpoint = cmd->params[0];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,21 +146,21 @@ static bool cmd_ramp(struct pl_command *cmd, bool cmd_continue)
|
|||||||
|
|
||||||
if (!cmd_continue) {
|
if (!cmd_continue) {
|
||||||
/* Init of command */
|
/* Init of command */
|
||||||
start_temp = state.setpoint;
|
start_temp = current_state.setpoint;
|
||||||
slope = (cmd->params[0] - start_temp) / cmd->params[1];
|
slope = (cmd->params[0] - start_temp) / cmd->params[1];
|
||||||
reactivate_pid_if_suspended();
|
reactivate_pid_if_suspended();
|
||||||
oven_pid_set_target_temperature(start_temp);
|
oven_pid_set_target_temperature(start_temp);
|
||||||
start_timestamp = systick_get_global_tick();
|
start_timestamp = systick_get_global_tick();
|
||||||
} else {
|
} else {
|
||||||
secs_passed = ((float)(systick_get_global_tick() - start_timestamp)) / 1000.0f;
|
secs_passed = ((float)(systick_get_global_tick() - start_timestamp)) / 1000.0f;
|
||||||
if ((state.setpoint <= cmd->params[0] && start_temp < cmd->params[0]) ||
|
if ((current_state.setpoint <= cmd->params[0] && start_temp < cmd->params[0]) ||
|
||||||
(state.setpoint >= cmd->params[0] && start_temp > cmd->params[0])) {
|
(current_state.setpoint >= cmd->params[0] && start_temp > cmd->params[0])) {
|
||||||
state.setpoint = start_temp + secs_passed * slope;
|
current_state.setpoint = start_temp + secs_passed * slope;
|
||||||
} else {
|
} else {
|
||||||
state.setpoint = cmd->params[0];
|
current_state.setpoint = cmd->params[0];
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
oven_pid_set_target_temperature(state.setpoint);
|
oven_pid_set_target_temperature(current_state.setpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -195,7 +195,7 @@ int temp_profile_executer_handle(void)
|
|||||||
|
|
||||||
|
|
||||||
/* Return if no profile is currently executed */
|
/* Return if no profile is currently executed */
|
||||||
if (state.status != TPE_RUNNING)
|
if (current_state.status != TPE_RUNNING)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Abort profile execution if oven PID is aborted. This is most likely due to some error flags */
|
/* 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))
|
if (!systick_ticks_have_passed(last_tick, 100))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
current_cmd = (struct pl_command *)sl_list_nth(command_list, state.step)->data;
|
current_cmd = (struct pl_command *)sl_list_nth(command_list, current_state.step)->data;
|
||||||
next_step = state.step;
|
next_step = current_state.step;
|
||||||
|
|
||||||
switch (current_cmd->cmd) {
|
switch (current_cmd->cmd) {
|
||||||
case PL_WAIT_FOR_TIME:
|
case PL_WAIT_FOR_TIME:
|
||||||
@ -259,9 +259,9 @@ int temp_profile_executer_handle(void)
|
|||||||
if (advance)
|
if (advance)
|
||||||
next_step++;
|
next_step++;
|
||||||
|
|
||||||
if (next_step != state.step) {
|
if (next_step != current_state.step) {
|
||||||
state.step = next_step;
|
current_state.step = next_step;
|
||||||
if (next_step >= state.profile_steps) {
|
if (next_step >= current_state.profile_steps) {
|
||||||
(void)temp_profile_executer_stop();
|
(void)temp_profile_executer_stop();
|
||||||
} else {
|
} else {
|
||||||
cmd_continue = false;
|
cmd_continue = false;
|
||||||
@ -274,15 +274,15 @@ int temp_profile_executer_handle(void)
|
|||||||
return 0;
|
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)
|
int temp_profile_executer_stop(void)
|
||||||
{
|
{
|
||||||
if (state.status == TPE_RUNNING) {
|
if (current_state.status == TPE_RUNNING) {
|
||||||
state.status = TPE_OFF;
|
current_state.status = TPE_OFF;
|
||||||
oven_pid_stop();
|
oven_pid_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 gui_menu_temp_profile_execute(struct lcd_menu *menu, enum menu_entry_func_entry entry_type, void* parent)
|
||||||
{
|
{
|
||||||
static void *my_parent;
|
static void *my_parent;
|
||||||
const struct tpe_current_state *state;
|
const struct tpe_exec_state *state;
|
||||||
static uint64_t last_tick;
|
static uint64_t last_tick;
|
||||||
float temperature;
|
float temperature;
|
||||||
float resistance;
|
float resistance;
|
||||||
|
Loading…
Reference in New Issue
Block a user