mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 16:55:36 +03:00
Merge remote-tracking branch 'betaflight/master' into bfdev-osd-cms-separation-poc
This commit is contained in:
commit
e9a2f2b2c1
42 changed files with 640 additions and 344 deletions
|
@ -86,6 +86,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);
|
||||
|
||||
|
@ -168,6 +169,7 @@ static const specialColorIndexes_t defaultSpecialColors[] = {
|
|||
};
|
||||
|
||||
static int scaledThrottle;
|
||||
static int scaledAux;
|
||||
|
||||
static void updateLedRingCounts(void);
|
||||
|
||||
|
@ -177,7 +179,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);
|
||||
|
@ -199,7 +201,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;
|
||||
|
@ -229,7 +231,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' };
|
||||
|
@ -251,9 +253,9 @@ bool parseLedStripConfig(int ledIndex, const char *config)
|
|||
RING_COLORS,
|
||||
PARSE_STATE_COUNT
|
||||
};
|
||||
static const char chunkSeparators[PARSE_STATE_COUNT] = {',', ':', ':',':', '\0'};
|
||||
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
|
||||
|
@ -372,7 +374,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);
|
||||
|
@ -414,7 +416,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++) {
|
||||
|
@ -422,7 +424,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;
|
||||
}
|
||||
|
@ -448,7 +450,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);
|
||||
|
@ -456,13 +458,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;
|
||||
}
|
||||
|
@ -490,7 +492,7 @@ static void applyLedFixedLayers()
|
|||
}
|
||||
|
||||
if (ledGetOverlayBit(ledConfig, LED_OVERLAY_THROTTLE)) {
|
||||
hOffset += ((scaledThrottle - 10) * 4) / 3;
|
||||
hOffset += scaledAux;
|
||||
}
|
||||
|
||||
color.h = (color.h + hOffset) % (HSV_HUE_MAX + 1);
|
||||
|
@ -503,7 +505,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);
|
||||
}
|
||||
|
@ -699,7 +701,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);
|
||||
|
@ -740,7 +742,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;
|
||||
|
@ -751,7 +753,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);
|
||||
}
|
||||
|
||||
|
@ -867,7 +869,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));
|
||||
|
@ -929,7 +931,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;
|
||||
|
@ -960,6 +962,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[currentLedStripConfig->ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1);
|
||||
|
||||
applyLedFixedLayers();
|
||||
|
||||
|
@ -975,7 +978,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] = {
|
||||
|
@ -1028,11 +1031,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;
|
||||
currentLedStripConfig->ledstrip_aux_channel = colorIndex;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -1090,21 +1097,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