AP_Relay: add enabled method by function

This commit is contained in:
Iampete1 2023-12-08 04:36:03 +00:00 committed by Peter Barker
parent 8ce490d985
commit 8ab6f01942
2 changed files with 15 additions and 0 deletions

View File

@ -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); 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 #if AP_MAVLINK_MSG_RELAY_STATUS_ENABLED
// this method may only return false if there is no space in the // this method may only return false if there is no space in the
// supplied link for the message. // supplied link for the message.

View File

@ -57,6 +57,9 @@ public:
void set(AP_Relay_Params::Function function, bool value); void set(AP_Relay_Params::Function function, bool value);
// see if the relay is enabled
bool enabled(AP_Relay_Params::Function function) const;
private: private:
static AP_Relay *singleton; static AP_Relay *singleton;