Fix #3: Merge branch 'issue/3-load-oven-pid-params' into dev
This commit is contained in:
commit
a858223c35
@ -96,7 +96,7 @@ exit:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, struct config_parser_entry *entry)
|
enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, struct config_parser_entry *entry, bool force_float)
|
||||||
{
|
{
|
||||||
struct config_parser *p;
|
struct config_parser *p;
|
||||||
config_parser_check_handle(handle);
|
config_parser_check_handle(handle);
|
||||||
@ -142,6 +142,15 @@ enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, str
|
|||||||
token = strtok(NULL, token_delim);
|
token = strtok(NULL, token_delim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (force_float) {
|
||||||
|
if (entry->type == CONFIG_PARSER_TYPE_INT)
|
||||||
|
entry->value.float_val = (float)entry->value.int_val;
|
||||||
|
if (entry->type == CONFIG_PARSER_TYPE_UINT)
|
||||||
|
entry->value.float_val = (float)entry->value.uint_val;
|
||||||
|
|
||||||
|
entry->type = CONFIG_PARSER_TYPE_FLOAT;
|
||||||
|
}
|
||||||
|
|
||||||
return CONFIG_PARSER_OK;
|
return CONFIG_PARSER_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ config_parser_handle_t config_parser_open_file(struct config_parser *config_pars
|
|||||||
* have to be copied
|
* have to be copied
|
||||||
* @return Config parser error
|
* @return Config parser error
|
||||||
*/
|
*/
|
||||||
enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, struct config_parser_entry *entry);
|
enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, struct config_parser_entry *entry, bool force_float);
|
||||||
|
|
||||||
enum config_parser_ret config_parser_reset_to_start(config_parser_handle_t handle);
|
enum config_parser_ret config_parser_reset_to_start(config_parser_handle_t handle);
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
#define __SETTINGS_SETTINGS_SD_CARD_H__
|
#define __SETTINGS_SETTINGS_SD_CARD_H__
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <reflow-controller/settings/settings.h>
|
||||||
#define CALIBRATION_FILE_NAME "settings.ini"
|
|
||||||
|
|
||||||
int sd_card_settings_save_calibration(float sens_deviation, float offset, bool active);
|
int sd_card_settings_save_calibration(float sens_deviation, float offset, bool active);
|
||||||
|
|
||||||
@ -35,4 +34,6 @@ int sd_card_settings_save_calibration(float sens_deviation, float offset, bool a
|
|||||||
*/
|
*/
|
||||||
int sd_card_settings_try_load_calibration(float *sens_deviation, float *offset);
|
int sd_card_settings_try_load_calibration(float *sens_deviation, float *offset);
|
||||||
|
|
||||||
|
enum settings_load_result sd_card_settings_load_pid_oven_parameters(struct oven_pid_settings *settings);
|
||||||
|
|
||||||
#endif /* __SETTINGS_SETTINGS_SD_CARD_H__ */
|
#endif /* __SETTINGS_SETTINGS_SD_CARD_H__ */
|
||||||
|
@ -24,6 +24,23 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
struct oven_pid_settings {
|
||||||
|
float kd;
|
||||||
|
float kp;
|
||||||
|
float ki;
|
||||||
|
float t_sample;
|
||||||
|
float max_integral;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum settings_load_result {
|
||||||
|
SETT_LOAD_SUCCESS = 0,
|
||||||
|
SETT_LOAD_FILE_NOT_FOUND,
|
||||||
|
SETT_LOAD_ERR,
|
||||||
|
SETT_LOAD_DISK_ERR
|
||||||
|
};
|
||||||
|
|
||||||
|
#define SETTINGS_PID_PARAMETER_FILE "pid.conf"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Save the calibration
|
* @brief Save the calibration
|
||||||
* @param sens_deviation
|
* @param sens_deviation
|
||||||
@ -34,4 +51,6 @@ int settings_save_calibration(float sens_deviation, float offset, bool active);
|
|||||||
|
|
||||||
int settings_load_calibration(float *sens_dev, float *offset);
|
int settings_load_calibration(float *sens_dev, float *offset);
|
||||||
|
|
||||||
|
enum settings_load_result settings_load_pid_oven_parameters(struct oven_pid_settings *settings);
|
||||||
|
|
||||||
#endif /* __SETTINGS_SETTINGS_H__ */
|
#endif /* __SETTINGS_SETTINGS_H__ */
|
||||||
|
@ -138,7 +138,7 @@ int sd_card_settings_try_load_calibration(float *sens_deviation, float *offset)
|
|||||||
p = config_parser_open_file(&parser, false, path, workbuff, sizeof(workbuff));
|
p = config_parser_open_file(&parser, false, path, workbuff, sizeof(workbuff));
|
||||||
status = 0;
|
status = 0;
|
||||||
do {
|
do {
|
||||||
res = config_parser_get_line(p, &entry);
|
res = config_parser_get_line(p, &entry, true);
|
||||||
if (res == CONFIG_PARSER_OK) {
|
if (res == CONFIG_PARSER_OK) {
|
||||||
if (!strcmp(entry.name, "offset") && entry.type == CONFIG_PARSER_TYPE_FLOAT) {
|
if (!strcmp(entry.name, "offset") && entry.type == CONFIG_PARSER_TYPE_FLOAT) {
|
||||||
offset_loaded = true;
|
offset_loaded = true;
|
||||||
@ -161,3 +161,58 @@ int sd_card_settings_try_load_calibration(float *sens_deviation, float *offset)
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum settings_load_result sd_card_settings_load_pid_oven_parameters(struct oven_pid_settings *settings)
|
||||||
|
{
|
||||||
|
enum settings_load_result ret = SETT_LOAD_ERR;
|
||||||
|
const char * const file_name = SETTINGS_PID_PARAMETER_FILE;
|
||||||
|
struct config_parser parser;
|
||||||
|
config_parser_handle_t p;
|
||||||
|
enum config_parser_ret parse_result;
|
||||||
|
struct config_parser_entry entry;
|
||||||
|
bool kp_loaded = false, kd_loaded = false, ki_loaded = false, int_max_loaded = false, t_sample = false;
|
||||||
|
|
||||||
|
if (!settings) {
|
||||||
|
ret = SETT_LOAD_ERR;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
workbuff[0] = 0;
|
||||||
|
p = config_parser_open_file(&parser, false, file_name, workbuff, sizeof(workbuff));
|
||||||
|
if (!p)
|
||||||
|
goto exit;
|
||||||
|
do {
|
||||||
|
parse_result = config_parser_get_line(p, &entry, true);
|
||||||
|
if (parse_result == CONFIG_PARSER_OK) {
|
||||||
|
if (!strcmp(entry.name, "kp")) {
|
||||||
|
kp_loaded = true;
|
||||||
|
settings->kp = entry.value.float_val;
|
||||||
|
} else if (!strcmp(entry.name, "kd")) {
|
||||||
|
kd_loaded = true;
|
||||||
|
settings->kd = entry.value.float_val;
|
||||||
|
} else if (!strcmp(entry.name, "ki")) {
|
||||||
|
ki_loaded = true;
|
||||||
|
settings->ki = entry.value.float_val;
|
||||||
|
} else if (!strcmp(entry.name, "max_int")) {
|
||||||
|
int_max_loaded = true;
|
||||||
|
settings->max_integral = entry.value.float_val;
|
||||||
|
} else if (!strcmp(entry.name, "sample_period")) {
|
||||||
|
t_sample = true;
|
||||||
|
settings->t_sample = entry.value.float_val / 1000.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (parse_result != CONFIG_PARSER_END_REACHED &&
|
||||||
|
parse_result != CONFIG_PARSER_GENERIC_ERR &&
|
||||||
|
parse_result != CONFIG_PARSER_IOERR &&
|
||||||
|
parse_result != CONFIG_PARSER_PARAM_ERR);
|
||||||
|
|
||||||
|
|
||||||
|
if (kp_loaded && kd_loaded && ki_loaded && t_sample && int_max_loaded)
|
||||||
|
ret = SETT_LOAD_SUCCESS;
|
||||||
|
|
||||||
|
config_parser_close_file(p);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -31,3 +31,8 @@ int settings_load_calibration(float *sens_dev, float *offset)
|
|||||||
{
|
{
|
||||||
return sd_card_settings_try_load_calibration(sens_dev, offset);
|
return sd_card_settings_try_load_calibration(sens_dev, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum settings_load_result settings_load_pid_oven_parameters(struct oven_pid_settings *settings)
|
||||||
|
{
|
||||||
|
return sd_card_settings_load_pid_oven_parameters(settings);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user