APM:Libraries
RGBLed.h
Go to the documentation of this file.
1 /*
2  * AP_Notify Library.
3  * based upon a prototype library by David "Buzz" Bussenschutt.
4  */
5 
6 /*
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #pragma once
21 
22 #include <AP_HAL/AP_HAL.h>
23 #include "NotifyDevice.h"
24 
25 class RGBLed: public NotifyDevice {
26 public:
27  RGBLed(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t led_dim);
28 
29  // init - initialised the LED
30  virtual bool init(void);
31 
32  // healthy - returns true if the LED is operating properly
33  virtual bool healthy() { return _healthy; }
34 
35  // set_rgb - set color as a combination of red, green and blue levels from 0 ~ 15
36  virtual void set_rgb(uint8_t red, uint8_t green, uint8_t blue);
37 
38  // update - updates led according to timed_updated. Should be
39  // called at 50Hz
40  virtual void update();
41 
42  // handle LED control, only used when LED_OVERRIDE=1
43  virtual void handle_led_control(mavlink_message_t *msg) override;
44 
45 protected:
46  // methods implemented in hardware specific classes
47  virtual bool hw_init(void) = 0;
48  virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) = 0;
49 
50  // set_rgb - set color as a combination of red, green and blue levels from 0 ~ 15
51  virtual void _set_rgb(uint8_t red, uint8_t green, uint8_t blue);
52 
53  virtual void update_override();
54 
55  // meta-data common to all hw devices
56  uint8_t counter;
57  uint8_t step;
58  bool _healthy; // true if the LED is operating properly
59  uint8_t _red_des, _green_des, _blue_des; // color requested by timed update
60  uint8_t _red_curr, _green_curr, _blue_curr; // current colours displayed by the led
61  uint8_t _led_off;
62  uint8_t _led_bright;
63  uint8_t _led_medium;
64  uint8_t _led_dim;
65 
66  struct {
67  uint8_t r, g, b;
68  uint8_t rate_hz;
69  uint32_t start_ms;
70  } _led_override;
71 
72 private:
73  virtual void update_colours();
74 };
virtual void set_rgb(uint8_t red, uint8_t green, uint8_t blue)
Definition: RGBLed.cpp:66
virtual void update_override()
Definition: RGBLed.cpp:391
uint8_t b
Definition: RGBLed.h:67
Definition: RGBLed.h:25
RGBLed(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t led_dim)
Definition: RGBLed.cpp:26
uint8_t g
Definition: RGBLed.h:67
uint8_t step
Definition: RGBLed.h:57
uint8_t rate_hz
Definition: RGBLed.h:68
virtual void update_colours()
Definition: RGBLed.cpp:81
virtual void _set_rgb(uint8_t red, uint8_t green, uint8_t blue)
Definition: RGBLed.cpp:51
uint8_t _led_off
Definition: RGBLed.h:61
uint32_t start_ms
Definition: RGBLed.h:69
uint8_t _red_des
Definition: RGBLed.h:59
uint8_t r
Definition: RGBLed.h:67
uint8_t _led_bright
Definition: RGBLed.h:62
uint8_t _red_curr
Definition: RGBLed.h:60
uint8_t _led_dim
Definition: RGBLed.h:64
virtual bool init(void)
Definition: RGBLed.cpp:44
struct RGBLed::@157 _led_override
bool _healthy
Definition: RGBLed.h:58
uint8_t _blue_curr
Definition: RGBLed.h:60
virtual void handle_led_control(mavlink_message_t *msg) override
Definition: RGBLed.cpp:356
virtual bool hw_init(void)=0
virtual bool healthy()
Definition: RGBLed.h:33
uint8_t _blue_des
Definition: RGBLed.h:59
virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)=0
uint8_t _led_medium
Definition: RGBLed.h:63
uint8_t _green_curr
Definition: RGBLed.h:60
virtual void update()
Definition: RGBLed.cpp:339
uint8_t counter
Definition: RGBLed.h:56
uint8_t _green_des
Definition: RGBLed.h:59