FEATURE: simple input channel support

This commit is contained in:
Robin Dietzel 2023-01-10 14:04:49 +01:00
parent 3cc48e2d23
commit 5420b39dd2
3 changed files with 79 additions and 5 deletions

View File

@ -16,6 +16,7 @@
#include "Menu_Controller.h"
#include "PressureChannel.h"
#include "RelayChannel.h"
#include "GPIChannel.h"
#define SLAVE_ADDRESS_LCD 0x4e
@ -122,17 +123,22 @@ int main(void) {
cdd.linkConfig(&curCooldown);
Menu_Entry entry6(cdd, "Cooldown");
mainmenu.addEntry(entry6);
Menu_Entry_Type_Checkable tr(false);
bool inputTest;
tr.linkConfig(&inputTest);
Menu_Entry entry7(tr, "Input");
mainmenu.addEntry(entry7);
Menu_Controller controller(&mainmenu, display);
HAL_GPIO_WritePin(MPWR0_GPIO_Port, MPWR0_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(MPWR2_GPIO_Port, MPWR2_Pin, GPIO_PIN_SET);
floatpump::io::PressureChannel channel(&hadc1, MPWR0_GPIO_Port, MPWR0_Pin);
floatpump::io::RelayChannel relay(OCHAN0_GPIO_Port, OCHAN0_Pin, false);
floatpump::io::GPIChannel swimmer(GPI0_GPIO_Port, GPI0_Pin, false);
relay.setCooldown(10000);
static int old_pos = 0;
@ -172,11 +178,14 @@ int main(void) {
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);

View File

@ -0,0 +1,36 @@
//
// Created by robtor on 10.01.23.
//
#ifndef FLOATPUMP_GPICHANNEL_H
#define FLOATPUMP_GPICHANNEL_H
#include "stm32f4xx_hal.h"
namespace floatpump::io {
class GPIChannel {
public:
enum state {
ON, OFF
};
GPIChannel(GPIO_TypeDef *gpio, uint16_t pin, bool inverted = false);
void poll();
[[nodiscard]] state getState() const;
[[nodiscard]] bool getStateBool() const;
private:
GPIO_TypeDef *m_gpio;
uint16_t m_gpio_pin;
bool m_inverted;
state m_state = state::OFF;
};
} // io
#endif //FLOATPUMP_GPICHANNEL_H

View File

@ -0,0 +1,29 @@
//
// Created by robtor on 10.01.23.
//
#include "GPIChannel.h"
namespace floatpump {
namespace io {
GPIChannel::GPIChannel(GPIO_TypeDef *gpio, uint16_t pin, bool inverted) : m_gpio(gpio), m_gpio_pin(pin), m_inverted(inverted) {
}
void GPIChannel::poll() {
if(HAL_GPIO_ReadPin(m_gpio, m_gpio_pin) == GPIO_PIN_SET) {
m_state = (m_inverted)? state::OFF : state::ON;
} else {
m_state = (m_inverted)? state::ON : state::OFF;
}
}
GPIChannel::state GPIChannel::getState() const {
return m_state;
}
bool GPIChannel::getStateBool() const {
return (m_state == state::ON);
}
} // floatpump
} // io