From 55a11ec9805b7ec0018ec8a000d7a5c5294fb022 Mon Sep 17 00:00:00 2001 From: Robin Dietzel Date: Fri, 13 Jan 2023 14:50:50 +0100 Subject: [PATCH] FEATURE: impl refill pump cooldown logic --- Core/Inc/git_rev.h | 2 +- Core/Src/main.cpp | 60 +++++++++++++++++++++++++++++++++------------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/Core/Inc/git_rev.h b/Core/Inc/git_rev.h index af57a17..d4b8e5e 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 "cf1254c" +#define GIT_HASH "9b50d90" #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 7547611..547ac08 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -52,6 +52,7 @@ bool S_backlight = false; bool S_tankempty = true; bool S_refilling = false; bool S_refillempty = true; +uint32_t S_refillcooldown = 0; void CheckTankConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io::RelayChannel &tankPump) { //Check if config says relay works inverted @@ -69,28 +70,47 @@ void CheckTankConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io:: void CheckRefillConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io::GPIChannel &refillBlock, io::RelayChannel &refillPump) { + static uint32_t c_RefillCooldown = 0; + static bool c_LastState = false; bool rblock = (cfg.RefillBlockInvert.getValue()) ? !refillBlock.getStateBool() : refillBlock.getStateBool(); + if (cfg.RefillEnable.getValue()) { //Check whether refilling is necessary - if (tankLevel.getPercent() < cfg.RefillBelow.getValue()) { - if (cfg.RefillBlockEnable.getValue() && !rblock) { - refillPump.switchRelay(io::RelayChannel::state::ON); - S_refilling = true; - S_refillempty = false; - } else if (rblock) { + + if(HAL_GetTick() > (c_RefillCooldown + (cfg.RefillCooldown.getValue() * 60*1000))) { + if (tankLevel.getPercent() < cfg.RefillBelow.getValue()) { + if (cfg.RefillBlockEnable.getValue() && !rblock) { + refillPump.switchRelay(io::RelayChannel::state::ON); + c_LastState = true; + S_refilling = true; + S_refillempty = false; + } else if (rblock) { + refillPump.switchRelay(io::RelayChannel::state::OFF); + S_refilling = false; + S_refillempty = true; + //Reset cooldown only if it was previously on + if(c_LastState) + c_RefillCooldown = HAL_GetTick(); + c_LastState = false; + } else { + refillPump.switchRelay(io::RelayChannel::state::ON); + c_LastState = true; + S_refilling = true; + S_refillempty = false; + } + } else if (tankLevel.getPercent() > cfg.RefillBelow.getValue() + cfg.RefillHysteresis.getValue()) { refillPump.switchRelay(io::RelayChannel::state::OFF); S_refilling = false; - S_refillempty = true; - } else { - refillPump.switchRelay(io::RelayChannel::state::ON); - S_refilling = true; S_refillempty = false; + if(c_LastState) + c_RefillCooldown = HAL_GetTick(); + c_LastState = false; } - } else if (tankLevel.getPercent() > cfg.RefillBelow.getValue() + cfg.RefillHysteresis.getValue()) { + } else { + HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin); refillPump.switchRelay(io::RelayChannel::state::OFF); - S_refilling = false; - S_refillempty = false; + S_refillcooldown = (((c_RefillCooldown + (cfg.RefillCooldown.getValue() * 60*1000)) - HAL_GetTick()) / 1000); } } else { refillPump.switchRelay(io::RelayChannel::state::OFF); @@ -196,12 +216,16 @@ int main(void) { menu::Menu_Entry refillBelow(t_RefillBelow, "Auff. bis"); menu::Menu_Entry refillHysteresis(t_RefillHysteresis, "Hysterese"); + menu::Menu_Entry_Type_Numeric t_RefillCooldown(10); + t_RefillCooldown.linkConfig(reinterpret_cast(globalConfig.RefillCooldown.getLink())); + menu::Menu_Entry refillCooldown(t_RefillCooldown, "Wartezeit"); + refillmenu.addEntry(refillEnable); refillmenu.addEntry(refillBlock); refillmenu.addEntry(refillBlockInvert); refillmenu.addEntry(refillBelow); refillmenu.addEntry(refillHysteresis); - + refillmenu.addEntry(refillCooldown); menu::Menu mainmenu("Hauptmenu"); mainmenu.addSubmenu(&tankmenu); @@ -262,15 +286,19 @@ int main(void) { } - display.LCDSetCursor(0, 3); + /*display.LCDSetCursor(0, 3); if (S_refillempty) { display.LCDSendCString(const_cast(std::string("Nachspeisung mangel ").c_str())); HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); } else { display.LCDSendCString(const_cast(std::string("Nachspeisung ok ").c_str())); HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET); - } + }*/ + display.LCDSetCursor(0, 3); + //if (S_refillcooldown > 0) { + display.LCDSendCString(const_cast(std::string("Cooldown: " + std::to_string(S_refillcooldown) + "s").c_str())); + //} //Check for rotation to enable display backlight if (old_pos < rot_counter) {