From 0f497d72ca2097e2663624d2118a8be96c32e9d3 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Mon, 12 Aug 2024 20:56:35 +0100 Subject: [PATCH] AP_Notify: allow split-standard LED pattern on serial LEDs --- libraries/AP_Notify/AP_Notify.cpp | 2 +- libraries/AP_Notify/RGBLed.cpp | 1 + libraries/AP_Notify/RGBLed.h | 20 +++++++++++--------- libraries/AP_Notify/SerialLED.cpp | 23 ++++++++++++++++++++--- libraries/AP_Notify/SerialLED.h | 1 - 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/libraries/AP_Notify/AP_Notify.cpp b/libraries/AP_Notify/AP_Notify.cpp index abfb047711baa..904edde8a626e 100644 --- a/libraries/AP_Notify/AP_Notify.cpp +++ b/libraries/AP_Notify/AP_Notify.cpp @@ -183,7 +183,7 @@ const AP_Param::GroupInfo AP_Notify::var_info[] = { // @Param: LED_OVERRIDE // @DisplayName: Specifies colour source for the RGBLed // @Description: Specifies the source for the colours and brightness for the LED. OutbackChallenge conforms to the MedicalExpress (https://uavchallenge.org/medical-express/) rules, essentially "Green" is disarmed (safe-to-approach), "Red" is armed (not safe-to-approach). Traffic light is a simplified color set, red when armed, yellow when the safety switch is not surpressing outputs (but disarmed), and green when outputs are surpressed and disarmed, the LED will blink faster if disarmed and failing arming checks. - // @Values: 0:Standard,1:MAVLink/Scripting/AP_Periph,2:OutbackChallenge,3:TrafficLight + // @Values: 0:Standard,1:MAVLink/Scripting/AP_Periph,2:OutbackChallenge,3:TrafficLight,4:Split Standard // @User: Advanced AP_GROUPINFO("LED_OVERRIDE", 2, AP_Notify, _rgb_led_override, NOTIFY_LED_OVERRIDE_DEFAULT), diff --git a/libraries/AP_Notify/RGBLed.cpp b/libraries/AP_Notify/RGBLed.cpp index caa549fd94cae..853962cce96de 100644 --- a/libraries/AP_Notify/RGBLed.cpp +++ b/libraries/AP_Notify/RGBLed.cpp @@ -213,6 +213,7 @@ void RGBLed::update() update_override(); return; // note this is a return not a break! case Source::standard: + case Source::split_standard: current_colour_sequence = get_colour_sequence(); break; case Source::obc: diff --git a/libraries/AP_Notify/RGBLed.h b/libraries/AP_Notify/RGBLed.h index 3978f04806c67..3fa64da435c28 100644 --- a/libraries/AP_Notify/RGBLed.h +++ b/libraries/AP_Notify/RGBLed.h @@ -62,7 +62,17 @@ class RGBLed: public NotifyDevice { uint8_t rate_hz; uint32_t start_ms; } _led_override; - + + enum class Source { + standard = 0, + mavlink = 1, + obc = 2, + traffic_light = 3, + split_standard = 4, + }; + + Source rgb_source() const; + private: void update_colours(); uint32_t get_colour_sequence() const; @@ -105,12 +115,4 @@ class RGBLed: public NotifyDevice { const uint32_t sequence_disarmed_bad_gps_or_no_location = DEFINE_COLOUR_SEQUENCE_SLOW(BLUE); uint8_t last_step; - enum class Source { - standard = 0, - mavlink = 1, - obc = 2, - traffic_light = 3, - }; - Source rgb_source() const; - }; diff --git a/libraries/AP_Notify/SerialLED.cpp b/libraries/AP_Notify/SerialLED.cpp index 8f8ee500fa820..79099292f6f15 100644 --- a/libraries/AP_Notify/SerialLED.cpp +++ b/libraries/AP_Notify/SerialLED.cpp @@ -14,6 +14,7 @@ */ #include "SerialLED.h" +#include "AP_Notify/AP_Notify.h" #if AP_NOTIFY_SERIALLED_ENABLED @@ -42,9 +43,25 @@ bool SerialLED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) return false; } - for (uint16_t chan=0; chan<16; chan++) { - if ((1U<set_RGB(chan+1, -1, red, green, blue); + if (rgb_source() != Source::split_standard) { + for (uint16_t chan=0; chan<16; chan++) { + if ((1U<set_RGB(chan+1, -1, red, green, blue); + } + } + } else { + // switch red and green for half the LEDs in split standard + // so that copters can display different armed colours on different sides + for (uint16_t chan=0; chan<16; chan++) { + const uint8_t led_len = pNotify->get_led_len(); + if ((1U<set_RGB(chan+1, i, red, green, blue); + } + for (uint8_t i = led_len/2; i < led_len; i++) { + led->set_RGB(chan+1, i, green, red, blue); + } + } } } diff --git a/libraries/AP_Notify/SerialLED.h b/libraries/AP_Notify/SerialLED.h index ba29be20ff27b..88c965cabcb72 100644 --- a/libraries/AP_Notify/SerialLED.h +++ b/libraries/AP_Notify/SerialLED.h @@ -37,7 +37,6 @@ class SerialLED: public RGBLed { virtual uint16_t init_ports() { return 0; }; protected: - bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override; private: