//
// Created by robtor on 10.01.23.
//

#ifndef FLOATPUMP_RELAYCHANNEL_H
#define FLOATPUMP_RELAYCHANNEL_H

#include "stm32f4xx_hal.h"

namespace floatpump::io {

    class RelayChannel {
    public:

        enum state {
            ON, OFF
        };

        RelayChannel(GPIO_TypeDef *gpio, uint16_t pin, bool inverted = false, state initial = state::OFF);;

        void switchRelay(state st);

        void forceRefresh();

        void setInverted(bool inv);

        void setCooldown(uint16_t ms);

        [[nodiscard]] uint16_t getRemainingCooldown() const;


    private:
        GPIO_TypeDef *m_gpio;
        uint16_t m_gpio_pin;

        uint16_t m_cooldown = 0;

        uint32_t m_lastTick = 0;

        bool m_inverted = false;
        state m_state = state::OFF;
    };

} // io

#endif //FLOATPUMP_RELAYCHANNEL_H
