FEATURE: impl refill pump cooldown logic

This commit is contained in:
Robin Dietzel 2023-01-13 14:50:50 +01:00
parent c994c1bd0d
commit 55a11ec980
2 changed files with 45 additions and 17 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 "cf1254c" #define GIT_HASH "9b50d90"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -52,6 +52,7 @@ bool S_backlight = false;
bool S_tankempty = true; bool S_tankempty = true;
bool S_refilling = false; bool S_refilling = false;
bool S_refillempty = true; bool S_refillempty = true;
uint32_t S_refillcooldown = 0;
void CheckTankConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io::RelayChannel &tankPump) { void CheckTankConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io::RelayChannel &tankPump) {
//Check if config says relay works inverted //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, void CheckRefillConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io::GPIChannel &refillBlock,
io::RelayChannel &refillPump) { io::RelayChannel &refillPump) {
static uint32_t c_RefillCooldown = 0;
static bool c_LastState = false;
bool rblock = (cfg.RefillBlockInvert.getValue()) ? !refillBlock.getStateBool() : refillBlock.getStateBool(); bool rblock = (cfg.RefillBlockInvert.getValue()) ? !refillBlock.getStateBool() : refillBlock.getStateBool();
if (cfg.RefillEnable.getValue()) { if (cfg.RefillEnable.getValue()) {
//Check whether refilling is necessary //Check whether refilling is necessary
if (tankLevel.getPercent() < cfg.RefillBelow.getValue()) {
if (cfg.RefillBlockEnable.getValue() && !rblock) { if(HAL_GetTick() > (c_RefillCooldown + (cfg.RefillCooldown.getValue() * 60*1000))) {
refillPump.switchRelay(io::RelayChannel::state::ON); if (tankLevel.getPercent() < cfg.RefillBelow.getValue()) {
S_refilling = true; if (cfg.RefillBlockEnable.getValue() && !rblock) {
S_refillempty = false; refillPump.switchRelay(io::RelayChannel::state::ON);
} else if (rblock) { 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); refillPump.switchRelay(io::RelayChannel::state::OFF);
S_refilling = false; S_refilling = false;
S_refillempty = true;
} else {
refillPump.switchRelay(io::RelayChannel::state::ON);
S_refilling = true;
S_refillempty = false; 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); refillPump.switchRelay(io::RelayChannel::state::OFF);
S_refilling = false; S_refillcooldown = (((c_RefillCooldown + (cfg.RefillCooldown.getValue() * 60*1000)) - HAL_GetTick()) / 1000);
S_refillempty = false;
} }
} else { } else {
refillPump.switchRelay(io::RelayChannel::state::OFF); refillPump.switchRelay(io::RelayChannel::state::OFF);
@ -196,12 +216,16 @@ int main(void) {
menu::Menu_Entry refillBelow(t_RefillBelow, "Auff. bis"); menu::Menu_Entry refillBelow(t_RefillBelow, "Auff. bis");
menu::Menu_Entry refillHysteresis(t_RefillHysteresis, "Hysterese"); menu::Menu_Entry refillHysteresis(t_RefillHysteresis, "Hysterese");
menu::Menu_Entry_Type_Numeric t_RefillCooldown(10);
t_RefillCooldown.linkConfig(reinterpret_cast<uint16_t *>(globalConfig.RefillCooldown.getLink()));
menu::Menu_Entry refillCooldown(t_RefillCooldown, "Wartezeit");
refillmenu.addEntry(refillEnable); refillmenu.addEntry(refillEnable);
refillmenu.addEntry(refillBlock); refillmenu.addEntry(refillBlock);
refillmenu.addEntry(refillBlockInvert); refillmenu.addEntry(refillBlockInvert);
refillmenu.addEntry(refillBelow); refillmenu.addEntry(refillBelow);
refillmenu.addEntry(refillHysteresis); refillmenu.addEntry(refillHysteresis);
refillmenu.addEntry(refillCooldown);
menu::Menu mainmenu("Hauptmenu"); menu::Menu mainmenu("Hauptmenu");
mainmenu.addSubmenu(&tankmenu); mainmenu.addSubmenu(&tankmenu);
@ -262,15 +286,19 @@ int main(void) {
} }
display.LCDSetCursor(0, 3); /*display.LCDSetCursor(0, 3);
if (S_refillempty) { if (S_refillempty) {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung mangel ").c_str())); display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung mangel ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
} else { } else {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung ok ").c_str())); display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung ok ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET);
} }*/
display.LCDSetCursor(0, 3);
//if (S_refillcooldown > 0) {
display.LCDSendCString(const_cast<char *>(std::string("Cooldown: " + std::to_string(S_refillcooldown) + "s").c_str()));
//}
//Check for rotation to enable display backlight //Check for rotation to enable display backlight
if (old_pos < rot_counter) { if (old_pos < rot_counter) {