FEATURE: Pump status with leds

This commit is contained in:
Robin Dietzel 2023-01-13 13:40:30 +01:00
parent 02c604021a
commit 503675d46b
2 changed files with 66 additions and 24 deletions

View File

@ -7,6 +7,6 @@
// Auto generated header file containing the last git revision
#define GIT_HASH "df5aa6f"
#define GIT_HASH "79077af"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -47,29 +47,50 @@ extern bool rot_button;
using namespace floatpump;
bool S_backlight = false;
bool S_tankempty = true;
bool S_refilling = false;
bool S_refillempty = true;
void CheckTankConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io::RelayChannel &tankPump) {
//Check if config says relay works inverted
tankPump.setInverted(cfg.TankPumpInvert.getValue());
//First check if Tank has enough water and disable pump if necessary
if(tankLevel.getPercent() < cfg.TankMinLevel.getValue()) {
if (tankLevel.getPercent() < cfg.TankMinLevel.getValue()) {
tankPump.switchRelay(io::RelayChannel::state::OFF);
} else if(tankLevel.getPercent() > cfg.TankMinLevel.getValue() + cfg.TankHysteresis.getValue()) {
S_tankempty = true;
} else if (tankLevel.getPercent() > cfg.TankMinLevel.getValue() + cfg.TankHysteresis.getValue()) {
tankPump.switchRelay(io::RelayChannel::state::ON);
S_tankempty = false;
}
}
void CheckRefillConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io::GPIChannel &refillBlock, io::RelayChannel &refillPump) {
if(cfg.RefillEnable.getValue()) {
void CheckRefillConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io::GPIChannel &refillBlock,
io::RelayChannel &refillPump) {
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() && !refillBlock.getStateBool()) {
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) {
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;
}
} else if (tankLevel.getPercent() > cfg.RefillBelow.getValue() + cfg.RefillHysteresis.getValue()) {
refillPump.switchRelay(io::RelayChannel::state::OFF);
S_refilling = false;
S_refillempty = false;
}
} else {
refillPump.switchRelay(io::RelayChannel::state::OFF);
@ -79,6 +100,7 @@ void CheckRefillConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io
int main(void) {
Config_Store globalConfig;
globalConfig.loadFromFlash();
// Step 1: Initialize HAL
HAL_Init();
@ -106,13 +128,10 @@ int main(void) {
InitSequence initializer(display);
initializer.runInitSequence();
//Enable green led
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET);
///
///
/// EXPERIMENTAL CODE BEGIN
/// LOGICAL CODE BEGIN
///
///
///
@ -184,7 +203,6 @@ int main(void) {
refillmenu.addEntry(refillHysteresis);
menu::Menu mainmenu("Hauptmenu");
mainmenu.addSubmenu(&tankmenu);
mainmenu.addSubmenu(&refillmenu);
@ -201,6 +219,7 @@ int main(void) {
io::RelayChannel refillPump(OCHAN1_GPIO_Port, OCHAN1_Pin, false, io::RelayChannel::state::OFF);
uint32_t last_menu_retrigger = 0;
uint32_t last_backlight_retrigger = 0;
bool f_store = false, f_restore = false;
menu::Menu_Entry_Type_Execute t_MStore;
@ -216,27 +235,51 @@ int main(void) {
while (1) {
display.LCDSetBacklight(false);
display.LCDSetCursor(0,0);
display.LCDSendCString(const_cast<char *>(std::string("Tank: " + std::to_string(tankLevel0.getPercent()) + " %").c_str()));
display.LCDSetBacklight(S_backlight);
display.LCDSetCursor(0, 0);
display.LCDSendCString(
const_cast<char *>(std::string("Tank: " + std::to_string(tankLevel0.getPercent()) + " %").c_str()));
display.LCDSetCursor(0, 1);
if(tankLevel0.getPercent() < globalConfig.TankMinLevel.getValue()) {
if (S_tankempty) {
display.LCDSendCString(const_cast<char *>(std::string("Tank Wassermangel ").c_str()));
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_SET);
} else {
display.LCDSendCString(const_cast<char *>(std::string("Tank Normal ").c_str()));
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET);
}
display.LCDSetCursor(0,2);
display.LCDSetCursor(0, 2);
if (S_refilling) {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung laeuft ").c_str()));
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_RESET);
}
else {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung inaktiv").c_str()));
HAL_GPIO_WritePin(LED4_GPIO_Port, LED4_Pin, GPIO_PIN_SET);
}
display.LCDSetCursor(0, 3);
if (S_refillempty) {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung mangel ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);
}
else {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung ok ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_SET);
}
if(rot_button) {
if (rot_button) {
display.LCDSetBacklight(true);
rot_button = false;
last_menu_retrigger = HAL_GetTick();
while(true) {
while (true) {
//Display menu until timeout
controller.execute();
if (rot_button) {
@ -257,7 +300,7 @@ int main(void) {
HAL_Delay(100);
//Execute Calibrations if necessary
if(a_caliblow) {
if (a_caliblow) {
tankLevel0.calibrateLow();
controller.execute();
HAL_Delay(2000);
@ -270,7 +313,7 @@ int main(void) {
}
//Store or restore if necessary
if(f_store) {
if (f_store) {
globalConfig.saveToFlash();
f_store = false;
} else if (f_restore) {
@ -278,7 +321,7 @@ int main(void) {
f_restore = false;
}
if(HAL_GetTick() > last_menu_retrigger + 10000) {
if (HAL_GetTick() > last_menu_retrigger + 10000) {
display.LCDClearDisplay();
break;
}
@ -300,7 +343,6 @@ int main(void) {
}
void SystemClock_Config(void) {
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};