2014-11-14 10:14:40 -04:00
|
|
|
/*
|
|
|
|
* AP_Notify Library.
|
|
|
|
* based upon a prototype library by David "Buzz" Bussenschutt.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-02-17 21:25:41 -04:00
|
|
|
#pragma once
|
2014-11-14 10:14:40 -04:00
|
|
|
|
2014-12-26 00:05:15 -04:00
|
|
|
#include "NotifyDevice.h"
|
2014-11-14 10:14:40 -04:00
|
|
|
|
2014-12-26 00:05:15 -04:00
|
|
|
class RGBLed: public NotifyDevice {
|
2014-11-14 10:14:40 -04:00
|
|
|
public:
|
|
|
|
RGBLed(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t led_dim);
|
|
|
|
|
|
|
|
// set_rgb - set color as a combination of red, green and blue levels from 0 ~ 15
|
2022-10-20 05:28:01 -03:00
|
|
|
void set_rgb(uint8_t red, uint8_t green, uint8_t blue);
|
2014-11-14 10:14:40 -04:00
|
|
|
|
|
|
|
// update - updates led according to timed_updated. Should be
|
|
|
|
// called at 50Hz
|
2018-11-07 07:01:17 -04:00
|
|
|
virtual void update() override;
|
2014-11-14 10:14:40 -04:00
|
|
|
|
2022-10-21 08:48:51 -03:00
|
|
|
#if AP_NOTIFY_MAVLINK_LED_CONTROL_SUPPORT_ENABLED
|
2016-07-16 03:02:27 -03:00
|
|
|
// handle LED control, only used when LED_OVERRIDE=1
|
2019-04-30 07:22:48 -03:00
|
|
|
virtual void handle_led_control(const mavlink_message_t &msg) override;
|
2022-10-21 08:48:51 -03:00
|
|
|
#endif
|
2019-12-09 17:06:35 -04:00
|
|
|
|
|
|
|
// RGB control
|
|
|
|
// give RGB and flash rate, used with scripting
|
2022-10-20 05:28:01 -03:00
|
|
|
void rgb_control(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz) override;
|
2019-12-09 17:06:35 -04:00
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
protected:
|
|
|
|
// methods implemented in hardware specific classes
|
|
|
|
virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) = 0;
|
|
|
|
|
2016-07-16 03:02:27 -03:00
|
|
|
// set_rgb - set color as a combination of red, green and blue levels from 0 ~ 15
|
|
|
|
virtual void _set_rgb(uint8_t red, uint8_t green, uint8_t blue);
|
|
|
|
|
2018-08-13 23:17:24 -03:00
|
|
|
void update_override();
|
2016-07-16 03:02:27 -03:00
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
// meta-data common to all hw devices
|
|
|
|
uint8_t _red_curr, _green_curr, _blue_curr; // current colours displayed by the led
|
|
|
|
uint8_t _led_off;
|
|
|
|
uint8_t _led_bright;
|
|
|
|
uint8_t _led_medium;
|
|
|
|
uint8_t _led_dim;
|
2016-07-16 03:02:27 -03:00
|
|
|
|
|
|
|
struct {
|
|
|
|
uint8_t r, g, b;
|
|
|
|
uint8_t rate_hz;
|
|
|
|
uint32_t start_ms;
|
|
|
|
} _led_override;
|
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
private:
|
2018-08-13 08:42:28 -03:00
|
|
|
void update_colours();
|
|
|
|
uint32_t get_colour_sequence() const;
|
2018-08-13 23:17:24 -03:00
|
|
|
uint32_t get_colour_sequence_obc() const;
|
2019-08-29 18:04:17 -03:00
|
|
|
uint32_t get_colour_sequence_traffic_light() const;
|
2018-08-13 08:42:28 -03:00
|
|
|
|
|
|
|
uint8_t get_brightness(void) const;
|
|
|
|
|
|
|
|
#define DEFINE_COLOUR_SEQUENCE(S0, S1, S2, S3, S4, S5, S6, S7, S8, S9) \
|
|
|
|
((S0) << (0*3) | (S1) << (1*3) | (S2) << (2*3) | (S3) << (3*3) | (S4) << (4*3) | (S5) << (5*3) | (S6) << (6*3) | (S7) << (7*3) | (S8) << (8*3) | (S9) << (9*3))
|
|
|
|
|
|
|
|
#define DEFINE_COLOUR_SEQUENCE_SLOW(colour) \
|
2020-09-03 10:32:40 -03:00
|
|
|
DEFINE_COLOUR_SEQUENCE(colour,colour,colour,colour,colour,BLACK,BLACK,BLACK,BLACK,BLACK)
|
2018-08-13 08:42:28 -03:00
|
|
|
#define DEFINE_COLOUR_SEQUENCE_FAILSAFE(colour) \
|
|
|
|
DEFINE_COLOUR_SEQUENCE(YELLOW,YELLOW,YELLOW,YELLOW,YELLOW,colour,colour,colour,colour,colour)
|
|
|
|
#define DEFINE_COLOUR_SEQUENCE_SOLID(colour) \
|
|
|
|
DEFINE_COLOUR_SEQUENCE(colour,colour,colour,colour,colour,colour,colour,colour,colour,colour)
|
|
|
|
#define DEFINE_COLOUR_SEQUENCE_ALTERNATE(colour1, colour2) \
|
|
|
|
DEFINE_COLOUR_SEQUENCE(colour1,colour2,colour1,colour2,colour1,colour2,colour1,colour2,colour1,colour2)
|
|
|
|
|
2020-09-03 10:32:40 -03:00
|
|
|
#define BLACK 0
|
2018-08-13 08:42:28 -03:00
|
|
|
#define BLUE 1
|
|
|
|
#define GREEN 2
|
|
|
|
#define RED 4
|
|
|
|
#define YELLOW (RED|GREEN)
|
|
|
|
#define WHITE (RED|GREEN|BLUE)
|
|
|
|
|
|
|
|
const uint32_t sequence_initialising = DEFINE_COLOUR_SEQUENCE_ALTERNATE(RED,BLUE);
|
2020-09-03 10:32:40 -03:00
|
|
|
const uint32_t sequence_trim_or_esc = DEFINE_COLOUR_SEQUENCE(RED,BLUE,GREEN,RED,BLUE,GREEN,RED,BLUE,GREEN,BLACK);
|
2018-08-13 08:42:28 -03:00
|
|
|
const uint32_t sequence_failsafe_leak = DEFINE_COLOUR_SEQUENCE_FAILSAFE(WHITE);
|
|
|
|
const uint32_t sequence_failsafe_ekf = DEFINE_COLOUR_SEQUENCE_FAILSAFE(RED);
|
|
|
|
const uint32_t sequence_failsafe_gps_glitching = DEFINE_COLOUR_SEQUENCE_FAILSAFE(BLUE);
|
2020-09-03 10:32:40 -03:00
|
|
|
const uint32_t sequence_failsafe_radio_or_battery = DEFINE_COLOUR_SEQUENCE_FAILSAFE(BLACK);
|
2018-08-13 08:42:28 -03:00
|
|
|
|
|
|
|
const uint32_t sequence_armed = DEFINE_COLOUR_SEQUENCE_SOLID(GREEN);
|
2024-06-25 02:18:58 -03:00
|
|
|
const uint32_t sequence_armed_no_gps_or_no_location = DEFINE_COLOUR_SEQUENCE_SOLID(BLUE);
|
2020-09-03 10:32:40 -03:00
|
|
|
const uint32_t sequence_prearm_failing = DEFINE_COLOUR_SEQUENCE(YELLOW,YELLOW,BLACK,BLACK,YELLOW,YELLOW,BLACK,BLACK,BLACK,BLACK);
|
2024-06-25 02:18:58 -03:00
|
|
|
const uint32_t sequence_disarmed_good_dgps_and_location = DEFINE_COLOUR_SEQUENCE_ALTERNATE(GREEN,BLACK);
|
|
|
|
const uint32_t sequence_disarmed_good_gps_and_location = DEFINE_COLOUR_SEQUENCE_SLOW(GREEN);
|
|
|
|
const uint32_t sequence_disarmed_bad_gps_or_no_location = DEFINE_COLOUR_SEQUENCE_SLOW(BLUE);
|
2018-08-13 08:42:28 -03:00
|
|
|
|
2018-10-07 02:47:05 -03:00
|
|
|
uint8_t last_step;
|
2024-05-26 15:25:47 -03:00
|
|
|
enum class Source {
|
2018-08-13 23:17:24 -03:00
|
|
|
standard = 0,
|
|
|
|
mavlink = 1,
|
|
|
|
obc = 2,
|
2019-08-29 18:04:17 -03:00
|
|
|
traffic_light = 3,
|
2018-08-13 23:17:24 -03:00
|
|
|
};
|
2024-05-26 15:25:47 -03:00
|
|
|
Source rgb_source() const;
|
2018-08-13 23:17:24 -03:00
|
|
|
|
2014-11-14 10:14:40 -04:00
|
|
|
};
|