From 5c6479bf18633a1c2738aa47c9754c4b57104198 Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Mon, 23 Oct 2023 12:31:58 -0700 Subject: [PATCH] Relay --- libraries/AP_Relay/AP_Relay.cpp | 41 +++++++++++++++++++++++++++++++-- libraries/AP_Relay/AP_Relay.h | 1 + 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Relay/AP_Relay.cpp b/libraries/AP_Relay/AP_Relay.cpp index 1a2d03e9726d0b..0c5092861faa90 100644 --- a/libraries/AP_Relay/AP_Relay.cpp +++ b/libraries/AP_Relay/AP_Relay.cpp @@ -169,6 +169,28 @@ void AP_Relay::init() set(i, (bool)default_state); } } + + for (uint8_t instance = 0; instance < AP_RELAY_NUM_RELAYS; instance++) { + const int8_t pin = _params[instance].pin; + if (pin == -1) { + // no valid pin to set it on, skip it + continue; + } + + const AP_Relay_Params::Function function = _params[instance].function; + if (function <= AP_Relay_Params::Function::relay || function >= AP_Relay_Params::Function::num_functions) { + // invalid function, skip it + continue; + } + + // all functions are interpreted to be off at power on, so if we tag our pins to the wrong + // state that will trigger the first call to output to update the state, and will get the + // pins into the correct state. + // + // This will need to be made aware of pin inversion when that support is added + _pin_states = _pin_states | (1U< _relay_by_instance; + Bitmask _relay_by_instance_has_been_asserted; Bitmask<(uint16_t)AP_Relay_Params::Function::num_functions> _desired_state; };