ExternalLED.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #pragma once
  14. #include <AP_Common/AP_Common.h>
  15. #include <AP_HAL/AP_HAL.h>
  16. #include <AP_Param/AP_Param.h>
  17. #include "NotifyDevice.h"
  18. #define HIGH 1
  19. #define LOW 0
  20. class ExternalLED: public NotifyDevice
  21. {
  22. public:
  23. // constructor
  24. ExternalLED() : _pattern(NONE) {}
  25. // initialise the LED driver
  26. bool init(void) override;
  27. // should be called at 50Hz
  28. void update(void) override;
  29. private:
  30. enum LEDPattern {
  31. NONE = 0,
  32. FAST_FLASH = 1,
  33. OSCILLATE = 2
  34. };
  35. /// buzzer_flag_type - bitmask of current state and ap_notify states we track
  36. struct copterleds_flag_type {
  37. // individual led status
  38. uint8_t armedled_on : 1; // 1 if the armed led is currently on
  39. uint8_t gpsled_on : 1; // 1 if the gps led is currently on
  40. uint8_t motorled1_on : 1; // 1 if motor led #1 is currently on
  41. uint8_t motorled2_on : 1; // 1 if motor led #2 is currently on
  42. } _flags;
  43. uint8_t _counter; // reduces 50hz calls to 10hz
  44. uint8_t _counter2; // used to control steps of arming and gps leds
  45. LEDPattern _pattern; // current pattern for motor leds
  46. uint8_t _pattern_counter; // used to time on/off of current patter
  47. // armed_led - set armed light on or off
  48. void armed_led(bool on_off);
  49. // gps_led - set gps light on or off
  50. void gps_led(bool on_off);
  51. // set_pattern - sets pattern for motor leds
  52. void set_pattern(LEDPattern pattern_id);
  53. // motor_led1, motor_led2 - set motor lights on or off
  54. void motor_led1(bool on_off);
  55. void motor_led2(bool on_off);
  56. };