From 036f5c9bf410374bbe40de2c7dc5afd14b2ef43e Mon Sep 17 00:00:00 2001 From: Robin Dietzel Date: Thu, 2 Feb 2023 15:54:06 +0100 Subject: [PATCH] FEATURE: correctly initialize and reset relays --- floatpump/Middlewares/floatpump/Inc/RelayChannel.h | 2 ++ floatpump/Middlewares/floatpump/Src/RelayChannel.cpp | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/floatpump/Middlewares/floatpump/Inc/RelayChannel.h b/floatpump/Middlewares/floatpump/Inc/RelayChannel.h index f97e752..b9f3874 100644 --- a/floatpump/Middlewares/floatpump/Inc/RelayChannel.h +++ b/floatpump/Middlewares/floatpump/Inc/RelayChannel.h @@ -20,6 +20,8 @@ namespace floatpump::io { void switchRelay(state st); + void forceRefresh(); + void setInverted(bool inv); void setCooldown(uint16_t ms); diff --git a/floatpump/Middlewares/floatpump/Src/RelayChannel.cpp b/floatpump/Middlewares/floatpump/Src/RelayChannel.cpp index bcfbb32..9379320 100644 --- a/floatpump/Middlewares/floatpump/Src/RelayChannel.cpp +++ b/floatpump/Middlewares/floatpump/Src/RelayChannel.cpp @@ -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 \ No newline at end of file