This commit is contained in:
Candas1 2021-01-03 02:12:33 +01:00
parent 0f6132a71e
commit 177d5d4dc1
2 changed files with 23 additions and 4 deletions

View File

@ -149,7 +149,9 @@ uint8_t initValue(uint8_t index);
uint32_t getValue(uint8_t index); uint32_t getValue(uint8_t index);
uint8_t incrValue(uint8_t index); uint8_t incrValue(uint8_t index);
uint8_t saveValue(uint8_t index); uint8_t saveValue(uint8_t index);
void dumpValues(); void saveAllParams();
void dumpParamValues();
void dumpParameters();
typedef struct parameter_entry_struct parameter_entry; typedef struct parameter_entry_struct parameter_entry;
struct parameter_entry_struct { struct parameter_entry_struct {

View File

@ -262,7 +262,7 @@ parameter_entry params[] = {
uint8_t setParam(uint8_t index, int32_t newValue) { uint8_t setParam(uint8_t index, int32_t newValue) {
// Only Parameters can be set // Only Parameters can be set
if (params[index].parameter_type == VARIABLE) return 1; if (params[index].parameter_type == VARIABLE) return 0;
int32_t value = newValue; int32_t value = newValue;
// check mean and max before conversion to internal values // check mean and max before conversion to internal values
@ -310,6 +310,8 @@ uint8_t setParam(uint8_t index, int32_t newValue) {
} }
uint8_t initParam(uint8_t index) { uint8_t initParam(uint8_t index) {
// Only Parameters can be initialized
if (params[index].parameter_type == VARIABLE) return 0;
return setParam(index,(int32_t) params[index].init); return setParam(index,(int32_t) params[index].init);
} }
@ -362,6 +364,9 @@ void dumpParameters(){
} }
uint8_t incrParam(uint8_t index) { uint8_t incrParam(uint8_t index) {
// Only Parameters can be set
if (params[index].parameter_type == VARIABLE) return 0;
uint32_t value = getParam(index); uint32_t value = getParam(index);
if (value < params[index].max){ if (value < params[index].max){
return setParam(index,value + 1); return setParam(index,value + 1);
@ -371,16 +376,28 @@ uint8_t incrParam(uint8_t index) {
} }
uint8_t saveParam(uint8_t index) { uint8_t saveParam(uint8_t index) {
uint32_t value = getValue(index); // Only Parameters can be saved to EEPROM
if (params[index].parameter_type == VARIABLE) return 0;
if (params[index].addr){ if (params[index].addr){
HAL_FLASH_Unlock(); HAL_FLASH_Unlock();
EE_WriteVariable(VirtAddVarTab[params[index].addr] , (uint16_t)value); EE_WriteVariable(VirtAddVarTab[params[index].addr] , (uint16_t)getValue(index));
HAL_FLASH_Lock(); HAL_FLASH_Lock();
return 1; return 1;
} }
return 0; return 0;
} }
void saveAllParams() {
HAL_FLASH_Unlock();
for(int index=0;index<PARAM_SIZE(params);index++){
if (params[index].parameter_type != VARIABLE && params[index].addr){
EE_WriteVariable(VirtAddVarTab[params[index].addr] , (uint16_t)getValue(index));
}
}
HAL_FLASH_Lock();
}
/* =========================== Initialization Functions =========================== */ /* =========================== Initialization Functions =========================== */