Designed config store as singleton
This commit is contained in:
parent
df4b34545e
commit
2c47d7385b
@ -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
|
@ -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<MenuEntryExecute>(&a_caliblow, "Kal. Unt. Punkt");
|
||||
tankmenu.addEntry<MenuEntryExecute>(&a_calibhigh, "Kal. Ob. Punkt");
|
||||
|
||||
tankmenu.addEntry<MenuEntryNumeric>(globalConfig.TankCalibLow.getLink(), "K Unten");
|
||||
tankmenu.addEntry<MenuEntryNumeric>(globalConfig.TankCalibHigh.getLink(), "K Oben");
|
||||
tankmenu.addEntry<MenuEntryNumeric>(Config_Store::getInstance().TankCalibLow.getLink(), "K Unten");
|
||||
tankmenu.addEntry<MenuEntryNumeric>(Config_Store::getInstance().TankCalibHigh.getLink(), "K Oben");
|
||||
|
||||
tankmenu.addEntry<MenuEntryPercent>(globalConfig.TankMinLevel.getLink(), "Min. Fuellst.");
|
||||
tankmenu.addEntry<MenuEntryPercent>(globalConfig.TankHysteresis.getLink(), "Hysterese");
|
||||
tankmenu.addEntry<MenuEntryPercent>(Config_Store::getInstance().TankMinLevel.getLink(), "Min. Fuellst.");
|
||||
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");
|
||||
|
||||
refillmenu.addEntry<MenuEntryCheckable>(globalConfig.RefillEnable.getLink(), "Nachsp. akt.");
|
||||
refillmenu.addEntry<MenuEntryCheckable>(globalConfig.RefillBlockEnable.getLink(), "Notabschalt.");
|
||||
refillmenu.addEntry<MenuEntryCheckable>(globalConfig.RefillBlockInvert.getLink(), "NotAbs. Inv.");
|
||||
refillmenu.addEntry<MenuEntryCheckable>(Config_Store::getInstance().RefillEnable.getLink(), "Nachsp. akt.");
|
||||
refillmenu.addEntry<MenuEntryCheckable>(Config_Store::getInstance().RefillBlockEnable.getLink(), "Notabschalt.");
|
||||
refillmenu.addEntry<MenuEntryCheckable>(Config_Store::getInstance().RefillBlockInvert.getLink(), "NotAbs. Inv.");
|
||||
|
||||
refillmenu.addEntry<MenuEntryPercent>(globalConfig.RefillBelow.getLink(), "Auff. bis");
|
||||
refillmenu.addEntry<MenuEntryPercent>(globalConfig.RefillHysteresis.getLink(), "Hysterese");
|
||||
refillmenu.addEntry<MenuEntryPercent>(Config_Store::getInstance().RefillBelow.getLink(), "Auff. bis");
|
||||
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");
|
||||
@ -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);
|
||||
|
@ -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<uint16_t> TankCalibHigh = Config_Object<uint16_t>(65535);
|
||||
Config_Object<uint8_t> TankMinLevel = Config_Object<uint8_t>(20);
|
||||
Config_Object<uint8_t> TankHysteresis = Config_Object<uint8_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> TankFullLevelCM = Config_Object<uint32_t>(200);
|
||||
//Config_Object<uint32_t> TankCooldown = Config_Object<uint32_t>(5);
|
||||
//Config_Object<uint32_t> TankZeroLevelCM = Config_Object<uint32_t>(0);
|
||||
//Config_Object<uint32_t> TankFullLevelCM = Config_Object<uint32_t>(200);
|
||||
Config_Object<bool> TankPumpInvert = Config_Object<bool>(false);
|
||||
|
||||
Config_Object<bool> RefillEnable = Config_Object<bool>(false);
|
||||
|
@ -5,7 +5,5 @@
|
||||
#include "Config_Store.h"
|
||||
|
||||
namespace floatpump {
|
||||
Config_Store::Config_Store() {
|
||||
|
||||
}
|
||||
} // floatpump
|
Loading…
Reference in New Issue
Block a user