mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Moving LED strip to be configurable via resource command
This commit is contained in:
parent
3b506415c9
commit
e56f915018
18 changed files with 281 additions and 214 deletions
|
@ -88,6 +88,7 @@ PG_REGISTER_WITH_RESET_FN(specialColorIndexes_t, specialColors, PG_SPECIAL_COLOR
|
|||
|
||||
static bool ledStripInitialised = false;
|
||||
static bool ledStripEnabled = true;
|
||||
static ledStripConfig_t * currentLedStripConfig;
|
||||
|
||||
static void ledStripDisable(void);
|
||||
|
||||
|
@ -180,7 +181,7 @@ STATIC_UNIT_TESTED void determineLedStripDimensions(void)
|
|||
int maxY = 0;
|
||||
|
||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
|
||||
maxX = MAX(ledGetX(ledConfig), maxX);
|
||||
maxY = MAX(ledGetY(ledConfig), maxY);
|
||||
|
@ -202,7 +203,7 @@ STATIC_UNIT_TESTED void updateLedCount(void)
|
|||
int count = 0, countRing = 0, countScanner= 0;
|
||||
|
||||
for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) {
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
|
||||
if (!(*ledConfig))
|
||||
break;
|
||||
|
@ -232,7 +233,7 @@ void reevaluateLedConfig(void)
|
|||
// get specialColor by index
|
||||
static hsvColor_t* getSC(ledSpecialColorIds_e index)
|
||||
{
|
||||
return &masterConfig.colors[masterConfig.specialColors.color[index]];
|
||||
return ¤tLedStripConfig->colors[currentLedStripConfig->specialColors.color[index]];
|
||||
}
|
||||
|
||||
static const char directionCodes[LED_DIRECTION_COUNT] = { 'N', 'E', 'S', 'W', 'U', 'D' };
|
||||
|
@ -256,7 +257,7 @@ bool parseLedStripConfig(int ledIndex, const char *config)
|
|||
};
|
||||
static const char chunkSeparators[PARSE_STATE_COUNT] = {',', ':', ':', ':', '\0'};
|
||||
|
||||
ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
memset(ledConfig, 0, sizeof(ledConfig_t));
|
||||
|
||||
int x = 0, y = 0, color = 0; // initialize to prevent warnings
|
||||
|
@ -375,7 +376,7 @@ typedef enum {
|
|||
|
||||
static quadrant_e getLedQuadrant(const int ledIndex)
|
||||
{
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
|
||||
int x = ledGetX(ledConfig);
|
||||
int y = ledGetY(ledConfig);
|
||||
|
@ -417,7 +418,7 @@ static const struct {
|
|||
|
||||
static hsvColor_t* getDirectionalModeColor(const int ledIndex, const modeColorIndexes_t *modeColors)
|
||||
{
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
|
||||
quadrant_e quad = getLedQuadrant(ledIndex);
|
||||
for (unsigned i = 0; i < ARRAYLEN(directionQuadrantMap); i++) {
|
||||
|
@ -425,7 +426,7 @@ static hsvColor_t* getDirectionalModeColor(const int ledIndex, const modeColorIn
|
|||
quadrant_e quadMask = directionQuadrantMap[i].quadrantMask;
|
||||
|
||||
if (ledGetDirectionBit(ledConfig, dir) && (quad & quadMask))
|
||||
return &masterConfig.colors[modeColors->color[dir]];
|
||||
return ¤tLedStripConfig->colors[modeColors->color[dir]];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -451,7 +452,7 @@ static const struct {
|
|||
static void applyLedFixedLayers()
|
||||
{
|
||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
hsvColor_t color = *getSC(LED_SCOLOR_BACKGROUND);
|
||||
|
||||
int fn = ledGetFunction(ledConfig);
|
||||
|
@ -459,13 +460,13 @@ static void applyLedFixedLayers()
|
|||
|
||||
switch (fn) {
|
||||
case LED_FUNCTION_COLOR:
|
||||
color = masterConfig.colors[ledGetColor(ledConfig)];
|
||||
color = currentLedStripConfig->colors[ledGetColor(ledConfig)];
|
||||
break;
|
||||
|
||||
case LED_FUNCTION_FLIGHT_MODE:
|
||||
for (unsigned i = 0; i < ARRAYLEN(flightModeToLed); i++)
|
||||
if (!flightModeToLed[i].flightMode || FLIGHT_MODE(flightModeToLed[i].flightMode)) {
|
||||
hsvColor_t *directionalColor = getDirectionalModeColor(ledIndex, &masterConfig.modeColors[flightModeToLed[i].ledMode]);
|
||||
hsvColor_t *directionalColor = getDirectionalModeColor(ledIndex, ¤tLedStripConfig->modeColors[flightModeToLed[i].ledMode]);
|
||||
if (directionalColor) {
|
||||
color = *directionalColor;
|
||||
}
|
||||
|
@ -506,7 +507,7 @@ static void applyLedFixedLayers()
|
|||
static void applyLedHsv(uint32_t mask, const hsvColor_t *color)
|
||||
{
|
||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
if ((*ledConfig & mask) == mask)
|
||||
setLedHsv(ledIndex, color);
|
||||
}
|
||||
|
@ -702,7 +703,7 @@ static void applyLedIndicatorLayer(bool updateNow, uint32_t *timer)
|
|||
}
|
||||
|
||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
if (ledGetOverlayBit(ledConfig, LED_OVERLAY_INDICATOR)) {
|
||||
if (getLedQuadrant(ledIndex) & quadrants)
|
||||
setLedHsv(ledIndex, flashColor);
|
||||
|
@ -743,7 +744,7 @@ static void applyLedThrustRingLayer(bool updateNow, uint32_t *timer)
|
|||
}
|
||||
|
||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
if (ledGetFunction(ledConfig) == LED_FUNCTION_THRUST_RING) {
|
||||
|
||||
bool applyColor;
|
||||
|
@ -754,7 +755,7 @@ static void applyLedThrustRingLayer(bool updateNow, uint32_t *timer)
|
|||
}
|
||||
|
||||
if (applyColor) {
|
||||
const hsvColor_t *ringColor = &masterConfig.colors[ledGetColor(ledConfig)];
|
||||
const hsvColor_t *ringColor = ¤tLedStripConfig->colors[ledGetColor(ledConfig)];
|
||||
setLedHsv(ledIndex, ringColor);
|
||||
}
|
||||
|
||||
|
@ -870,7 +871,7 @@ static void applyLedAnimationLayer(bool updateNow, uint32_t *timer)
|
|||
int nextRow = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0;
|
||||
|
||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||
const ledConfig_t *ledConfig = &masterConfig.ledConfigs[ledIndex];
|
||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
||||
|
||||
if (ledGetY(ledConfig) == previousRow) {
|
||||
setLedHsv(ledIndex, getSC(LED_SCOLOR_ANIMATION));
|
||||
|
@ -932,7 +933,7 @@ void ledStripUpdate(uint32_t currentTime)
|
|||
return;
|
||||
}
|
||||
|
||||
if (IS_RC_MODE_ACTIVE(BOXLEDLOW) && !(masterConfig.ledstrip_visual_beeper && isBeeperOn())) {
|
||||
if (IS_RC_MODE_ACTIVE(BOXLEDLOW) && !(currentLedStripConfig->ledstrip_visual_beeper && isBeeperOn())) {
|
||||
if (ledStripEnabled) {
|
||||
ledStripDisable();
|
||||
ledStripEnabled = false;
|
||||
|
@ -963,7 +964,7 @@ void ledStripUpdate(uint32_t currentTime)
|
|||
// apply all layers; triggered timed functions has to update timers
|
||||
|
||||
scaledThrottle = ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 10, 100) : 10;
|
||||
scaledAux = scaleRange(rcData[masterConfig.ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1);
|
||||
scaledAux = scaleRange(rcData[currentLedStripConfig->ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1);
|
||||
|
||||
applyLedFixedLayers();
|
||||
|
||||
|
@ -979,7 +980,7 @@ bool parseColor(int index, const char *colorConfig)
|
|||
{
|
||||
const char *remainingCharacters = colorConfig;
|
||||
|
||||
hsvColor_t *color = &masterConfig.colors[index];
|
||||
hsvColor_t *color = ¤tLedStripConfig->colors[index];
|
||||
|
||||
bool result = true;
|
||||
static const uint16_t hsv_limit[HSV_COLOR_COMPONENT_COUNT] = {
|
||||
|
@ -1032,15 +1033,15 @@ bool setModeColor(ledModeIndex_e modeIndex, int modeColorIndex, int colorIndex)
|
|||
if (modeIndex < LED_MODE_COUNT) { // modeIndex_e is unsigned, so one-sided test is enough
|
||||
if(modeColorIndex < 0 || modeColorIndex >= LED_DIRECTION_COUNT)
|
||||
return false;
|
||||
masterConfig.modeColors[modeIndex].color[modeColorIndex] = colorIndex;
|
||||
currentLedStripConfig->modeColors[modeIndex].color[modeColorIndex] = colorIndex;
|
||||
} else if (modeIndex == LED_SPECIAL) {
|
||||
if (modeColorIndex < 0 || modeColorIndex >= LED_SPECIAL_COLOR_COUNT)
|
||||
return false;
|
||||
masterConfig.specialColors.color[modeColorIndex] = colorIndex;
|
||||
currentLedStripConfig->specialColors.color[modeColorIndex] = colorIndex;
|
||||
} else if (modeIndex == LED_AUX_CHANNEL) {
|
||||
if (modeColorIndex < 0 || modeColorIndex >= 1)
|
||||
return false;
|
||||
masterConfig.ledstrip_aux_channel = colorIndex;
|
||||
currentLedStripConfig->ledstrip_aux_channel = colorIndex;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -1098,21 +1099,26 @@ void applyDefaultSpecialColors(specialColorIndexes_t *specialColors)
|
|||
memcpy_fn(specialColors, &defaultSpecialColors, sizeof(defaultSpecialColors));
|
||||
}
|
||||
|
||||
void ledStripInit(ledConfig_t *ledConfigsToUse, hsvColor_t *colorsToUse, modeColorIndexes_t *modeColorsToUse, specialColorIndexes_t *specialColorsToUse)
|
||||
void ledStripInit(ledStripConfig_t *ledStripConfig)
|
||||
{
|
||||
ledConfigs = ledConfigsToUse;
|
||||
colors = colorsToUse;
|
||||
modeColors = modeColorsToUse;
|
||||
specialColors = *specialColorsToUse;
|
||||
currentLedStripConfig = ledStripConfig;
|
||||
|
||||
ledConfigs = currentLedStripConfig->ledConfigs;
|
||||
colors = currentLedStripConfig->colors;
|
||||
modeColors = currentLedStripConfig->modeColors;
|
||||
specialColors = currentLedStripConfig->specialColors;
|
||||
ledStripInitialised = false;
|
||||
}
|
||||
|
||||
void ledStripEnable(void)
|
||||
{
|
||||
if (currentLedStripConfig == NULL) {
|
||||
return;
|
||||
}
|
||||
reevaluateLedConfig();
|
||||
ledStripInitialised = true;
|
||||
|
||||
ws2811LedStripInit();
|
||||
ws2811LedStripInit(currentLedStripConfig->ioTag);
|
||||
}
|
||||
|
||||
static void ledStripDisable(void)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue