From 8d36b2ae89b25091e78f02911eaf87a07f9511d0 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Fri, 18 Nov 2016 13:26:22 +1300 Subject: [PATCH] Cleaned up some ambiguos names / unlogical value ranges in 'ledstrip.c'. --- src/main/io/ledstrip.c | 48 ++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/io/ledstrip.c b/src/main/io/ledstrip.c index 8c7b37dbe..d535379ab 100644 --- a/src/main/io/ledstrip.c +++ b/src/main/io/ledstrip.c @@ -92,8 +92,7 @@ static void ledStripDisable(void); //#define USE_LED_ANIMATION -#define LED_STRIP_HZ(hz) ((int32_t)((1000 * 1000) / (hz))) -#define LED_STRIP_MS(ms) ((int32_t)(1000 * (ms))) +#define HZ_TO_MICROS(hz) ((int32_t)((1000 * 1000) / (hz))) #if LED_MAX_STRIP_LENGTH > WS2811_LED_STRIP_LENGTH # error "Led strip length must match driver" @@ -536,7 +535,7 @@ static void applyLedWarningLayer(bool updateNow, uint32_t *timer) if (!ARMING_FLAG(ARMED) && !ARMING_FLAG(OK_TO_ARM)) warningFlags |= 1 << WARNING_ARMING_DISABLED; } - *timer += LED_STRIP_HZ(10); + *timer += HZ_TO_MICROS(10); } if (warningFlags) { @@ -568,7 +567,7 @@ static void applyLedBatteryLayer(bool updateNow, uint32_t *timer) static bool flash = false; int state; - int timeOffset = 1; + int frequency = 1; if (updateNow) { state = getBatteryState(); @@ -576,19 +575,19 @@ static void applyLedBatteryLayer(bool updateNow, uint32_t *timer) switch (state) { case BATTERY_OK: flash = false; - timeOffset = 1; + frequency = 1; break; case BATTERY_WARNING: - timeOffset = 2; + frequency = 2; break; default: - timeOffset = 8; + frequency = 8; break; } flash = !flash; } - *timer += LED_STRIP_HZ(timeOffset); + *timer += HZ_TO_MICROS(frequency); if (!flash) { hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND); @@ -601,24 +600,24 @@ static void applyLedRssiLayer(bool updateNow, uint32_t *timer) static bool flash = false; int state; - int timeOffset = 1; + int frequency = 1; if (updateNow) { state = (rssi * 100) / 1023; if (state > 50) { flash = false; - timeOffset = 1; + frequency = 1; } else if (state > 20) { - timeOffset = 2; + frequency = 2; } else { - timeOffset = 8; + frequency = 8; } flash = !flash; } - *timer += LED_STRIP_HZ(timeOffset); + *timer += HZ_TO_MICROS(frequency); if (!flash) { hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND); @@ -643,7 +642,7 @@ static void applyLedGpsLayer(bool updateNow, uint32_t *timer) gpsFlashCounter++; gpsPauseCounter = 1; } - *timer += LED_STRIP_HZ(2.5); + *timer += HZ_TO_MICROS(2.5f); } const hsvColor_t *gpsColor; @@ -675,11 +674,11 @@ static void applyLedIndicatorLayer(bool updateNow, uint32_t *timer) // calculate update frequency int scale = MAX(ABS(rcCommand[ROLL]), ABS(rcCommand[PITCH])); // 0 - 500 scale = scale - INDICATOR_DEADBAND; // start increasing frequency right after deadband - *timer += LED_STRIP_HZ(5 + (45 * scale) / (500 - INDICATOR_DEADBAND)); // 5 - 50Hz update, 2.5 - 25Hz blink + *timer += HZ_TO_MICROS(5 + (45 * scale) / (500 - INDICATOR_DEADBAND)); // 5 - 50Hz update, 2.5 - 25Hz blink flash = !flash; } else { - *timer += LED_STRIP_HZ(5); // try again soon + *timer += HZ_TO_MICROS(5); // try again soon } } @@ -737,8 +736,7 @@ static void applyLedThrustRingLayer(bool updateNow, uint32_t *timer) if (updateNow) { rotationPhase = rotationPhase > 0 ? rotationPhase - 1 : ledCounts.ringSeqLen - 1; - int scale = scaledThrottle; // ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 10, 100) : 10; - *timer += LED_STRIP_HZ(5) * 10 / scale; // 5 - 50Hz update rate + *timer += HZ_TO_MICROS(5 + (45 * scaledThrottle) / 100); // 5 - 50Hz update rate } for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) { @@ -806,7 +804,7 @@ static void applyLarsonScannerLayer(bool updateNow, uint32_t *timer) if (updateNow) { larsonScannerNextStep(&larsonParameters, 15); - *timer += LED_STRIP_HZ(60); + *timer += HZ_TO_MICROS(60); } int scannerLedIndex = 0; @@ -835,7 +833,7 @@ static void applyLedBlinkLayer(bool updateNow, uint32_t *timer) if (blinkMask <= 1) blinkMask = blinkPattern; - *timer += LED_STRIP_HZ(10); + *timer += HZ_TO_MICROS(10); } bool ledOn = (blinkMask & 1); // b_b_____... @@ -844,7 +842,7 @@ static void applyLedBlinkLayer(bool updateNow, uint32_t *timer) const ledConfig_t *ledConfig = &ledConfigs[i]; if (ledGetOverlayBit(ledConfig, LED_OVERLAY_BLINK) || - (ledGetOverlayBit(ledConfig, LED_OVERLAY_LANDING_FLASH) && scaledThrottle < 55 && scaledThrottle > 10)) { + (ledGetOverlayBit(ledConfig, LED_OVERLAY_LANDING_FLASH) && scaledThrottle < 50)) { setLedHsv(i, getSC(LED_SCOLOR_BLINKBACKGROUND)); } } @@ -858,7 +856,7 @@ static void applyLedAnimationLayer(bool updateNow, uint32_t *timer) const int animationFrames = ledGridHeight; if(updateNow) { frameCounter = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0; - *timer += LED_STRIP_HZ(20); + *timer += HZ_TO_MICROS(20); } if (ARMING_FLAG(ARMED)) @@ -948,10 +946,10 @@ void ledStripUpdate(uint32_t currentTime) // sanitize timer value, so that it can be safely incremented. Handles inital timerVal value. // max delay is limited to 5s int32_t delta = cmp32(now, timerVal[timId]); - if (delta < 0 && delta > -LED_STRIP_MS(5000)) + if (delta < 0 && delta > -HZ_TO_MICROS(0.2f)) continue; // not ready yet timActive |= 1 << timId; - if (delta >= LED_STRIP_MS(100) || delta < 0) { + if (delta >= HZ_TO_MICROS(10) || delta < 0) { timerVal[timId] = now; } } @@ -961,7 +959,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; + 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); applyLedFixedLayers();