1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 04:45:24 +03:00

Merge pull request #5266 from etracer65/ledstrip_optimization

Optimize ledstip by disabling unassigned overlays
This commit is contained in:
Michael Keller 2018-02-22 23:38:29 +13:00 committed by GitHub
commit 9d7c8fbd46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 8 deletions

View file

@ -251,6 +251,7 @@ void reevaluateLedConfig(void)
updateLedCount();
updateDimensions();
updateLedRingCounts();
updateRequiredOverlay();
}
// get specialColor by index
@ -1013,6 +1014,7 @@ typedef enum {
} timId_e;
static timeUs_t timerVal[timTimerCount];
static bool requiredTimerLayer[timTimerCount];
// function to apply layer.
// function must replan self using timer pointer
@ -1040,6 +1042,31 @@ static applyLayerFn_timed* layerTable[] = {
[timRing] = &applyLedThrustRingLayer
};
bool isOverlayTypeUsed(ledOverlayId_e overlayType)
{
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
if (ledGetOverlayBit(ledConfig, overlayType)) {
return true;
}
}
return false;
}
void updateRequiredOverlay(void)
{
for (int timID = 0; timID < timTimerCount; timID++) {
requiredTimerLayer[timID] = true;
}
requiredTimerLayer[timBlink] = isOverlayTypeUsed(LED_OVERLAY_BLINK);
requiredTimerLayer[timLarson] = isOverlayTypeUsed(LED_OVERLAY_LARSON_SCANNER);
requiredTimerLayer[timWarning] = isOverlayTypeUsed(LED_OVERLAY_WARNING);
#ifdef USE_VTX_COMMON
requiredTimerLayer[timVtx] = isOverlayTypeUsed(LED_OVERLAY_VTX);
#endif
requiredTimerLayer[timIndicator] = isOverlayTypeUsed(LED_OVERLAY_INDICATOR);
}
void ledStripUpdate(timeUs_t currentTimeUs)
{
if (!(ledStripInitialised && isWS2811LedStripReady())) {
@ -1060,14 +1087,16 @@ void ledStripUpdate(timeUs_t currentTimeUs)
// test all led timers, setting corresponding bits
uint32_t timActive = 0;
for (timId_e timId = 0; timId < timTimerCount; timId++) {
// sanitize timer value, so that it can be safely incremented. Handles inital timerVal value.
const timeDelta_t delta = cmpTimeUs(now, timerVal[timId]);
// max delay is limited to 5s
if (delta < 0 && delta > -MAX_TIMER_DELAY)
continue; // not ready yet
timActive |= 1 << timId;
if (delta >= 100 * 1000 || delta < 0) {
timerVal[timId] = now;
if (requiredTimerLayer[timId]) {
// sanitize timer value, so that it can be safely incremented. Handles inital timerVal value.
const timeDelta_t delta = cmpTimeUs(now, timerVal[timId]);
// max delay is limited to 5s
if (delta < 0 && delta > -MAX_TIMER_DELAY)
continue; // not ready yet
timActive |= 1 << timId;
if (delta >= 100 * 1000 || delta < 0) {
timerVal[timId] = now;
}
}
}

View file

@ -187,3 +187,5 @@ void applyDefaultLedStripConfig(ledConfig_t *ledConfig);
void applyDefaultColors(hsvColor_t *colors);
void applyDefaultModeColors(modeColorIndexes_t *modeColors);
void applyDefaultSpecialColors(specialColorIndexes_t *specialColors);
void updateRequiredOverlay(void);