WIP: simple business logic and their config

This commit is contained in:
Robin Dietzel 2023-01-10 16:11:03 +01:00
parent 74eceacf7e
commit 898471058d
3 changed files with 149 additions and 85 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 "a7d18ec" #define GIT_HASH "59fdd3a"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -17,6 +17,7 @@
#include "PressureChannel.h" #include "PressureChannel.h"
#include "RelayChannel.h" #include "RelayChannel.h"
#include "GPIChannel.h" #include "GPIChannel.h"
#include "Menu_Entry_Type_Execute.h"
#define SLAVE_ADDRESS_LCD 0x4e #define SLAVE_ADDRESS_LCD 0x4e
@ -86,113 +87,163 @@ int main(void) {
/// ///
/// ///
using namespace floatpump::menu; using namespace floatpump;
Menu mainmenu("Hauptmenu");
Menu_Entry_Type_Checkable entry1bool(false), entry2bool(false);
bool l_calib, h_calib = false;
uint8_t cur_perc = 0;
uint32_t current = 0;
uint16_t prescaler = 0;
uint32_t curCooldown = 0;
entry1bool.linkConfig(&l_calib);
entry2bool.linkConfig(&h_calib);
Menu_Entry entry(entry1bool, "Low Calib");
Menu_Entry entry2(entry2bool, "High Calib");
Menu_Entry_Type_Percent entry1perc(15);
Menu_Entry entry3(entry1perc, "Pegel Schalten");
Menu_Entry_Type_ReadOnly<uint32_t> entry1read(0);
entry1read.linkConfig(&current);
Menu_Entry entry4(entry1read, "Pegel");
Menu_Entry_Type_ReadOnly<uint8_t> entry2read(0);
entry2read.linkConfig(&cur_perc);
Menu_Entry entry5(entry2read, "Pegel Proz");
mainmenu.addEntry(entry);
mainmenu.addEntry(entry2);
mainmenu.addEntry(entry3);
mainmenu.addEntry(entry4);
mainmenu.addEntry(entry5);
Menu_Entry_Type_ReadOnly<uint32_t> cdd(0);
cdd.linkConfig(&curCooldown);
Menu_Entry entry6(cdd, "Cooldown");
Menu_Entry_Type_Checkable tr(false);
bool inputTest;
tr.linkConfig(&inputTest);
Menu_Entry entry7(tr, "Input");
mainmenu.addEntry(entry7);
Menu_Controller controller(&mainmenu, display); menu::Menu tankmenu("Tank");
floatpump::io::PressureChannel channel(&hadc1, MPWR0_GPIO_Port, MPWR0_Pin); bool a_caliblow, a_calibhigh = false;
floatpump::io::RelayChannel relay(OCHAN0_GPIO_Port, OCHAN0_Pin, false); menu::Menu_Entry_Type_Execute t_exCalibLow;
floatpump::io::GPIChannel swimmer(GPI0_GPIO_Port, GPI0_Pin, false); menu::Menu_Entry_Type_Execute t_exCalibHigh;
t_exCalibLow.linkConfig(&a_caliblow);
t_exCalibHigh.linkConfig(&a_calibhigh);
menu::Menu_Entry exCalibLow(t_exCalibLow, "Kal. Unt. Punkt");
menu::Menu_Entry exCalibHigh(t_exCalibHigh, "Kal. Unt. Punkt");
menu::Menu_Entry_Type_Numeric t_CalibLow(0);
menu::Menu_Entry_Type_Numeric t_CalibHigh(65535);
t_CalibLow.linkConfig(globalConfig.TankCalibLow.getLink());
t_CalibHigh.linkConfig(globalConfig.TankCalibHigh.getLink());
menu::Menu_Entry CalibLow(t_CalibLow, "K Unten");
menu::Menu_Entry CalibHigh(t_CalibHigh, "K Oben");
menu::Menu_Entry_Type_Percent t_tankLevel(25);
t_tankLevel.linkConfig(globalConfig.TankMinLevel.getLink());
menu::Menu_Entry TankLevel(t_tankLevel, "Min. Fuellst.");
menu::Menu_Entry_Type_Percent t_tankHysteresis(5);
t_tankHysteresis.linkConfig(globalConfig.TankHysteresis.getLink());
menu::Menu_Entry TankHysteresis(t_tankHysteresis, "Hysterese");
menu::Menu_Entry_Type_Checkable t_tankInvert(false);
t_tankInvert.linkConfig(globalConfig.TankPumpInvert.getLink());
menu::Menu_Entry TankInvert(t_tankInvert, "Inv. Relais");
tankmenu.addEntry(exCalibLow);
tankmenu.addEntry(exCalibHigh);
tankmenu.addEntry(CalibLow);
tankmenu.addEntry(CalibHigh);
tankmenu.addEntry(TankLevel);
tankmenu.addEntry(TankHysteresis);
tankmenu.addEntry(TankInvert);
menu::Menu refillmenu("Nachspeisung");
menu::Menu_Entry_Type_Checkable t_refillEnable(false);
menu::Menu_Entry_Type_Checkable t_refillBlock(true);
menu::Menu_Entry_Type_Checkable t_refillBlockInvert(false);
t_refillEnable.linkConfig(globalConfig.RefillEnable.getLink());
t_refillBlock.linkConfig(globalConfig.RefillBlockEnable.getLink());
t_refillBlockInvert.linkConfig(globalConfig.RefillBlockInvert.getLink());
menu::Menu_Entry refillEnable(t_refillEnable, "Nachsp. akt.");
menu::Menu_Entry refillBlock(t_refillBlock, "Notabschalt.");
menu::Menu_Entry refillBlockInvert(t_refillBlockInvert, "NotAbs. Inv.");
menu::Menu_Entry_Type_Percent t_RefillBelow(20);
menu::Menu_Entry_Type_Percent t_RefillHysteresis(5);
t_RefillBelow.linkConfig(globalConfig.RefillBelow.getLink());
t_RefillHysteresis.linkConfig(globalConfig.RefillHysteresis.getLink());
menu::Menu_Entry refillBelow(t_RefillBelow, "Auff. bis");
menu::Menu_Entry refillHysteresis(t_RefillHysteresis, "Hysterese");
refillmenu.addEntry(refillEnable);
refillmenu.addEntry(refillBlock);
refillmenu.addEntry(refillBlockInvert);
refillmenu.addEntry(refillBelow);
refillmenu.addEntry(refillHysteresis);
relay.setCooldown(10000); menu::Menu mainmenu("Hauptmenu");
mainmenu.addSubmenu(&tankmenu);
mainmenu.addSubmenu(&refillmenu);
menu::Menu_Controller controller(&mainmenu, display);
static int old_pos = 0; static int old_pos = 0;
while (1) { while (1) {
//render menu //render menu
controller.execute(); controller.execute();
if (rot_button) { if (rot_button) {
rot_button = false; rot_button = false;
controller.pushEvent(Menu_Controller::Event::Push); controller.pushEvent(menu::Menu_Controller::Event::Push);
} }
if (old_pos < rot_counter) { if (old_pos < rot_counter) {
controller.pushEvent(Menu_Controller::Event::Increase); controller.pushEvent(menu::Menu_Controller::Event::Increase);
old_pos = rot_counter; old_pos = rot_counter;
} else if (old_pos > rot_counter) { } else if (old_pos > rot_counter) {
controller.pushEvent(Menu_Controller::Event::Decrease); controller.pushEvent(menu::Menu_Controller::Event::Decrease);
old_pos = rot_counter; old_pos = rot_counter;
} }
HAL_Delay(100); HAL_Delay(100);
if(l_calib) {
relay.switchRelay(floatpump::io::RelayChannel::state::ON);
} }
//channel.calibrateLow();
if(h_calib) { // Menu_Controller controller(&mainmenu, display);
relay.switchRelay(floatpump::io::RelayChannel::state::OFF); //
} // floatpump::io::PressureChannel channel(&hadc1, MPWR0_GPIO_Port, MPWR0_Pin);
//channel.calibrateHigh(); // floatpump::io::RelayChannel relay(OCHAN0_GPIO_Port, OCHAN0_Pin, false);
// floatpump::io::GPIChannel swimmer(GPI0_GPIO_Port, GPI0_Pin, false);
l_calib = false; //
h_calib = false; //
//
curCooldown = relay.getRemainingCooldown(); // relay.setCooldown(10000);
//
prescaler++; // static int old_pos = 0;
// while (1) {
//
swimmer.poll(); // //render menu
if(prescaler % 100 == 0) // controller.execute();
channel.poll(); // if (rot_button) {
// rot_button = false;
current = channel.getRaw(); // controller.pushEvent(Menu_Controller::Event::Push);
cur_perc = channel.getPercent(); // }
inputTest = swimmer.getStateBool(); //
// if (old_pos < rot_counter) {
/*if(cur_perc > 50) { // controller.pushEvent(Menu_Controller::Event::Increase);
relay.switchRelay(floatpump::io::RelayChannel::state::ON); // old_pos = rot_counter;
} else if(cur_perc < 45) { // } else if (old_pos > rot_counter) {
relay.switchRelay(floatpump::io::RelayChannel::state::OFF); // controller.pushEvent(Menu_Controller::Event::Decrease);
}*/ // old_pos = rot_counter;
} // }
// HAL_Delay(100);
//
//
// if(l_calib) {
// relay.switchRelay(floatpump::io::RelayChannel::state::ON);
// }
// //channel.calibrateLow();
//
// if(h_calib) {
// relay.switchRelay(floatpump::io::RelayChannel::state::OFF);
// }
// //channel.calibrateHigh();
//
// l_calib = false;
// h_calib = false;
//
// curCooldown = relay.getRemainingCooldown();
//
// prescaler++;
//
//
// swimmer.poll();
// if(prescaler % 100 == 0)
// channel.poll();
//
// current = channel.getRaw();
// cur_perc = channel.getPercent();
// inputTest = swimmer.getStateBool();
//
// /*if(cur_perc > 50) {
// relay.switchRelay(floatpump::io::RelayChannel::state::ON);
// } else if(cur_perc < 45) {
// relay.switchRelay(floatpump::io::RelayChannel::state::OFF);
// }*/
// }
} }

View File

@ -40,8 +40,21 @@ namespace floatpump {
T m_data; T m_data;
}; };
Config_Object<uint16_t> TankCalibLow = Config_Object<uint16_t>(0);
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<bool> TankPumpInvert = Config_Object<bool>(false);
Config_Object<bool> testbool = Config_Object<bool>(false); Config_Object<bool> RefillEnable = Config_Object<bool>(false);
Config_Object<bool> RefillBlockInvert = Config_Object<bool>(false);
Config_Object<bool> RefillBlockEnable = Config_Object<bool>(true);
Config_Object<uint8_t> RefillBelow = Config_Object<uint8_t>(false);
Config_Object<uint8_t> RefillHysteresis = Config_Object<uint8_t>(false);
Config_Object<uint32_t> RefillCooldown = Config_Object<uint32_t>(60);
}; };
} // floatpump } // floatpump