From 8ab6f01942cc40001b1f0dcb828d3c05a03bdff5 Mon Sep 17 00:00:00 2001 From: Iampete1 Date: Fri, 8 Dec 2023 04:36:03 +0000 Subject: [PATCH] AP_Relay: add enabled method by function --- libraries/AP_Relay/AP_Relay.cpp | 12 ++++++++++++ libraries/AP_Relay/AP_Relay.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/libraries/AP_Relay/AP_Relay.cpp b/libraries/AP_Relay/AP_Relay.cpp index 4ffe1d3562..e5cdde29c0 100644 --- a/libraries/AP_Relay/AP_Relay.cpp +++ b/libraries/AP_Relay/AP_Relay.cpp @@ -299,6 +299,18 @@ bool AP_Relay::enabled(uint8_t instance) const return (instance < AP_RELAY_NUM_RELAYS) && (_params[instance].pin != -1) && (_params[instance].function == AP_Relay_Params::Function::relay); } +// see if the relay is enabled +bool AP_Relay::enabled(AP_Relay_Params::Function function) const +{ + bool valid = false; + for (uint8_t instance = 0; instance < AP_RELAY_NUM_RELAYS; instance++) { + if ((_params[instance].function == function) && (_params[instance].pin != -1)) { + valid = true; + } + } + return valid; +} + #if AP_MAVLINK_MSG_RELAY_STATUS_ENABLED // this method may only return false if there is no space in the // supplied link for the message. diff --git a/libraries/AP_Relay/AP_Relay.h b/libraries/AP_Relay/AP_Relay.h index 5a5237d18c..a668e9144c 100644 --- a/libraries/AP_Relay/AP_Relay.h +++ b/libraries/AP_Relay/AP_Relay.h @@ -57,6 +57,9 @@ public: void set(AP_Relay_Params::Function function, bool value); + // see if the relay is enabled + bool enabled(AP_Relay_Params::Function function) const; + private: static AP_Relay *singleton;