Browse Source

HAL_SITL: support simulated serial LEDs

mission-4.1.18
Andrew Tridgell 5 years ago committed by Randy Mackay
parent
commit
33755b9da0
  1. 41
      libraries/AP_HAL_SITL/RCOutput.cpp
  2. 7
      libraries/AP_HAL_SITL/RCOutput.h

41
libraries/AP_HAL_SITL/RCOutput.cpp

@ -84,4 +84,45 @@ void RCOutput::push(void) @@ -84,4 +84,45 @@ void RCOutput::push(void)
}
}
/*
Serial LED emulation
*/
bool RCOutput::set_neopixel_num_LEDs(const uint16_t chan, uint8_t num_leds)
{
if (chan > 15 || num_leds > 32) {
return false;
}
SITL::SITL *sitl = AP::sitl();
if (sitl) {
sitl->led.num_leds[chan] = num_leds;
return true;
}
return false;
}
void RCOutput::set_neopixel_rgb_data(const uint16_t chan, uint32_t ledmask, uint8_t red, uint8_t green, uint8_t blue)
{
if (chan > 15) {
return;
}
SITL::SITL *sitl = AP::sitl();
if (sitl) {
for (uint8_t i=0; i<32; i++) {
if ((1U<<i) & ledmask) {
sitl->led.rgb[chan][i].rgb[0] = red;
sitl->led.rgb[chan][i].rgb[1] = green;
sitl->led.rgb[chan][i].rgb[2] = blue;
}
}
}
}
void RCOutput::neopixel_send(void)
{
SITL::SITL *sitl = AP::sitl();
if (sitl) {
sitl->led.send_counter++;
}
}
#endif

7
libraries/AP_HAL_SITL/RCOutput.h

@ -18,6 +18,13 @@ public: @@ -18,6 +18,13 @@ public:
void cork(void) override;
void push(void) override;
/*
Serial LED emulation
*/
bool set_neopixel_num_LEDs(const uint16_t chan, uint8_t num_leds) override;
void set_neopixel_rgb_data(const uint16_t chan, uint32_t ledmask, uint8_t red, uint8_t green, uint8_t blue) override;
void neopixel_send(void) override;
private:
SITL_State *_sitlState;
uint16_t _freq_hz;

Loading…
Cancel
Save