From 33ab5406534f9a0f9ff5c87d0ed1e7263d339537 Mon Sep 17 00:00:00 2001 From: Robin Dietzel Date: Fri, 3 Feb 2023 12:46:17 +0100 Subject: [PATCH] FEATURE: new correct initial configuration after flashing with full chip erase --- .../Middlewares/floatpump/Inc/Config_Store.h | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/floatpump/Middlewares/floatpump/Inc/Config_Store.h b/floatpump/Middlewares/floatpump/Inc/Config_Store.h index b525346..fa24fda 100644 --- a/floatpump/Middlewares/floatpump/Inc/Config_Store.h +++ b/floatpump/Middlewares/floatpump/Inc/Config_Store.h @@ -60,7 +60,7 @@ namespace floatpump { void saveToFlash() { - uint32_t data[11]; + uint32_t data[12]; data[0] = TankCalibLow.getValue(); data[1] = TankCalibHigh.getValue(); data[2] = TankMinLevel.getValue(); @@ -72,28 +72,48 @@ namespace floatpump { data[8] = RefillBelow.getValue(); data[9] = RefillHysteresis.getValue(); data[10] = RefillCooldown.getValue(); + data[11] = 0xf0f0; - StoreInFlash(startAddr, data, 11); + StoreInFlash(startAddr, data, 12); return; }; void resetDefaults(); void loadFromFlash() { - uint32_t data[11]; - ReadFromFlash(startAddr, data, 11); - 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]); - RefillCooldown.setValue(data[10]); - return; + uint32_t data[12]; + ReadFromFlash(startAddr, data, 12); + + //Check if intial values must be loaded + if(data[11] == 0xf0f0) { + 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]); + RefillCooldown.setValue(data[10]); + return; + } else { + //Set default values for fist initialization only + //TODO: refactor this, maybe edit linker script to initially store values to correct flash location + TankCalibLow.setValue(0); + TankCalibHigh.setValue(10000); + TankMinLevel.setValue(25); + TankHysteresis.setValue(5); + TankPumpInvert.setValue(1); + RefillEnable.setValue(0); + RefillBlockInvert.setValue(0); + RefillBlockEnable.setValue(1); + RefillBelow.setValue(35); + RefillHysteresis.setValue(5); + RefillCooldown.setValue(5); + saveToFlash(); + } }; template