//
// 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