Adding code to change led colors based on mode and armed state.

This commit is contained in:
Dominic Clifton 2014-07-02 21:53:50 +01:00
parent de04acd7e1
commit 36990951df
2 changed files with 121 additions and 47 deletions

View File

@ -35,10 +35,6 @@ volatile uint8_t ws2811LedDataTransferInProgress = 0;
static rgbColor24bpp_t ledColorBuffer[WS2811_LED_STRIP_LENGTH]; static rgbColor24bpp_t ledColorBuffer[WS2811_LED_STRIP_LENGTH];
const rgbColor24bpp_t black = { {0, 0, 0} };
const rgbColor24bpp_t orange = { {255, 128, 0} };
const rgbColor24bpp_t white = { {255, 255, 255} };
void setLedColor(uint16_t index, const rgbColor24bpp_t *color) void setLedColor(uint16_t index, const rgbColor24bpp_t *color)
{ {
ledColorBuffer[index].rgb = color->rgb; ledColorBuffer[index].rgb = color->rgb;

View File

@ -19,6 +19,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <platform.h>
#include <common/maths.h> #include <common/maths.h>
#include "drivers/light_ws2811strip.h" #include "drivers/light_ws2811strip.h"
@ -44,6 +45,11 @@
#define LED_PINK {255, 0, 128} #define LED_PINK {255, 0, 128}
#define LED_PURPLE {192, 64, 255} #define LED_PURPLE {192, 64, 255}
const rgbColor24bpp_t black = { LED_BLACK };
const rgbColor24bpp_t orange = { LED_ORANGE };
const rgbColor24bpp_t white = { LED_WHITE };
const rgbColor24bpp_t green = { LED_GREEN };
/* /*
* 0..5 - rear right cluster, 0..2 rear 3..5 right * 0..5 - rear right cluster, 0..2 rear 3..5 right
* 6..11 - front right cluster, 6..8 rear, 9..11 front * 6..11 - front right cluster, 6..8 rear, 9..11 front
@ -119,6 +125,11 @@ static const ledConfig_t ledConfigs[WS2811_LED_STRIP_LENGTH] = {
{ LED_XY( 2, 9), LED_DIRECTION_SOUTH | LED_FUNCTION_MODE | LED_FUNCTION_BATTERY } { LED_XY( 2, 9), LED_DIRECTION_SOUTH | LED_FUNCTION_MODE | LED_FUNCTION_BATTERY }
}; };
// grid offsets
uint8_t highestYValueForNorth;
uint8_t lowestYValueForSouth;
// timers
uint32_t nextIndicatorFlashAt = 0; uint32_t nextIndicatorFlashAt = 0;
uint32_t nextBatteryFlashAt = 0; uint32_t nextBatteryFlashAt = 0;
@ -141,7 +152,7 @@ typedef union {
struct modeColors_s colors; struct modeColors_s colors;
} modeColors_t; } modeColors_t;
static const modeColors_t orientationColors = { static const modeColors_t orientationModeColors = {
.raw = { .raw = {
{LED_WHITE}, {LED_WHITE},
{LED_BLUE}, {LED_BLUE},
@ -152,60 +163,113 @@ static const modeColors_t orientationColors = {
} }
}; };
static const modeColors_t headfreeModeColors = {
.raw = {
{LED_PINK},
{LED_BLACK},
{LED_ORANGE},
{LED_BLACK},
{LED_BLACK},
{LED_BLACK}
}
};
static const modeColors_t horizonModeColors = {
.raw = {
{LED_BLUE},
{LED_BLACK},
{LED_YELLOW},
{LED_BLACK},
{LED_BLACK},
{LED_BLACK}
}
};
static const modeColors_t angleModeColors = {
.raw = {
{LED_CYAN},
{LED_BLACK},
{LED_YELLOW},
{LED_BLACK},
{LED_BLACK},
{LED_BLACK}
}
};
static const modeColors_t magModeColors = {
.raw = {
{LED_PURPLE},
{LED_BLACK},
{LED_ORANGE},
{LED_BLACK},
{LED_BLACK},
{LED_BLACK}
}
};
void applyDirectionalModeColor(uint8_t ledIndex, const ledConfig_t *ledConfig, const modeColors_t *modeColors)
{
if (ledConfig->flags & LED_DIRECTION_NORTH && LED_Y(ledConfig) < highestYValueForNorth) {
setLedColor(ledIndex, &modeColors->colors.north);
return;
}
if (ledConfig->flags & LED_DIRECTION_SOUTH && LED_Y(ledConfig) >= lowestYValueForSouth) {
setLedColor(ledIndex, &modeColors->colors.south);
return;
}
}
void applyModeColor(uint8_t ledIndex, const ledConfig_t *ledConfig, const modeColors_t *modeColors)
{
if (!(ledConfig->flags & LED_FUNCTION_MODE)) {
return;
}
applyDirectionalModeColor(ledIndex, ledConfig, modeColors);
}
void applyOrientationColor(uint8_t ledIndex, const ledConfig_t *ledConfig)
{
if (!(ledConfig->flags & LED_FUNCTION_MODE)) {
setLedColor(ledIndex, &black);
return;
}
applyModeColor(ledIndex, ledConfig, &orientationModeColors);
setLedColor(ledIndex, &black);
}
void applyLEDModeLayer(void) void applyLEDModeLayer(void)
{ {
const ledConfig_t *ledConfig; const ledConfig_t *ledConfig;
uint8_t highestYValueForNorth = (ledGridHeight / 2) - 1;
highestYValueForNorth &= ~(1 << 0); // make even
uint8_t lowestYValueForSouth = (ledGridHeight / 2) - 1;
if (lowestYValueForSouth & 1) {
lowestYValueForSouth = min(lowestYValueForSouth + 1, ledGridHeight - 1);
}
uint8_t ledIndex; uint8_t ledIndex;
for (ledIndex = 0; ledIndex < WS2811_LED_STRIP_LENGTH; ledIndex++) { for (ledIndex = 0; ledIndex < WS2811_LED_STRIP_LENGTH; ledIndex++) {
ledConfig = &ledConfigs[ledIndex]; ledConfig = &ledConfigs[ledIndex];
if (!(ledConfig->flags & LED_FUNCTION_MODE)) {
setLedColor(ledIndex, &black);
continue;
}
if (ledConfig->flags & LED_DIRECTION_NORTH && LED_Y(ledConfig) < highestYValueForNorth) {
setLedColor(ledIndex, &orientationColors.colors.north);
continue;
}
if (ledConfig->flags & LED_DIRECTION_SOUTH && LED_Y(ledConfig) >= lowestYValueForSouth) {
setLedColor(ledIndex, &orientationColors.colors.south);
continue;
}
setLedColor(ledIndex, &black);
}
/*
if (f.ARMED) { if (f.ARMED) {
setStripColors(stripOrientation); applyOrientationColor(ledIndex, ledConfig);
} else { } else {
setStripColors(stripReds); setLedColor(ledIndex, &green);
} }
if (f.HEADFREE_MODE) { if (f.HEADFREE_MODE) {
setStripColors(stripHeadfree); applyModeColor(ledIndex, ledConfig, &headfreeModeColors);
#ifdef MAG #ifdef MAG
} else if (f.MAG_MODE) { } else if (f.MAG_MODE) {
setStripColors(stripMag); applyModeColor(ledIndex, ledConfig, &magModeColors);
#endif #endif
} else if (f.HORIZON_MODE) { } else if (f.HORIZON_MODE) {
setStripColors(stripHorizon); applyModeColor(ledIndex, ledConfig, &horizonModeColors);
} else if (f.ANGLE_MODE) { } else if (f.ANGLE_MODE) {
setStripColors(stripAngle); applyModeColor(ledIndex, ledConfig, &angleModeColors);
} }
*/
} }
}
void updateLedStrip(void) void updateLedStrip(void)
{ {
if (!isWS2811LedStripReady()) { if (!isWS2811LedStripReady()) {
@ -287,12 +351,26 @@ void updateLedStrip(void)
ws2811UpdateStrip(); ws2811UpdateStrip();
} }
void determineLedStripDimensions() { void determineLedStripDimensions()
{
// TODO iterate over ledConfigs and determine programatically // TODO iterate over ledConfigs and determine programatically
ledGridWidth = 12; ledGridWidth = 12;
ledGridHeight = 12; ledGridHeight = 12;
} }
void ledStripInit(void) { void determineOrientationLimits(void)
determineLedStripDimensions(); {
highestYValueForNorth = (ledGridHeight / 2) - 1;
highestYValueForNorth &= ~(1 << 0); // make even
lowestYValueForSouth = (ledGridHeight / 2) - 1;
if (lowestYValueForSouth & 1) {
lowestYValueForSouth = min(lowestYValueForSouth + 1, ledGridHeight - 1);
}
}
void ledStripInit(void)
{
determineLedStripDimensions();
determineOrientationLimits();
} }