From 2c47d7385bad921217dc6c033dcf647a4a72ad38 Mon Sep 17 00:00:00 2001 From: Robin Dietzel Date: Thu, 26 Jan 2023 14:46:36 +0100 Subject: [PATCH] Designed config store as singleton --- Core/Inc/git_rev.h | 2 +- Core/Src/main.cpp | 35 +++++++++++----------- Middlewares/floatpump/Inc/Config_Store.h | 30 ++++++++++++++----- Middlewares/floatpump/Src/Config_Store.cpp | 2 -- 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/Core/Inc/git_rev.h b/Core/Inc/git_rev.h index 6303431..9885801 100644 --- a/Core/Inc/git_rev.h +++ b/Core/Inc/git_rev.h @@ -7,6 +7,6 @@ // Auto generated header file containing the last git revision -#define GIT_HASH "5f98ee9" +#define GIT_HASH "af8a022" #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H \ No newline at end of file diff --git a/Core/Src/main.cpp b/Core/Src/main.cpp index 1eb5992..45db930 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -136,8 +136,7 @@ int main(void) { HAL_NVIC_EnableIRQ(TIM2_IRQn); //Restore configuration - Config_Store globalConfig; - globalConfig.loadFromFlash(); + Config_Store::getInstance().loadFromFlash(); //Run init Sequence InitSequence initializer(display); @@ -151,25 +150,25 @@ int main(void) { tankmenu.addEntry(&a_caliblow, "Kal. Unt. Punkt"); tankmenu.addEntry(&a_calibhigh, "Kal. Ob. Punkt"); - tankmenu.addEntry(globalConfig.TankCalibLow.getLink(), "K Unten"); - tankmenu.addEntry(globalConfig.TankCalibHigh.getLink(), "K Oben"); + tankmenu.addEntry(Config_Store::getInstance().TankCalibLow.getLink(), "K Unten"); + tankmenu.addEntry(Config_Store::getInstance().TankCalibHigh.getLink(), "K Oben"); - tankmenu.addEntry(globalConfig.TankMinLevel.getLink(), "Min. Fuellst."); - tankmenu.addEntry(globalConfig.TankHysteresis.getLink(), "Hysterese"); + tankmenu.addEntry(Config_Store::getInstance().TankMinLevel.getLink(), "Min. Fuellst."); + tankmenu.addEntry(Config_Store::getInstance().TankHysteresis.getLink(), "Hysterese"); - tankmenu.addEntry(globalConfig.TankPumpInvert.getLink(), "Inv Relais"); + tankmenu.addEntry(Config_Store::getInstance().TankPumpInvert.getLink(), "Inv Relais"); Menu refillmenu("Nachspeisung"); - refillmenu.addEntry(globalConfig.RefillEnable.getLink(), "Nachsp. akt."); - refillmenu.addEntry(globalConfig.RefillBlockEnable.getLink(), "Notabschalt."); - refillmenu.addEntry(globalConfig.RefillBlockInvert.getLink(), "NotAbs. Inv."); + refillmenu.addEntry(Config_Store::getInstance().RefillEnable.getLink(), "Nachsp. akt."); + refillmenu.addEntry(Config_Store::getInstance().RefillBlockEnable.getLink(), "Notabschalt."); + refillmenu.addEntry(Config_Store::getInstance().RefillBlockInvert.getLink(), "NotAbs. Inv."); - refillmenu.addEntry(globalConfig.RefillBelow.getLink(), "Auff. bis"); - refillmenu.addEntry(globalConfig.RefillHysteresis.getLink(), "Hysterese"); + refillmenu.addEntry(Config_Store::getInstance().RefillBelow.getLink(), "Auff. bis"); + refillmenu.addEntry(Config_Store::getInstance().RefillHysteresis.getLink(), "Hysterese"); - refillmenu.addEntry(globalConfig.RefillCooldown.getLink(), "Wartezeit"); + refillmenu.addEntry(Config_Store::getInstance().RefillCooldown.getLink(), "Wartezeit"); Menu mainmenu("Hauptmenu"); @@ -180,7 +179,7 @@ int main(void) { //Instantiate Input and Output modules 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::RelayChannel tankPump(OCHAN0_GPIO_Port, OCHAN0_Pin, true, io::RelayChannel::state::OFF); @@ -300,10 +299,10 @@ int main(void) { //Store or restore if necessary if (f_store) { - globalConfig.saveToFlash(); + Config_Store::getInstance().saveToFlash(); f_store = false; } else if (f_restore) { - globalConfig.loadFromFlash(); + Config_Store::getInstance().loadFromFlash(); f_restore = false; } @@ -321,8 +320,8 @@ int main(void) { refillBlocker0.poll(); //Check conditions - CheckTankConditions(globalConfig, tankLevel0, tankPump); - CheckRefillConditions(globalConfig, tankLevel0, refillBlocker0, refillPump); + CheckTankConditions(Config_Store::getInstance(), tankLevel0, tankPump); + CheckRefillConditions(Config_Store::getInstance(), tankLevel0, refillBlocker0, refillPump); HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET); HAL_Delay(1000); diff --git a/Middlewares/floatpump/Inc/Config_Store.h b/Middlewares/floatpump/Inc/Config_Store.h index 194c7c3..b525346 100644 --- a/Middlewares/floatpump/Inc/Config_Store.h +++ b/Middlewares/floatpump/Inc/Config_Store.h @@ -11,9 +11,7 @@ namespace floatpump { class Config_Store { - public: - Config_Store(); - + private: const uint32_t startAddr = 0x08060000; static uint32_t StoreInFlash(uint32_t StartAddress, uint32_t *Data, uint16_t nData) { @@ -43,6 +41,24 @@ namespace floatpump { 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() { uint32_t data[11]; data[0] = TankCalibLow.getValue(); @@ -105,9 +121,9 @@ namespace floatpump { Config_Object TankCalibHigh = Config_Object(65535); Config_Object TankMinLevel = Config_Object(20); Config_Object TankHysteresis = Config_Object(5); - Config_Object TankCooldown = Config_Object(5); - Config_Object TankZeroLevelCM = Config_Object(0); - Config_Object TankFullLevelCM = Config_Object(200); + //Config_Object TankCooldown = Config_Object(5); + //Config_Object TankZeroLevelCM = Config_Object(0); + //Config_Object TankFullLevelCM = Config_Object(200); Config_Object TankPumpInvert = Config_Object(false); Config_Object RefillEnable = Config_Object(false); @@ -115,7 +131,7 @@ namespace floatpump { Config_Object RefillBlockEnable = Config_Object(true); Config_Object RefillBelow = Config_Object(false); Config_Object RefillHysteresis = Config_Object(false); - Config_Object RefillCooldown = Config_Object(60); + Config_Object RefillCooldown = Config_Object(60); }; } // floatpump diff --git a/Middlewares/floatpump/Src/Config_Store.cpp b/Middlewares/floatpump/Src/Config_Store.cpp index ea04a19..4978635 100644 --- a/Middlewares/floatpump/Src/Config_Store.cpp +++ b/Middlewares/floatpump/Src/Config_Store.cpp @@ -5,7 +5,5 @@ #include "Config_Store.h" namespace floatpump { - Config_Store::Config_Store() { - } } // floatpump \ No newline at end of file