mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
Cleaned up some ambiguos names / unlogical value ranges in 'ledstrip.c'.
This commit is contained in:
parent
d4338b1a93
commit
8d36b2ae89
1 changed files with 23 additions and 25 deletions
|
@ -92,8 +92,7 @@ static void ledStripDisable(void);
|
||||||
|
|
||||||
//#define USE_LED_ANIMATION
|
//#define USE_LED_ANIMATION
|
||||||
|
|
||||||
#define LED_STRIP_HZ(hz) ((int32_t)((1000 * 1000) / (hz)))
|
#define HZ_TO_MICROS(hz) ((int32_t)((1000 * 1000) / (hz)))
|
||||||
#define LED_STRIP_MS(ms) ((int32_t)(1000 * (ms)))
|
|
||||||
|
|
||||||
#if LED_MAX_STRIP_LENGTH > WS2811_LED_STRIP_LENGTH
|
#if LED_MAX_STRIP_LENGTH > WS2811_LED_STRIP_LENGTH
|
||||||
# error "Led strip length must match driver"
|
# 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))
|
if (!ARMING_FLAG(ARMED) && !ARMING_FLAG(OK_TO_ARM))
|
||||||
warningFlags |= 1 << WARNING_ARMING_DISABLED;
|
warningFlags |= 1 << WARNING_ARMING_DISABLED;
|
||||||
}
|
}
|
||||||
*timer += LED_STRIP_HZ(10);
|
*timer += HZ_TO_MICROS(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (warningFlags) {
|
if (warningFlags) {
|
||||||
|
@ -568,7 +567,7 @@ static void applyLedBatteryLayer(bool updateNow, uint32_t *timer)
|
||||||
static bool flash = false;
|
static bool flash = false;
|
||||||
|
|
||||||
int state;
|
int state;
|
||||||
int timeOffset = 1;
|
int frequency = 1;
|
||||||
|
|
||||||
if (updateNow) {
|
if (updateNow) {
|
||||||
state = getBatteryState();
|
state = getBatteryState();
|
||||||
|
@ -576,19 +575,19 @@ static void applyLedBatteryLayer(bool updateNow, uint32_t *timer)
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case BATTERY_OK:
|
case BATTERY_OK:
|
||||||
flash = false;
|
flash = false;
|
||||||
timeOffset = 1;
|
frequency = 1;
|
||||||
break;
|
break;
|
||||||
case BATTERY_WARNING:
|
case BATTERY_WARNING:
|
||||||
timeOffset = 2;
|
frequency = 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
timeOffset = 8;
|
frequency = 8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
flash = !flash;
|
flash = !flash;
|
||||||
}
|
}
|
||||||
|
|
||||||
*timer += LED_STRIP_HZ(timeOffset);
|
*timer += HZ_TO_MICROS(frequency);
|
||||||
|
|
||||||
if (!flash) {
|
if (!flash) {
|
||||||
hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND);
|
hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND);
|
||||||
|
@ -601,24 +600,24 @@ static void applyLedRssiLayer(bool updateNow, uint32_t *timer)
|
||||||
static bool flash = false;
|
static bool flash = false;
|
||||||
|
|
||||||
int state;
|
int state;
|
||||||
int timeOffset = 1;
|
int frequency = 1;
|
||||||
|
|
||||||
if (updateNow) {
|
if (updateNow) {
|
||||||
state = (rssi * 100) / 1023;
|
state = (rssi * 100) / 1023;
|
||||||
|
|
||||||
if (state > 50) {
|
if (state > 50) {
|
||||||
flash = false;
|
flash = false;
|
||||||
timeOffset = 1;
|
frequency = 1;
|
||||||
} else if (state > 20) {
|
} else if (state > 20) {
|
||||||
timeOffset = 2;
|
frequency = 2;
|
||||||
} else {
|
} else {
|
||||||
timeOffset = 8;
|
frequency = 8;
|
||||||
}
|
}
|
||||||
flash = !flash;
|
flash = !flash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*timer += LED_STRIP_HZ(timeOffset);
|
*timer += HZ_TO_MICROS(frequency);
|
||||||
|
|
||||||
if (!flash) {
|
if (!flash) {
|
||||||
hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND);
|
hsvColor_t *bgc = getSC(LED_SCOLOR_BACKGROUND);
|
||||||
|
@ -643,7 +642,7 @@ static void applyLedGpsLayer(bool updateNow, uint32_t *timer)
|
||||||
gpsFlashCounter++;
|
gpsFlashCounter++;
|
||||||
gpsPauseCounter = 1;
|
gpsPauseCounter = 1;
|
||||||
}
|
}
|
||||||
*timer += LED_STRIP_HZ(2.5);
|
*timer += HZ_TO_MICROS(2.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hsvColor_t *gpsColor;
|
const hsvColor_t *gpsColor;
|
||||||
|
@ -675,11 +674,11 @@ static void applyLedIndicatorLayer(bool updateNow, uint32_t *timer)
|
||||||
// calculate update frequency
|
// calculate update frequency
|
||||||
int scale = MAX(ABS(rcCommand[ROLL]), ABS(rcCommand[PITCH])); // 0 - 500
|
int scale = MAX(ABS(rcCommand[ROLL]), ABS(rcCommand[PITCH])); // 0 - 500
|
||||||
scale = scale - INDICATOR_DEADBAND; // start increasing frequency right after deadband
|
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;
|
flash = !flash;
|
||||||
} else {
|
} 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) {
|
if (updateNow) {
|
||||||
rotationPhase = rotationPhase > 0 ? rotationPhase - 1 : ledCounts.ringSeqLen - 1;
|
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 += HZ_TO_MICROS(5 + (45 * scaledThrottle) / 100); // 5 - 50Hz update rate
|
||||||
*timer += LED_STRIP_HZ(5) * 10 / scale; // 5 - 50Hz update rate
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
|
||||||
|
@ -806,7 +804,7 @@ static void applyLarsonScannerLayer(bool updateNow, uint32_t *timer)
|
||||||
|
|
||||||
if (updateNow) {
|
if (updateNow) {
|
||||||
larsonScannerNextStep(&larsonParameters, 15);
|
larsonScannerNextStep(&larsonParameters, 15);
|
||||||
*timer += LED_STRIP_HZ(60);
|
*timer += HZ_TO_MICROS(60);
|
||||||
}
|
}
|
||||||
|
|
||||||
int scannerLedIndex = 0;
|
int scannerLedIndex = 0;
|
||||||
|
@ -835,7 +833,7 @@ static void applyLedBlinkLayer(bool updateNow, uint32_t *timer)
|
||||||
if (blinkMask <= 1)
|
if (blinkMask <= 1)
|
||||||
blinkMask = blinkPattern;
|
blinkMask = blinkPattern;
|
||||||
|
|
||||||
*timer += LED_STRIP_HZ(10);
|
*timer += HZ_TO_MICROS(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ledOn = (blinkMask & 1); // b_b_____...
|
bool ledOn = (blinkMask & 1); // b_b_____...
|
||||||
|
@ -844,7 +842,7 @@ static void applyLedBlinkLayer(bool updateNow, uint32_t *timer)
|
||||||
const ledConfig_t *ledConfig = &ledConfigs[i];
|
const ledConfig_t *ledConfig = &ledConfigs[i];
|
||||||
|
|
||||||
if (ledGetOverlayBit(ledConfig, LED_OVERLAY_BLINK) ||
|
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));
|
setLedHsv(i, getSC(LED_SCOLOR_BLINKBACKGROUND));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -858,7 +856,7 @@ static void applyLedAnimationLayer(bool updateNow, uint32_t *timer)
|
||||||
const int animationFrames = ledGridHeight;
|
const int animationFrames = ledGridHeight;
|
||||||
if(updateNow) {
|
if(updateNow) {
|
||||||
frameCounter = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0;
|
frameCounter = (frameCounter + 1 < animationFrames) ? frameCounter + 1 : 0;
|
||||||
*timer += LED_STRIP_HZ(20);
|
*timer += HZ_TO_MICROS(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ARMING_FLAG(ARMED))
|
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.
|
// sanitize timer value, so that it can be safely incremented. Handles inital timerVal value.
|
||||||
// max delay is limited to 5s
|
// max delay is limited to 5s
|
||||||
int32_t delta = cmp32(now, timerVal[timId]);
|
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
|
continue; // not ready yet
|
||||||
timActive |= 1 << timId;
|
timActive |= 1 << timId;
|
||||||
if (delta >= LED_STRIP_MS(100) || delta < 0) {
|
if (delta >= HZ_TO_MICROS(10) || delta < 0) {
|
||||||
timerVal[timId] = now;
|
timerVal[timId] = now;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -961,7 +959,7 @@ void ledStripUpdate(uint32_t currentTime)
|
||||||
|
|
||||||
// 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, 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);
|
scaledAux = scaleRange(rcData[currentLedStripConfig->ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1);
|
||||||
|
|
||||||
applyLedFixedLayers();
|
applyLedFixedLayers();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue