mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Merge pull request #2455 from martinbudden/bf_ledstrip_fix
Fix ledstrip merge error
This commit is contained in:
commit
90393d5a12
1 changed files with 22 additions and 26 deletions
|
@ -90,7 +90,6 @@ PG_REGISTER_WITH_RESET_FN(specialColorIndexes_t, specialColors, PG_SPECIAL_COLOR
|
||||||
|
|
||||||
static bool ledStripInitialised = false;
|
static bool ledStripInitialised = false;
|
||||||
static bool ledStripEnabled = true;
|
static bool ledStripEnabled = true;
|
||||||
static ledStripConfig_t * currentLedStripConfig;
|
|
||||||
|
|
||||||
static void ledStripDisable(void);
|
static void ledStripDisable(void);
|
||||||
|
|
||||||
|
@ -185,7 +184,7 @@ STATIC_UNIT_TESTED void updateDimensions(void)
|
||||||
int minY = LED_XY_MASK;
|
int minY = LED_XY_MASK;
|
||||||
|
|
||||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
|
|
||||||
int ledX = ledGetX(ledConfig);
|
int ledX = ledGetX(ledConfig);
|
||||||
maxX = MAX(ledX, maxX);
|
maxX = MAX(ledX, maxX);
|
||||||
|
@ -219,7 +218,7 @@ STATIC_UNIT_TESTED void updateLedCount(void)
|
||||||
int count = 0, countRing = 0, countScanner= 0;
|
int count = 0, countRing = 0, countScanner= 0;
|
||||||
|
|
||||||
for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < LED_MAX_STRIP_LENGTH; ledIndex++) {
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
|
|
||||||
if (!(*ledConfig))
|
if (!(*ledConfig))
|
||||||
break;
|
break;
|
||||||
|
@ -248,7 +247,7 @@ void reevaluateLedConfig(void)
|
||||||
// get specialColor by index
|
// get specialColor by index
|
||||||
static hsvColor_t* getSC(ledSpecialColorIds_e index)
|
static hsvColor_t* getSC(ledSpecialColorIds_e index)
|
||||||
{
|
{
|
||||||
return ¤tLedStripConfig->colors[currentLedStripConfig->specialColors.color[index]];
|
return &ledStripConfigMutable()->colors[ledStripConfig()->specialColors.color[index]];
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char directionCodes[LED_DIRECTION_COUNT] = { 'N', 'E', 'S', 'W', 'U', 'D' };
|
static const char directionCodes[LED_DIRECTION_COUNT] = { 'N', 'E', 'S', 'W', 'U', 'D' };
|
||||||
|
@ -272,7 +271,7 @@ bool parseLedStripConfig(int ledIndex, const char *config)
|
||||||
};
|
};
|
||||||
static const char chunkSeparators[PARSE_STATE_COUNT] = {',', ':', ':', ':', '\0'};
|
static const char chunkSeparators[PARSE_STATE_COUNT] = {',', ':', ':', ':', '\0'};
|
||||||
|
|
||||||
ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
ledConfig_t *ledConfig = &ledStripConfigMutable()->ledConfigs[ledIndex];
|
||||||
memset(ledConfig, 0, sizeof(ledConfig_t));
|
memset(ledConfig, 0, sizeof(ledConfig_t));
|
||||||
|
|
||||||
int x = 0, y = 0, color = 0; // initialize to prevent warnings
|
int x = 0, y = 0, color = 0; // initialize to prevent warnings
|
||||||
|
@ -383,7 +382,7 @@ typedef enum {
|
||||||
|
|
||||||
static quadrant_e getLedQuadrant(const int ledIndex)
|
static quadrant_e getLedQuadrant(const int ledIndex)
|
||||||
{
|
{
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
|
|
||||||
int x = ledGetX(ledConfig);
|
int x = ledGetX(ledConfig);
|
||||||
int y = ledGetY(ledConfig);
|
int y = ledGetY(ledConfig);
|
||||||
|
@ -403,12 +402,12 @@ static quadrant_e getLedQuadrant(const int ledIndex)
|
||||||
|
|
||||||
static hsvColor_t* getDirectionalModeColor(const int ledIndex, const modeColorIndexes_t *modeColors)
|
static hsvColor_t* getDirectionalModeColor(const int ledIndex, const modeColorIndexes_t *modeColors)
|
||||||
{
|
{
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
const int ledDirection = ledGetDirection(ledConfig);
|
const int ledDirection = ledGetDirection(ledConfig);
|
||||||
|
|
||||||
for (unsigned i = 0; i < LED_DIRECTION_COUNT; i++) {
|
for (unsigned i = 0; i < LED_DIRECTION_COUNT; i++) {
|
||||||
if (ledDirection & (1 << i)) {
|
if (ledDirection & (1 << i)) {
|
||||||
return ¤tLedStripConfig->colors[modeColors->color[i]];
|
return &ledStripConfigMutable()->colors[modeColors->color[i]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +435,7 @@ static const struct {
|
||||||
static void applyLedFixedLayers()
|
static void applyLedFixedLayers()
|
||||||
{
|
{
|
||||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
hsvColor_t color = *getSC(LED_SCOLOR_BACKGROUND);
|
hsvColor_t color = *getSC(LED_SCOLOR_BACKGROUND);
|
||||||
|
|
||||||
int fn = ledGetFunction(ledConfig);
|
int fn = ledGetFunction(ledConfig);
|
||||||
|
@ -444,13 +443,13 @@ static void applyLedFixedLayers()
|
||||||
|
|
||||||
switch (fn) {
|
switch (fn) {
|
||||||
case LED_FUNCTION_COLOR:
|
case LED_FUNCTION_COLOR:
|
||||||
color = currentLedStripConfig->colors[ledGetColor(ledConfig)];
|
color = ledStripConfig()->colors[ledGetColor(ledConfig)];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LED_FUNCTION_FLIGHT_MODE:
|
case LED_FUNCTION_FLIGHT_MODE:
|
||||||
for (unsigned i = 0; i < ARRAYLEN(flightModeToLed); i++)
|
for (unsigned i = 0; i < ARRAYLEN(flightModeToLed); i++)
|
||||||
if (!flightModeToLed[i].flightMode || FLIGHT_MODE(flightModeToLed[i].flightMode)) {
|
if (!flightModeToLed[i].flightMode || FLIGHT_MODE(flightModeToLed[i].flightMode)) {
|
||||||
hsvColor_t *directionalColor = getDirectionalModeColor(ledIndex, ¤tLedStripConfig->modeColors[flightModeToLed[i].ledMode]);
|
hsvColor_t *directionalColor = getDirectionalModeColor(ledIndex, &ledStripConfig()->modeColors[flightModeToLed[i].ledMode]);
|
||||||
if (directionalColor) {
|
if (directionalColor) {
|
||||||
color = *directionalColor;
|
color = *directionalColor;
|
||||||
}
|
}
|
||||||
|
@ -491,7 +490,7 @@ static void applyLedFixedLayers()
|
||||||
static void applyLedHsv(uint32_t mask, const hsvColor_t *color)
|
static void applyLedHsv(uint32_t mask, const hsvColor_t *color)
|
||||||
{
|
{
|
||||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
if ((*ledConfig & mask) == mask)
|
if ((*ledConfig & mask) == mask)
|
||||||
setLedHsv(ledIndex, color);
|
setLedHsv(ledIndex, color);
|
||||||
}
|
}
|
||||||
|
@ -689,7 +688,7 @@ static void applyLedIndicatorLayer(bool updateNow, timeUs_t *timer)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
if (ledGetOverlayBit(ledConfig, LED_OVERLAY_INDICATOR)) {
|
if (ledGetOverlayBit(ledConfig, LED_OVERLAY_INDICATOR)) {
|
||||||
if (getLedQuadrant(ledIndex) & quadrants)
|
if (getLedQuadrant(ledIndex) & quadrants)
|
||||||
setLedHsv(ledIndex, flashColor);
|
setLedHsv(ledIndex, flashColor);
|
||||||
|
@ -729,7 +728,7 @@ static void applyLedThrustRingLayer(bool updateNow, timeUs_t *timer)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
if (ledGetFunction(ledConfig) == LED_FUNCTION_THRUST_RING) {
|
if (ledGetFunction(ledConfig) == LED_FUNCTION_THRUST_RING) {
|
||||||
|
|
||||||
bool applyColor;
|
bool applyColor;
|
||||||
|
@ -740,7 +739,7 @@ static void applyLedThrustRingLayer(bool updateNow, timeUs_t *timer)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (applyColor) {
|
if (applyColor) {
|
||||||
const hsvColor_t *ringColor = ¤tLedStripConfig->colors[ledGetColor(ledConfig)];
|
const hsvColor_t *ringColor = &ledStripConfig()->colors[ledGetColor(ledConfig)];
|
||||||
setLedHsv(ledIndex, ringColor);
|
setLedHsv(ledIndex, ringColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -856,7 +855,7 @@ static void applyLedAnimationLayer(bool updateNow, timeUs_t *timer)
|
||||||
int nextRow = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0;
|
int nextRow = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0;
|
||||||
|
|
||||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||||
const ledConfig_t *ledConfig = ¤tLedStripConfig->ledConfigs[ledIndex];
|
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
|
||||||
|
|
||||||
if (ledGetY(ledConfig) == previousRow) {
|
if (ledGetY(ledConfig) == previousRow) {
|
||||||
setLedHsv(ledIndex, getSC(LED_SCOLOR_ANIMATION));
|
setLedHsv(ledIndex, getSC(LED_SCOLOR_ANIMATION));
|
||||||
|
@ -918,7 +917,7 @@ void ledStripUpdate(timeUs_t currentTimeUs)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_RC_MODE_ACTIVE(BOXLEDLOW) && !(currentLedStripConfig->ledstrip_visual_beeper && isBeeperOn())) {
|
if (IS_RC_MODE_ACTIVE(BOXLEDLOW) && !(ledStripConfig()->ledstrip_visual_beeper && isBeeperOn())) {
|
||||||
if (ledStripEnabled) {
|
if (ledStripEnabled) {
|
||||||
ledStripDisable();
|
ledStripDisable();
|
||||||
ledStripEnabled = false;
|
ledStripEnabled = false;
|
||||||
|
@ -949,7 +948,7 @@ void ledStripUpdate(timeUs_t currentTimeUs)
|
||||||
// apply all layers; triggered timed functions has to update timers
|
// apply all layers; triggered timed functions has to update timers
|
||||||
|
|
||||||
scaledThrottle = ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, 100) : 0;
|
scaledThrottle = ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, 100) : 0;
|
||||||
scaledAux = scaleRange(rcData[currentLedStripConfig->ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1);
|
scaledAux = scaleRange(rcData[ledStripConfig()->ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1);
|
||||||
|
|
||||||
applyLedFixedLayers();
|
applyLedFixedLayers();
|
||||||
|
|
||||||
|
@ -965,7 +964,7 @@ bool parseColor(int index, const char *colorConfig)
|
||||||
{
|
{
|
||||||
const char *remainingCharacters = colorConfig;
|
const char *remainingCharacters = colorConfig;
|
||||||
|
|
||||||
hsvColor_t *color = ¤tLedStripConfig->colors[index];
|
hsvColor_t *color = &ledStripConfigMutable()->colors[index];
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
static const uint16_t hsv_limit[HSV_COLOR_COMPONENT_COUNT] = {
|
static const uint16_t hsv_limit[HSV_COLOR_COMPONENT_COUNT] = {
|
||||||
|
@ -1018,15 +1017,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 (modeIndex < LED_MODE_COUNT) { // modeIndex_e is unsigned, so one-sided test is enough
|
||||||
if(modeColorIndex < 0 || modeColorIndex >= LED_DIRECTION_COUNT)
|
if(modeColorIndex < 0 || modeColorIndex >= LED_DIRECTION_COUNT)
|
||||||
return false;
|
return false;
|
||||||
currentLedStripConfig->modeColors[modeIndex].color[modeColorIndex] = colorIndex;
|
ledStripConfigMutable()->modeColors[modeIndex].color[modeColorIndex] = colorIndex;
|
||||||
} else if (modeIndex == LED_SPECIAL) {
|
} else if (modeIndex == LED_SPECIAL) {
|
||||||
if (modeColorIndex < 0 || modeColorIndex >= LED_SPECIAL_COLOR_COUNT)
|
if (modeColorIndex < 0 || modeColorIndex >= LED_SPECIAL_COLOR_COUNT)
|
||||||
return false;
|
return false;
|
||||||
currentLedStripConfig->specialColors.color[modeColorIndex] = colorIndex;
|
ledStripConfigMutable()->specialColors.color[modeColorIndex] = colorIndex;
|
||||||
} else if (modeIndex == LED_AUX_CHANNEL) {
|
} else if (modeIndex == LED_AUX_CHANNEL) {
|
||||||
if (modeColorIndex < 0 || modeColorIndex >= 1)
|
if (modeColorIndex < 0 || modeColorIndex >= 1)
|
||||||
return false;
|
return false;
|
||||||
currentLedStripConfig->ledstrip_aux_channel = colorIndex;
|
ledStripConfigMutable()->ledstrip_aux_channel = colorIndex;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1094,13 +1093,10 @@ void ledStripInit()
|
||||||
|
|
||||||
void ledStripEnable(void)
|
void ledStripEnable(void)
|
||||||
{
|
{
|
||||||
if (currentLedStripConfig == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
reevaluateLedConfig();
|
reevaluateLedConfig();
|
||||||
ledStripInitialised = true;
|
ledStripInitialised = true;
|
||||||
|
|
||||||
ws2811LedStripInit(currentLedStripConfig->ioTag);
|
ws2811LedStripInit(ledStripConfig()->ioTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ledStripDisable(void)
|
static void ledStripDisable(void)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue