AP_Relay.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * AP_Relay.h
  3. *
  4. * Created on: Oct 2, 2011
  5. * Author: Amilcar Lucas
  6. */
  7. /// @file AP_Relay.h
  8. /// @brief APM relay control class
  9. #pragma once
  10. #include <AP_Param/AP_Param.h>
  11. #define AP_RELAY_NUM_RELAYS 6
  12. /// @class AP_Relay
  13. /// @brief Class to manage the ArduPilot relay
  14. class AP_Relay {
  15. public:
  16. AP_Relay();
  17. /* Do not allow copies */
  18. AP_Relay(const AP_Relay &other) = delete;
  19. AP_Relay &operator=(const AP_Relay&) = delete;
  20. // setup the relay pin
  21. void init();
  22. // activate the relay
  23. void on(uint8_t relay);
  24. // de-activate the relay
  25. void off(uint8_t relay);
  26. // see if the relay is enabled
  27. bool enabled(uint8_t relay) { return relay < AP_RELAY_NUM_RELAYS && _pin[relay] != -1; }
  28. // toggle the relay status
  29. void toggle(uint8_t relay);
  30. static AP_Relay *get_singleton(void) {return singleton; }
  31. static const struct AP_Param::GroupInfo var_info[];
  32. private:
  33. static AP_Relay *singleton;
  34. AP_Int8 _pin[AP_RELAY_NUM_RELAYS];
  35. AP_Int8 _default;
  36. };
  37. namespace AP {
  38. AP_Relay *relay();
  39. };