Issue #26: Add overtemp limit setting to settings module and load it from EEPROM at startup
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
#include <stm-periph/crc-unit.h>
|
||||
#include <string.h>
|
||||
|
||||
#define EEPROM_HEADER_MAGIC 0xA5
|
||||
#define EEPROM_HEADER_MAGIC 0xC5
|
||||
#define EEPROM_HEADER_COMP_VER 0x01
|
||||
|
||||
static const uint8_t expected_header[2] = {EEPROM_HEADER_MAGIC, EEPROM_HEADER_COMP_VER};
|
||||
@@ -57,6 +57,7 @@ static bool check_eeprom_header(void)
|
||||
static void settings_eeprom_zero()
|
||||
{
|
||||
settings_eeprom_save_calibration(0.0f, 0.0f, false);
|
||||
settings_eeprom_save_overtemp_limit(0.0, false);
|
||||
}
|
||||
|
||||
bool settings_eeprom_detect_and_prepare(void)
|
||||
@@ -145,10 +146,17 @@ int settings_eeprom_load_calibration(float *sens, float *offset, bool *active)
|
||||
}
|
||||
}
|
||||
|
||||
int settings_eeprom_save_overtemp_limit(float overtemp_limit)
|
||||
int settings_eeprom_save_overtemp_limit(float overtemp_limit, bool active)
|
||||
{
|
||||
int res;
|
||||
struct eeprom_over_temp_config over_temp_conf_entry;
|
||||
const uint8_t zero_vals[sizeof(over_temp_conf_entry)] = {0};
|
||||
|
||||
if (!active) {
|
||||
res = spi_eeprom_write(EEPROM_OVER_TEMP_CONFIG_BASE_ADDR, (const uint8_t *)zero_vals,
|
||||
sizeof(zero_vals));
|
||||
return res ? -1 : 0;
|
||||
}
|
||||
|
||||
over_temp_conf_entry.over_temperature = overtemp_limit;
|
||||
crc_unit_reset();
|
||||
|
@@ -64,3 +64,30 @@ void settings_setup(void)
|
||||
else
|
||||
settings_use_eeprom = false;
|
||||
}
|
||||
|
||||
enum settings_load_result settings_load_overtemp_limit(float *over_temp_limit)
|
||||
{
|
||||
int res;
|
||||
float tmp;
|
||||
|
||||
if (!over_temp_limit)
|
||||
return SETT_LOAD_ERR;
|
||||
|
||||
if (!settings_use_eeprom)
|
||||
return SETT_LOAD_FILE_NOT_FOUND;
|
||||
|
||||
res = settings_eeprom_load_overtemp_limit(&tmp);
|
||||
if (res)
|
||||
return SETT_LOAD_DISK_ERR;
|
||||
*over_temp_limit = tmp;
|
||||
|
||||
return SETT_LOAD_SUCCESS;
|
||||
}
|
||||
|
||||
int settings_save_overtemp_limit(float over_temp_limit, bool active)
|
||||
{
|
||||
if (settings_use_eeprom)
|
||||
return settings_eeprom_save_overtemp_limit(over_temp_limit, active);
|
||||
else
|
||||
return -100;
|
||||
}
|
||||
|
Reference in New Issue
Block a user