2019-04-02 14:56:00 -03:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "NeoPixel.h"
|
2023-02-28 22:57:09 -04:00
|
|
|
|
|
|
|
#if AP_NOTIFY_NEOPIXEL_ENABLED
|
|
|
|
|
|
|
|
#include "AP_Notify/AP_Notify.h"
|
2019-04-02 14:56:00 -03:00
|
|
|
#include "SRV_Channel/SRV_Channel.h"
|
|
|
|
|
|
|
|
// This limit is from the dshot driver rcout groups limit
|
|
|
|
#define AP_NOTIFY_NEOPIXEL_MAX_INSTANCES 4
|
|
|
|
|
|
|
|
// Datasheet: https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf
|
|
|
|
// 24bit msg as 3 byte GRB (not RGB) where first bit is G7, and last bit is B0
|
|
|
|
// (first) G7|G6|G5|G4|G3|G2|G1|G0|R7|R6|R5|R4|R3|R2|R1|R0|B7|B6|B5|B4|B3|B2|B1|B0 (last)
|
|
|
|
|
|
|
|
#define NEOPIXEL_LED_LOW 0x33
|
|
|
|
#define NEOPIXEL_LED_MEDIUM 0x7F
|
|
|
|
#define NEOPIXEL_LED_HIGH 0xFF
|
|
|
|
#define NEOPIXEL_LED_OFF 0x00
|
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
NeoPixel::NeoPixel() :
|
2020-02-22 19:54:57 -04:00
|
|
|
SerialLED(NEOPIXEL_LED_OFF, NEOPIXEL_LED_HIGH, NEOPIXEL_LED_MEDIUM, NEOPIXEL_LED_LOW)
|
2019-04-02 14:56:00 -03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t NeoPixel::init_ports()
|
|
|
|
{
|
|
|
|
uint16_t mask = 0;
|
|
|
|
for (uint16_t i=0; i<AP_NOTIFY_NEOPIXEL_MAX_INSTANCES; i++) {
|
2019-09-09 06:23:04 -03:00
|
|
|
const SRV_Channel::Aux_servo_function_t fn = (SRV_Channel::Aux_servo_function_t)((uint8_t)SRV_Channel::k_LED_neopixel1 + i);
|
|
|
|
if (!SRV_Channels::function_assigned(fn)) {
|
2019-04-02 14:56:00 -03:00
|
|
|
continue;
|
|
|
|
}
|
2019-09-09 06:23:04 -03:00
|
|
|
mask |= SRV_Channels::get_output_channel_mask(fn);
|
2019-04-02 14:56:00 -03:00
|
|
|
}
|
|
|
|
|
2020-02-22 19:54:57 -04:00
|
|
|
if (mask == 0) {
|
|
|
|
return 0;
|
2019-04-02 14:56:00 -03:00
|
|
|
}
|
|
|
|
|
2020-02-22 19:54:57 -04:00
|
|
|
AP_SerialLED *led = AP_SerialLED::get_singleton();
|
|
|
|
if (led == nullptr) {
|
|
|
|
return 0;
|
2019-04-02 14:56:00 -03:00
|
|
|
}
|
|
|
|
|
2019-09-09 06:23:04 -03:00
|
|
|
for (uint16_t chan=0; chan<16; chan++) {
|
2020-02-22 19:54:57 -04:00
|
|
|
if ((1U<<chan) & mask) {
|
2023-09-28 17:49:43 -03:00
|
|
|
if (pNotify->get_led_type() & AP_Notify::Notify_LED_NeoPixel) {
|
|
|
|
led->set_num_neopixel(chan+1, pNotify->get_led_len());
|
|
|
|
} else if (pNotify->get_led_type() & AP_Notify::Notify_LED_NeoPixelRGB) {
|
|
|
|
led->set_num_neopixel_rgb(chan+1, pNotify->get_led_len());
|
|
|
|
}
|
2019-09-09 06:23:04 -03:00
|
|
|
}
|
2019-04-02 14:56:00 -03:00
|
|
|
}
|
2020-02-22 19:54:57 -04:00
|
|
|
|
|
|
|
return mask;
|
2023-02-28 22:57:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // AP_NOTIFY_NEOPIXEL_ENABLED
|