1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 08:15:30 +03:00

Cleanup WS2811 code and sanitize API.

Removed many magic numbers.
Deduplicated code.
Removed unnecessary local variable usage.

The LED Strip is initialised to WHITE briefly on power up so that it's
possible to visually check that all LEDs are functioning correctly -
white uses each individual RGB diode and draws maximum power.

Introduced an API to allow any code to change any or all LED colors
individually.  This takes a little ram since an additional buffer is
needed - 3 bytes per LED, in addition to the DMA buffer.
This commit is contained in:
Dominic Clifton 2014-06-08 02:58:30 +01:00
parent c82754f5dc
commit 651a433718
3 changed files with 129 additions and 110 deletions

View file

@ -348,48 +348,34 @@ void updateInflightCalibrationState(void)
}
}
static const uint8_t stripOrientation[][3] =
static const rgbColor24bpp_t stripOrientation[] =
{
{0, 255, 0},
{0, 255, 0},
{0, 255, 0},
{0, 255, 0},
{0, 255, 0},
{{0, 255, 0}},
{{0, 255, 0}},
{{0, 255, 0}},
{{0, 255, 0}},
{{0, 255, 0}},
{255, 0, 0},
{255, 0, 0},
{255, 0, 0},
{255, 0, 0},
{255, 0, 0}
{{255, 0, 0}},
{{255, 0, 0}},
{{255, 0, 0}},
{{255, 0, 0}},
{{255, 0, 0}}
};
static const uint8_t stripOff[][3] =
static const rgbColor24bpp_t stripReds[] =
{
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
{0, 0, 0},
};
static const uint8_t stripRed[][3] =
{
{32, 0, 0},
{96, 0, 0},
{160, 0, 0},
{224, 0, 0},
{255, 0, 0},
{255, 0, 0},
{224, 0, 0},
{160, 0, 0},
{96, 0, 0},
{32, 0, 0},
{{ 32, 0, 0}},
{{ 96, 0, 0}},
{{160, 0, 0}},
{{224, 0, 0}},
{{255, 0, 0}},
{{255, 0, 0}},
{{224, 0, 0}},
{{160, 0, 0}},
{{ 96, 0, 0}},
{{ 32, 0, 0}},
};
uint32_t lastStripUpdateAt = 0;
@ -410,17 +396,19 @@ void updateLedStrip(void)
if (stripState == 0) {
if (f.ARMED) {
ws2812SetStripColors(stripOrientation, sizeof(stripOrientation) / sizeof(stripOrientation[0]));
setStripColors(stripOrientation);
} else {
ws2812SetStripColors(stripRed, sizeof(stripRed) / sizeof(stripRed[0]));
setStripColors(stripReds);
}
stripState = 1;
} else {
if (feature(FEATURE_VBAT) && shouldSoundBatteryAlarm()) {
ws2812SetStripColors(stripOff, sizeof(stripOff) / sizeof(stripOff[0]));
setStripColor(&black);
}
stripState = 0;
}
ws2811UpdateStrip();
}