Merge branch 'issue/1-shell-function-save-calibration-data' into dev
This commit is contained in:
commit
42ca1a01b5
@ -21,8 +21,10 @@
|
||||
#ifndef __SETTINGS_SETTINGS_SD_CARD_H__
|
||||
#define __SETTINGS_SETTINGS_SD_CARD_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define CALIBRATION_FILE_NAME "cal.toml"
|
||||
|
||||
int sd_card_settings_save_calibration(float sens_deviation, float offset);
|
||||
int sd_card_settings_save_calibration(float sens_deviation, float offset, bool active);
|
||||
|
||||
#endif /* __SETTINGS_SETTINGS_SD_CARD_H__ */
|
||||
|
@ -22,12 +22,14 @@
|
||||
#ifndef __SETTINGS_SETTINGS_H__
|
||||
#define __SETTINGS_SETTINGS_H__
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* @brief Save the calibration
|
||||
* @param sens_deviation
|
||||
* @param offset
|
||||
* @return 0 if successful, -1 if generic error, -2 if medium unavailable
|
||||
*/
|
||||
int settings_save_calibration(float sens_deviation, float offset);
|
||||
int settings_save_calibration(float sens_deviation, float offset, bool active);
|
||||
|
||||
#endif /* __SETTINGS_SETTINGS_H__ */
|
||||
|
@ -45,8 +45,6 @@
|
||||
#include <reflow-controller/reflow-menu.h>
|
||||
#include <reflow-controller/safety/safety-controller.h>
|
||||
|
||||
bool global_error_state;
|
||||
|
||||
static void setup_nvic_priorities(void)
|
||||
{
|
||||
/* No sub priorities */
|
||||
@ -200,8 +198,6 @@ int main(void)
|
||||
zero_ccm_ram();
|
||||
setup_system();
|
||||
|
||||
global_error_state = false;
|
||||
|
||||
shell_handle = shell_init(write_shell_callback);
|
||||
shell_print_motd(shell_handle);
|
||||
|
||||
|
@ -77,7 +77,7 @@ static int open_or_create_controller_folder(DIR *controller_folder)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sd_card_settings_save_calibration(float sens_deviation, float offset)
|
||||
int sd_card_settings_save_calibration(float sens_deviation, float offset, bool active)
|
||||
{
|
||||
DIR folder;
|
||||
FIL cal_file;
|
||||
@ -85,6 +85,7 @@ int sd_card_settings_save_calibration(float sens_deviation, float offset)
|
||||
FRESULT res;
|
||||
UINT bw;
|
||||
int ret = 0;
|
||||
char buff[256];
|
||||
|
||||
status = open_or_create_controller_folder(&folder);
|
||||
f_closedir(&folder);
|
||||
@ -95,9 +96,21 @@ int sd_card_settings_save_calibration(float sens_deviation, float offset)
|
||||
/* Create new calibration file */
|
||||
res = f_open(&cal_file, CALIBRATION_FILE_NAME, FA_CREATE_ALWAYS | FA_WRITE);
|
||||
if (res == FR_OK) {
|
||||
f_write(&cal_file, "Test", 4U, &bw);
|
||||
status = snprintf(buff, sizeof(buff), "[cal]\noffset = %f\nsensdev = %f\nactive = %s\n",
|
||||
offset, sens_deviation, (active ? "true" : "false"));
|
||||
|
||||
if ((unsigned int)status < sizeof(buff) && status >= 0) {
|
||||
f_write(&cal_file, buff, status, &bw);
|
||||
if (bw == (unsigned int)status)
|
||||
ret = 0;
|
||||
else
|
||||
ret = -3;
|
||||
} else {
|
||||
ret = -4;
|
||||
}
|
||||
|
||||
f_close(&cal_file);
|
||||
ret = 0;
|
||||
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include <reflow-controller/settings/settings.h>
|
||||
#include <reflow-controller/settings/settings-sd-card.h>
|
||||
|
||||
settings_save_calibration(float sens_deviation, float offset)
|
||||
settings_save_calibration(float sens_deviation, float offset, bool active)
|
||||
{
|
||||
/* There is no other configuration location besides the SD card (yet) */
|
||||
return sd_card_settings_save_calibration(sens_deviation, offset);
|
||||
return sd_card_settings_save_calibration(sens_deviation, offset, active);
|
||||
}
|
||||
|
@ -432,9 +432,12 @@ static shellmatta_retCode_t shell_cmd_save_cal(const shellmatta_handle_t handle,
|
||||
(void)length;
|
||||
(void)arguments;
|
||||
int res;
|
||||
float offset, sens_dev;
|
||||
bool active;
|
||||
|
||||
adc_pt1000_get_resistance_calibration(&offset, &sens_dev, &active);
|
||||
res = settings_save_calibration(sens_dev, offset, active);
|
||||
|
||||
/* TODO: Change this */
|
||||
res = settings_save_calibration(0.0f, 0.0f);
|
||||
if (res) {
|
||||
shellmatta_printf(handle, "Error saving %d\r\n", res);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user