FEATURE: full config store and restore
This commit is contained in:
parent
03a4180c9c
commit
7738e7d1ee
@ -7,6 +7,6 @@
|
||||
|
||||
// Auto generated header file containing the last git revision
|
||||
|
||||
#define GIT_HASH "5b2e03a"
|
||||
#define GIT_HASH "df5aa6f"
|
||||
|
||||
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H
|
@ -14,6 +14,8 @@ namespace floatpump {
|
||||
public:
|
||||
Config_Store();
|
||||
|
||||
const uint32_t startAddr = 0x08060000;
|
||||
|
||||
static uint32_t StoreInFlash(uint32_t StartAddress, uint32_t *Data, uint16_t nData) {
|
||||
uint16_t progr = 0;
|
||||
HAL_FLASH_Unlock();
|
||||
@ -21,11 +23,24 @@ namespace floatpump {
|
||||
while (progr < nData) {
|
||||
if (HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, StartAddress, Data[progr]) == HAL_OK) {
|
||||
progr++;
|
||||
StartAddress += 4; } else {
|
||||
StartAddress += 4;
|
||||
} else {
|
||||
return HAL_FLASH_GetError();
|
||||
}
|
||||
}
|
||||
HAL_FLASH_Lock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint32_t ReadFromFlash(uint32_t StartAddress, uint32_t *Data, uint16_t nData) {
|
||||
uint16_t progr = 0;
|
||||
|
||||
while (progr < nData) {
|
||||
Data[progr] = *(uint32_t *) StartAddress;
|
||||
progr++;
|
||||
StartAddress += 4;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void saveToFlash() {
|
||||
@ -41,13 +56,26 @@ namespace floatpump {
|
||||
data[8] = RefillBelow.getValue();
|
||||
data[9] = RefillHysteresis.getValue();
|
||||
|
||||
StoreInFlash(0x08060000, data, 10);
|
||||
StoreInFlash(startAddr, data, 10);
|
||||
return;
|
||||
};
|
||||
|
||||
void resetDefaults();
|
||||
|
||||
void loadFromFlash() {
|
||||
this->RefillBelow.setValue(*(uint32_t *)0x08060000);
|
||||
uint32_t data[10];
|
||||
ReadFromFlash(startAddr, data, 10);
|
||||
TankCalibLow.setValue(data[0]);
|
||||
TankCalibHigh.setValue(data[1]);
|
||||
TankMinLevel.setValue(data[2]);
|
||||
TankHysteresis.setValue(data[3]);
|
||||
TankPumpInvert.setValue(data[4]);
|
||||
RefillEnable.setValue(data[5]);
|
||||
RefillBlockInvert.setValue(data[6]);
|
||||
RefillBlockEnable.setValue(data[7]);
|
||||
RefillBelow.setValue(data[8]);
|
||||
RefillHysteresis.setValue(data[9]);
|
||||
return;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
|
Loading…
Reference in New Issue
Block a user