Designed config store as singleton

This commit is contained in:
Robin Dietzel 2023-01-26 14:46:36 +01:00
parent df4b34545e
commit 2c47d7385b
4 changed files with 41 additions and 28 deletions

View File

@ -7,6 +7,6 @@
// Auto generated header file containing the last git revision // Auto generated header file containing the last git revision
#define GIT_HASH "5f98ee9" #define GIT_HASH "af8a022"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -136,8 +136,7 @@ int main(void) {
HAL_NVIC_EnableIRQ(TIM2_IRQn); HAL_NVIC_EnableIRQ(TIM2_IRQn);
//Restore configuration //Restore configuration
Config_Store globalConfig; Config_Store::getInstance().loadFromFlash();
globalConfig.loadFromFlash();
//Run init Sequence //Run init Sequence
InitSequence initializer(display); InitSequence initializer(display);
@ -151,25 +150,25 @@ int main(void) {
tankmenu.addEntry<MenuEntryExecute>(&a_caliblow, "Kal. Unt. Punkt"); tankmenu.addEntry<MenuEntryExecute>(&a_caliblow, "Kal. Unt. Punkt");
tankmenu.addEntry<MenuEntryExecute>(&a_calibhigh, "Kal. Ob. Punkt"); tankmenu.addEntry<MenuEntryExecute>(&a_calibhigh, "Kal. Ob. Punkt");
tankmenu.addEntry<MenuEntryNumeric>(globalConfig.TankCalibLow.getLink(), "K Unten"); tankmenu.addEntry<MenuEntryNumeric>(Config_Store::getInstance().TankCalibLow.getLink(), "K Unten");
tankmenu.addEntry<MenuEntryNumeric>(globalConfig.TankCalibHigh.getLink(), "K Oben"); tankmenu.addEntry<MenuEntryNumeric>(Config_Store::getInstance().TankCalibHigh.getLink(), "K Oben");
tankmenu.addEntry<MenuEntryPercent>(globalConfig.TankMinLevel.getLink(), "Min. Fuellst."); tankmenu.addEntry<MenuEntryPercent>(Config_Store::getInstance().TankMinLevel.getLink(), "Min. Fuellst.");
tankmenu.addEntry<MenuEntryPercent>(globalConfig.TankHysteresis.getLink(), "Hysterese"); tankmenu.addEntry<MenuEntryPercent>(Config_Store::getInstance().TankHysteresis.getLink(), "Hysterese");
tankmenu.addEntry<MenuEntryCheckable>(globalConfig.TankPumpInvert.getLink(), "Inv Relais"); tankmenu.addEntry<MenuEntryCheckable>(Config_Store::getInstance().TankPumpInvert.getLink(), "Inv Relais");
Menu refillmenu("Nachspeisung"); Menu refillmenu("Nachspeisung");
refillmenu.addEntry<MenuEntryCheckable>(globalConfig.RefillEnable.getLink(), "Nachsp. akt."); refillmenu.addEntry<MenuEntryCheckable>(Config_Store::getInstance().RefillEnable.getLink(), "Nachsp. akt.");
refillmenu.addEntry<MenuEntryCheckable>(globalConfig.RefillBlockEnable.getLink(), "Notabschalt."); refillmenu.addEntry<MenuEntryCheckable>(Config_Store::getInstance().RefillBlockEnable.getLink(), "Notabschalt.");
refillmenu.addEntry<MenuEntryCheckable>(globalConfig.RefillBlockInvert.getLink(), "NotAbs. Inv."); refillmenu.addEntry<MenuEntryCheckable>(Config_Store::getInstance().RefillBlockInvert.getLink(), "NotAbs. Inv.");
refillmenu.addEntry<MenuEntryPercent>(globalConfig.RefillBelow.getLink(), "Auff. bis"); refillmenu.addEntry<MenuEntryPercent>(Config_Store::getInstance().RefillBelow.getLink(), "Auff. bis");
refillmenu.addEntry<MenuEntryPercent>(globalConfig.RefillHysteresis.getLink(), "Hysterese"); refillmenu.addEntry<MenuEntryPercent>(Config_Store::getInstance().RefillHysteresis.getLink(), "Hysterese");
refillmenu.addEntry<MenuEntryNumeric>(globalConfig.RefillCooldown.getLink(), "Wartezeit"); refillmenu.addEntry<MenuEntryNumeric>(Config_Store::getInstance().RefillCooldown.getLink(), "Wartezeit");
Menu mainmenu("Hauptmenu"); Menu mainmenu("Hauptmenu");
@ -180,7 +179,7 @@ int main(void) {
//Instantiate Input and Output modules //Instantiate Input and Output modules
io::PressureChannel tankLevel0(&hadc1, MPWR0_GPIO_Port, MPWR0_Pin, 50); io::PressureChannel tankLevel0(&hadc1, MPWR0_GPIO_Port, MPWR0_Pin, 50);
tankLevel0.LinkCalibConfig(globalConfig.TankCalibLow.getLink(), globalConfig.TankCalibHigh.getLink()); tankLevel0.LinkCalibConfig(Config_Store::getInstance().TankCalibLow.getLink(), Config_Store::getInstance().TankCalibHigh.getLink());
io::GPIChannel refillBlocker0(GPI0_GPIO_Port, GPI0_Pin); io::GPIChannel refillBlocker0(GPI0_GPIO_Port, GPI0_Pin);
io::RelayChannel tankPump(OCHAN0_GPIO_Port, OCHAN0_Pin, true, io::RelayChannel::state::OFF); io::RelayChannel tankPump(OCHAN0_GPIO_Port, OCHAN0_Pin, true, io::RelayChannel::state::OFF);
@ -300,10 +299,10 @@ int main(void) {
//Store or restore if necessary //Store or restore if necessary
if (f_store) { if (f_store) {
globalConfig.saveToFlash(); Config_Store::getInstance().saveToFlash();
f_store = false; f_store = false;
} else if (f_restore) { } else if (f_restore) {
globalConfig.loadFromFlash(); Config_Store::getInstance().loadFromFlash();
f_restore = false; f_restore = false;
} }
@ -321,8 +320,8 @@ int main(void) {
refillBlocker0.poll(); refillBlocker0.poll();
//Check conditions //Check conditions
CheckTankConditions(globalConfig, tankLevel0, tankPump); CheckTankConditions(Config_Store::getInstance(), tankLevel0, tankPump);
CheckRefillConditions(globalConfig, tankLevel0, refillBlocker0, refillPump); CheckRefillConditions(Config_Store::getInstance(), tankLevel0, refillBlocker0, refillPump);
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
HAL_Delay(1000); HAL_Delay(1000);

View File

@ -11,9 +11,7 @@
namespace floatpump { namespace floatpump {
class Config_Store { class Config_Store {
public: private:
Config_Store();
const uint32_t startAddr = 0x08060000; const uint32_t startAddr = 0x08060000;
static uint32_t StoreInFlash(uint32_t StartAddress, uint32_t *Data, uint16_t nData) { static uint32_t StoreInFlash(uint32_t StartAddress, uint32_t *Data, uint16_t nData) {
@ -43,6 +41,24 @@ namespace floatpump {
return 0; return 0;
} }
Config_Store() = default;
Config_Store(Config_Store const &) = delete;
Config_Store(Config_Store const &&) = delete;
void operator=(Config_Store const &) = delete;
void operator=(Config_Store const &&) = delete;
public:
static Config_Store &getInstance() {
static Config_Store instance;
return instance;
}
void saveToFlash() { void saveToFlash() {
uint32_t data[11]; uint32_t data[11];
data[0] = TankCalibLow.getValue(); data[0] = TankCalibLow.getValue();
@ -105,9 +121,9 @@ namespace floatpump {
Config_Object<uint16_t> TankCalibHigh = Config_Object<uint16_t>(65535); Config_Object<uint16_t> TankCalibHigh = Config_Object<uint16_t>(65535);
Config_Object<uint8_t> TankMinLevel = Config_Object<uint8_t>(20); Config_Object<uint8_t> TankMinLevel = Config_Object<uint8_t>(20);
Config_Object<uint8_t> TankHysteresis = Config_Object<uint8_t>(5); Config_Object<uint8_t> TankHysteresis = Config_Object<uint8_t>(5);
Config_Object<uint32_t> TankCooldown = Config_Object<uint32_t>(5); //Config_Object<uint32_t> TankCooldown = Config_Object<uint32_t>(5);
Config_Object<uint32_t> TankZeroLevelCM = Config_Object<uint32_t>(0); //Config_Object<uint32_t> TankZeroLevelCM = Config_Object<uint32_t>(0);
Config_Object<uint32_t> TankFullLevelCM = Config_Object<uint32_t>(200); //Config_Object<uint32_t> TankFullLevelCM = Config_Object<uint32_t>(200);
Config_Object<bool> TankPumpInvert = Config_Object<bool>(false); Config_Object<bool> TankPumpInvert = Config_Object<bool>(false);
Config_Object<bool> RefillEnable = Config_Object<bool>(false); Config_Object<bool> RefillEnable = Config_Object<bool>(false);
@ -115,7 +131,7 @@ namespace floatpump {
Config_Object<bool> RefillBlockEnable = Config_Object<bool>(true); Config_Object<bool> RefillBlockEnable = Config_Object<bool>(true);
Config_Object<uint8_t> RefillBelow = Config_Object<uint8_t>(false); Config_Object<uint8_t> RefillBelow = Config_Object<uint8_t>(false);
Config_Object<uint8_t> RefillHysteresis = Config_Object<uint8_t>(false); Config_Object<uint8_t> RefillHysteresis = Config_Object<uint8_t>(false);
Config_Object <uint16_t> RefillCooldown = Config_Object<uint16_t>(60); Config_Object<uint16_t> RefillCooldown = Config_Object<uint16_t>(60);
}; };
} // floatpump } // floatpump

View File

@ -5,7 +5,5 @@
#include "Config_Store.h" #include "Config_Store.h"
namespace floatpump { namespace floatpump {
Config_Store::Config_Store() {
}
} // floatpump } // floatpump