ardupilot/libraries/AP_Relay/AP_Relay.h

75 lines
1.6 KiB
C
Raw Normal View History

/*
* AP_Relay.h
*
* Created on: Oct 2, 2011
* Author: Amilcar Lucas
*/
/// @file AP_Relay.h
/// @brief APM relay control class
#pragma once
#include "AP_Relay_config.h"
#if AP_RELAY_ENABLED
#include <AP_Param/AP_Param.h>
#define AP_RELAY_NUM_RELAYS 6
2014-01-19 21:59:21 -04:00
/// @class AP_Relay
2017-08-29 15:08:41 -03:00
/// @brief Class to manage the ArduPilot relay
class AP_Relay {
public:
AP_Relay();
2017-08-29 15:08:41 -03:00
/* Do not allow copies */
2022-09-30 06:50:43 -03:00
CLASS_NO_COPY(AP_Relay);
2012-12-04 19:26:30 -04:00
// setup the relay pin
void init();
// activate the relay
void on(uint8_t instance) { set(instance, true); }
// de-activate the relay
void off(uint8_t instance) { set(instance, false); }
// get state of relay
uint8_t get(uint8_t instance) const {
return instance < AP_RELAY_NUM_RELAYS ? _pin_states & (1U<<instance) : 0;
}
2014-01-20 00:35:38 -04:00
// see if the relay is enabled
bool enabled(uint8_t instance) const { return instance < AP_RELAY_NUM_RELAYS && _pin[instance] != -1; }
2014-01-20 00:35:38 -04:00
// toggle the relay status
void toggle(uint8_t instance);
2021-07-20 01:26:33 -03:00
// check settings are valid
bool arming_checks(size_t buflen, char *buffer) const;
2019-04-22 20:12:56 -03:00
static AP_Relay *get_singleton(void) {return singleton; }
static const struct AP_Param::GroupInfo var_info[];
bool send_relay_status(const class GCS_MAVLINK &link) const;
private:
2019-04-22 20:12:56 -03:00
static AP_Relay *singleton;
2014-01-19 21:59:21 -04:00
AP_Int8 _pin[AP_RELAY_NUM_RELAYS];
AP_Int8 _default;
uint8_t _pin_states;
uint8_t _last_logged_pin_states;
uint32_t _last_log_ms;
2019-09-26 19:15:00 -03:00
void set(uint8_t instance, bool value);
};
namespace AP {
AP_Relay *relay();
};
#endif // AP_RELAY_ENABLED