1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 09:45:37 +03:00

Code size reduction when led animation is disabled.

This commit is contained in:
Dominic Clifton 2015-01-15 16:53:14 +00:00
parent 947bb0d918
commit ad65722f0e

View file

@ -50,14 +50,26 @@
static bool ledStripInitialised = false; static bool ledStripInitialised = false;
static failsafe_t* failsafe; static failsafe_t* failsafe;
//#define USE_LED_ANIMATION
// timers
#ifdef USE_LED_ANIMATION
static uint32_t nextAnimationUpdateAt = 0;
#endif
static uint32_t nextIndicatorFlashAt = 0;
static uint32_t nextWarningFlashAt = 0;
#define LED_STRIP_20HZ ((1000 * 1000) / 20)
#define LED_STRIP_10HZ ((1000 * 1000) / 10)
#define LED_STRIP_5HZ ((1000 * 1000) / 5)
#if MAX_LED_STRIP_LENGTH > WS2811_LED_STRIP_LENGTH #if MAX_LED_STRIP_LENGTH > WS2811_LED_STRIP_LENGTH
#error "Led strip length must match driver" #error "Led strip length must match driver"
#endif #endif
hsvColor_t *colors; hsvColor_t *colors;
//#define USE_LED_ANIMATION
// H S V // H S V
#define LED_BLACK { 0, 0, 0} #define LED_BLACK { 0, 0, 0}
#define LED_WHITE { 0, 255, 255} #define LED_WHITE { 0, 255, 255}
@ -438,15 +450,6 @@ void generateLedConfig(uint8_t ledIndex, char *ledConfigBuffer, size_t bufferSiz
sprintf(ledConfigBuffer, "%u,%u:%s:%s", GET_LED_X(ledConfig), GET_LED_Y(ledConfig), directions, functions); sprintf(ledConfigBuffer, "%u,%u:%s:%s", GET_LED_X(ledConfig), GET_LED_Y(ledConfig), directions, functions);
} }
// timers
uint32_t nextAnimationUpdateAt = 0;
uint32_t nextIndicatorFlashAt = 0;
uint32_t nextWarningFlashAt = 0;
#define LED_STRIP_20HZ ((1000 * 1000) / 20)
#define LED_STRIP_10HZ ((1000 * 1000) / 10)
#define LED_STRIP_5HZ ((1000 * 1000) / 5)
void applyDirectionalModeColor(const uint8_t ledIndex, const ledConfig_t *ledConfig, const modeColorIndexes_t *modeColors) void applyDirectionalModeColor(const uint8_t ledIndex, const ledConfig_t *ledConfig, const modeColorIndexes_t *modeColors)
{ {
// apply up/down colors regardless of quadrant. // apply up/down colors regardless of quadrant.
@ -688,6 +691,7 @@ void applyLedThrottleLayer()
} }
} }
#ifdef USE_LED_ANIMATION
static uint8_t frameCounter = 0; static uint8_t frameCounter = 0;
static uint8_t previousRow; static uint8_t previousRow;
@ -705,7 +709,6 @@ static void updateLedAnimationState(void)
frameCounter = (frameCounter + 1) % animationFrames; frameCounter = (frameCounter + 1) % animationFrames;
} }
#ifdef USE_LED_ANIMATION
static void applyLedAnimationLayer(void) static void applyLedAnimationLayer(void)
{ {
const ledConfig_t *ledConfig; const ledConfig_t *ledConfig;
@ -740,11 +743,18 @@ void updateLedStrip(void)
uint32_t now = micros(); uint32_t now = micros();
bool animationUpdateNow = (int32_t)(now - nextAnimationUpdateAt) >= 0L; bool indicatorFlashNow = indicatorFlashNow = (int32_t)(now - nextIndicatorFlashAt) >= 0L;
bool indicatorFlashNow = (int32_t)(now - nextIndicatorFlashAt) >= 0L; bool warningFlashNow =warningFlashNow = (int32_t)(now - nextWarningFlashAt) >= 0L;
bool warningFlashNow = (int32_t)(now - nextWarningFlashAt) >= 0L; #ifdef USE_LED_ANIMATION
bool animationUpdateNow = animationUpdateNow = (int32_t)(now - nextAnimationUpdateAt) >= 0L;
if (!(warningFlashNow || indicatorFlashNow || animationUpdateNow)) { #endif
if (!(
indicatorFlashNow ||
warningFlashNow
#ifdef USE_LED_ANIMATION
|| animationUpdateNow
#endif
)) {
return; return;
} }
@ -779,14 +789,15 @@ void updateLedStrip(void)
applyLedIndicatorLayer(indicatorFlashState); applyLedIndicatorLayer(indicatorFlashState);
#ifdef USE_LED_ANIMATION
if (animationUpdateNow) { if (animationUpdateNow) {
nextAnimationUpdateAt = now + LED_STRIP_20HZ; nextAnimationUpdateAt = now + LED_STRIP_20HZ;
updateLedAnimationState(); updateLedAnimationState();
} }
#ifdef USE_LED_ANIMATION
applyLedAnimationLayer(); applyLedAnimationLayer();
#endif #endif
ws2811UpdateStrip(); ws2811UpdateStrip();
} }