FEATURE: correctly initialize and reset relays

This commit is contained in:
Robin Dietzel 2023-02-02 15:54:06 +01:00
parent 526546f0a4
commit 036f5c9bf4
2 changed files with 11 additions and 0 deletions

View File

@ -20,6 +20,8 @@ namespace floatpump::io {
void switchRelay(state st);
void forceRefresh();
void setInverted(bool inv);
void setCooldown(uint16_t ms);

View File

@ -27,6 +27,7 @@ namespace floatpump {
}
}
void RelayChannel::setCooldown(uint16_t ms) {
m_cooldown = ms;
}
@ -43,5 +44,13 @@ namespace floatpump {
void RelayChannel::setInverted(bool inv) {
m_inverted = inv;
}
void RelayChannel::forceRefresh() {
if ( m_state == state::ON) {
HAL_GPIO_WritePin(m_gpio, m_gpio_pin, (m_inverted) ? GPIO_PIN_RESET : GPIO_PIN_SET);
} else if (m_state == state::OFF) {
HAL_GPIO_WritePin(m_gpio, m_gpio_pin, (m_inverted) ? GPIO_PIN_SET : GPIO_PIN_RESET);
}
}
} // floatpump
} // io