Compare commits
3 Commits
c5667c6895
...
fa3c980207
Author | SHA1 | Date | |
---|---|---|---|
fa3c980207 | |||
3c6200e08c | |||
e7d150e8f5 |
@ -150,7 +150,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define FF_FS_RPATH 0
|
#define FF_FS_RPATH 2
|
||||||
/* This option configures support for relative path.
|
/* This option configures support for relative path.
|
||||||
/
|
/
|
||||||
/ 0: Disable relative path and remove related functions.
|
/ 0: Disable relative path and remove related functions.
|
||||||
|
@ -21,4 +21,8 @@
|
|||||||
#ifndef __SETTINGS_SETTINGS_SD_CARD_H__
|
#ifndef __SETTINGS_SETTINGS_SD_CARD_H__
|
||||||
#define __SETTINGS_SETTINGS_SD_CARD_H__
|
#define __SETTINGS_SETTINGS_SD_CARD_H__
|
||||||
|
|
||||||
|
#define CALIBRATION_FILE_NAME "cal.toml"
|
||||||
|
|
||||||
|
int sd_card_settings_save_calibration(float sens_deviation, float offset);
|
||||||
|
|
||||||
#endif /* __SETTINGS_SETTINGS_SD_CARD_H__ */
|
#endif /* __SETTINGS_SETTINGS_SD_CARD_H__ */
|
||||||
|
@ -22,6 +22,12 @@
|
|||||||
#ifndef __SETTINGS_SETTINGS_H__
|
#ifndef __SETTINGS_SETTINGS_H__
|
||||||
#define __SETTINGS_SETTINGS_H__
|
#define __SETTINGS_SETTINGS_H__
|
||||||
|
|
||||||
int settings_save_calibration();
|
/**
|
||||||
|
* @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);
|
||||||
|
|
||||||
#endif /* __SETTINGS_SETTINGS_H__ */
|
#endif /* __SETTINGS_SETTINGS_H__ */
|
||||||
|
@ -19,3 +19,90 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <reflow-controller/settings/settings-sd-card.h>
|
#include <reflow-controller/settings/settings-sd-card.h>
|
||||||
|
#include <stm-periph/unique-id.h>
|
||||||
|
#include <toml/toml.h>
|
||||||
|
#include <fatfs/ff.h>
|
||||||
|
|
||||||
|
static void get_controller_folder_path(char *path, size_t size)
|
||||||
|
{
|
||||||
|
uint32_t high;
|
||||||
|
uint32_t mid;
|
||||||
|
uint32_t low;
|
||||||
|
|
||||||
|
if (!path)
|
||||||
|
return;
|
||||||
|
|
||||||
|
unique_id_get(&high, &mid, &low);
|
||||||
|
|
||||||
|
snprintf(path, size, "/%08X-%08X-%08X",
|
||||||
|
(unsigned int)high, (unsigned int)mid, (unsigned int)low);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Open or create the controller folder on the SD Card.
|
||||||
|
* @param[in,out] controller_folder
|
||||||
|
* @return 0 if opened, 1 if created and opened, -1 if error.
|
||||||
|
*/
|
||||||
|
static int open_or_create_controller_folder(DIR *controller_folder)
|
||||||
|
{
|
||||||
|
char foldername[48];
|
||||||
|
int ret = -1;
|
||||||
|
FRESULT filesystem_result;
|
||||||
|
|
||||||
|
if (!controller_folder)
|
||||||
|
return -1001;
|
||||||
|
|
||||||
|
get_controller_folder_path(foldername, sizeof(foldername));
|
||||||
|
|
||||||
|
/* Check if folder is present */
|
||||||
|
filesystem_result = f_opendir(controller_folder, foldername);
|
||||||
|
if (filesystem_result == FR_OK) {
|
||||||
|
ret = 0;
|
||||||
|
} else {
|
||||||
|
filesystem_result = f_mkdir(foldername);
|
||||||
|
if (filesystem_result == FR_OK) {
|
||||||
|
filesystem_result = f_opendir(controller_folder, foldername);
|
||||||
|
if (filesystem_result == FR_OK)
|
||||||
|
ret = 1;
|
||||||
|
else
|
||||||
|
ret = -1;
|
||||||
|
} else {
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret >= 0)
|
||||||
|
f_chdir(foldername);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sd_card_settings_save_calibration(float sens_deviation, float offset)
|
||||||
|
{
|
||||||
|
DIR folder;
|
||||||
|
FIL cal_file;
|
||||||
|
int status;
|
||||||
|
FRESULT res;
|
||||||
|
UINT bw;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
status = open_or_create_controller_folder(&folder);
|
||||||
|
f_closedir(&folder);
|
||||||
|
|
||||||
|
if (status < 0)
|
||||||
|
return -2;
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
f_close(&cal_file);
|
||||||
|
ret = 0;
|
||||||
|
} else {
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_chdir("/");
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -19,8 +19,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <reflow-controller/settings/settings.h>
|
#include <reflow-controller/settings/settings.h>
|
||||||
|
#include <reflow-controller/settings/settings-sd-card.h>
|
||||||
|
|
||||||
int settings_save_calibration()
|
settings_save_calibration(float sens_deviation, float offset)
|
||||||
{
|
{
|
||||||
return 0;
|
/* There is no other configuration location besides the SD card (yet) */
|
||||||
|
return sd_card_settings_save_calibration(sens_deviation, offset);
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include <reflow-controller/stack-check.h>
|
#include <reflow-controller/stack-check.h>
|
||||||
#include <reflow-controller/rotary-encoder.h>
|
#include <reflow-controller/rotary-encoder.h>
|
||||||
#include <reflow-controller/safety/safety-controller.h>
|
#include <reflow-controller/safety/safety-controller.h>
|
||||||
|
#include <reflow-controller/settings/settings.h>
|
||||||
|
|
||||||
#ifndef GIT_VER
|
#ifndef GIT_VER
|
||||||
#define GIT_VER "VERSION NOT SET"
|
#define GIT_VER "VERSION NOT SET"
|
||||||
@ -407,6 +408,24 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
|
|||||||
return SHELLMATTA_OK;
|
return SHELLMATTA_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static shellmatta_retCode_t shell_cmd_save_cal(const shellmatta_handle_t handle, const char *arguments,
|
||||||
|
uint32_t length)
|
||||||
|
|
||||||
|
{
|
||||||
|
(void)length;
|
||||||
|
(void)arguments;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
/* TODO: Change this */
|
||||||
|
res = settings_save_calibration(0.0f, 0.0f);
|
||||||
|
if (res) {
|
||||||
|
shellmatta_printf(handle, "Error saving %d\r\n", res);
|
||||||
|
} else {
|
||||||
|
shellmatta_printf(handle, "Saved!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return SHELLMATTA_OK;
|
||||||
|
}
|
||||||
//typedef struct shellmatta_cmd
|
//typedef struct shellmatta_cmd
|
||||||
//{
|
//{
|
||||||
// char *cmd; /**< command name */
|
// char *cmd; /**< command name */
|
||||||
@ -417,7 +436,7 @@ static shellmatta_retCode_t shell_cmd_read_flags(const shellmatta_handle_t handl
|
|||||||
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
||||||
//} shellmatta_cmd_t;
|
//} shellmatta_cmd_t;
|
||||||
|
|
||||||
static shellmatta_cmd_t cmd[13] = {
|
static shellmatta_cmd_t cmd[14] = {
|
||||||
{
|
{
|
||||||
.cmd = "version",
|
.cmd = "version",
|
||||||
.cmdAlias = "ver",
|
.cmdAlias = "ver",
|
||||||
@ -520,8 +539,16 @@ static shellmatta_cmd_t cmd[13] = {
|
|||||||
.helpText = "",
|
.helpText = "",
|
||||||
.usageText = "",
|
.usageText = "",
|
||||||
.cmdFct = shell_cmd_read_flags,
|
.cmdFct = shell_cmd_read_flags,
|
||||||
|
.next = &cmd[13],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.cmd = "save-calibration",
|
||||||
|
.cmdAlias = "save-cal",
|
||||||
|
.helpText = "",
|
||||||
|
.usageText = "",
|
||||||
|
.cmdFct = shell_cmd_save_cal,
|
||||||
.next = NULL,
|
.next = NULL,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
shellmatta_handle_t shell_init(shellmatta_write_t write_func)
|
shellmatta_handle_t shell_init(shellmatta_write_t write_func)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user