floatpump-firmware/Middlewares/floatpump/Inc/RelayChannel.h

45 lines
801 B
C
Raw Normal View History

//
// Created by robtor on 10.01.23.
//
#ifndef FLOATPUMP_RELAYCHANNEL_H
#define FLOATPUMP_RELAYCHANNEL_H
#include "stm32f4xx_hal.h"
2023-01-10 12:00:18 +00:00
namespace floatpump::io {
2023-01-10 12:00:18 +00:00
class RelayChannel {
public:
2023-01-10 12:00:18 +00:00
enum state {
ON, OFF
};
2023-01-10 12:00:18 +00:00
RelayChannel(GPIO_TypeDef *gpio, uint16_t pin, bool inverted = false, state initial = state::OFF);;
2023-01-10 12:00:18 +00:00
void switchRelay(state st);
void setInverted(bool inv);
2023-01-10 12:00:18 +00:00
void setCooldown(uint16_t ms);
2023-01-10 12:00:18 +00:00
[[nodiscard]] uint16_t getRemainingCooldown() const;
2023-01-10 12:00:18 +00:00
private:
GPIO_TypeDef *m_gpio;
uint16_t m_gpio_pin;
2023-01-10 12:00:18 +00:00
uint16_t m_cooldown = 0;
2023-01-10 12:00:18 +00:00
uint32_t m_lastTick = 0;
2023-01-10 12:00:18 +00:00
bool m_inverted = false;
state m_state = state::OFF;
};
} // io
#endif //FLOATPUMP_RELAYCHANNEL_H