Made suggested changes to style and function

Style suggestions adopted.
Use centerPWM (average of max and min PWM) for readability.
No longer resets hOffset, means that other functions (battery and rssi, currently) which use this still add to the hue
This commit is contained in:
DrClaes 2017-05-27 08:05:21 +02:00 committed by GitHub
parent 1d091c317c
commit be91983bb4
1 changed files with 19 additions and 20 deletions

View File

@ -444,8 +444,8 @@ static void applyLedFixedLayers()
for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) { for (int ledIndex = 0; ledIndex < ledCounts.count; ledIndex++) {
const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex]; const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[ledIndex];
hsvColor_t color = *getSC(LED_SCOLOR_BACKGROUND); hsvColor_t color = *getSC(LED_SCOLOR_BACKGROUND);
hsvColor_t color2 = *getSC(LED_SCOLOR_BACKGROUND); //next color above the one selected, or color 0 if your are at the maximum hsvColor_t nextColor = *getSC(LED_SCOLOR_BACKGROUND); //next color above the one selected, or color 0 if your are at the maximum
hsvColor_t color0 = *getSC(LED_SCOLOR_BACKGROUND); //Previous color to the one selected, modulo color count hsvColor_t previousColor = *getSC(LED_SCOLOR_BACKGROUND); //Previous color to the one selected, modulo color count
int fn = ledGetFunction(ledConfig); int fn = ledGetFunction(ledConfig);
int hOffset = HSV_HUE_MAX; int hOffset = HSV_HUE_MAX;
@ -453,8 +453,8 @@ static void applyLedFixedLayers()
switch (fn) { switch (fn) {
case LED_FUNCTION_COLOR: case LED_FUNCTION_COLOR:
color = ledStripConfig()->colors[ledGetColor(ledConfig)]; color = ledStripConfig()->colors[ledGetColor(ledConfig)];
color2 = ledStripConfig()->colors[(ledGetColor(ledConfig)+1) % LED_CONFIGURABLE_COLOR_COUNT]; nextColor = ledStripConfig()->colors[(ledGetColor(ledConfig)+1) % LED_CONFIGURABLE_COLOR_COUNT];
color0 = ledStripConfig()->colors[(ledGetColor(ledConfig)-1) % LED_CONFIGURABLE_COLOR_COUNT]; previousColor = ledStripConfig()->colors[(ledGetColor(ledConfig)-1) % LED_CONFIGURABLE_COLOR_COUNT];
break; break;
case LED_FUNCTION_FLIGHT_MODE: case LED_FUNCTION_FLIGHT_MODE:
@ -487,20 +487,20 @@ static void applyLedFixedLayers()
break; break;
} }
if (ledGetOverlayBit(ledConfig, LED_OVERLAY_THROTTLE)) { if (ledGetOverlayBit(ledConfig, LED_OVERLAY_THROTTLE)) { //smooth fade with selected Aux channel of all HSV values from previousColor through color to nextColor
if (auxInput < (PWM_RANGE_MIN + PWM_RANGE_MAX)/2) //if below average int centerPWM = (PWM_RANGE_MIN + PWM_RANGE_MAX) / 2;
{ if (auxInput < centerPWM) //if below average
color.h = scaleRange(auxInput, PWM_RANGE_MIN, (PWM_RANGE_MIN + PWM_RANGE_MAX) / 2, color0.h, color.h); //Fade the color smoothly from color to the next color from min to max throttle {
color.s = scaleRange(auxInput, PWM_RANGE_MIN, (PWM_RANGE_MIN + PWM_RANGE_MAX) / 2, color0.s, color.s); color.h = scaleRange(auxInput, PWM_RANGE_MIN, centerPWM, previousColor.h, color.h);
color.v = scaleRange(auxInput, PWM_RANGE_MIN, (PWM_RANGE_MIN + PWM_RANGE_MAX) / 2, color0.v, color.v); color.s = scaleRange(auxInput, PWM_RANGE_MIN, centerPWM, previousColor.s, color.s);
} color.v = scaleRange(auxInput, PWM_RANGE_MIN, centerPWM, previousColor.v, color.v);
else }
{ else
color.h = scaleRange(auxInput, (PWM_RANGE_MAX + PWM_RANGE_MIN) / 2, PWM_RANGE_MAX, color.h, color2.h); //Fade the color smoothly from color to the next color from min to max throttle {
color.s = scaleRange(auxInput, (PWM_RANGE_MAX + PWM_RANGE_MIN) / 2, PWM_RANGE_MAX, color.s, color2.s); color.h = scaleRange(auxInput, centerPWM, PWM_RANGE_MAX, color.h, nextColor.h);
color.v = scaleRange(auxInput, (PWM_RANGE_MAX + PWM_RANGE_MIN) / 2, PWM_RANGE_MAX, color.v, color2.v); color.s = scaleRange(auxInput, centerPWM, PWM_RANGE_MAX, color.s, nextColor.s);
} color.v = scaleRange(auxInput, centerPWM, PWM_RANGE_MAX, color.v, nextColor.v);
hOffset = 0; //this makes throttle function override others, not sure which is best }
} }
color.h = (color.h + hOffset) % (HSV_HUE_MAX + 1); color.h = (color.h + hOffset) % (HSV_HUE_MAX + 1);
@ -971,8 +971,7 @@ void ledStripUpdate(timeUs_t currentTimeUs)
// 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, 0, 100) : 0; scaledThrottle = ARMING_FLAG(ARMED) ? scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, 100) : 0;
// scaledAux = scaleRange(rcData[ledStripConfig()->ledstrip_aux_channel], PWM_RANGE_MIN, PWM_RANGE_MAX, 0, HSV_HUE_MAX + 1); auxInput = rcData[ledStripConfig()->ledstrip_aux_channel];
auxInput = rcData[ledStripConfig()->ledstrip_aux_channel];
applyLedFixedLayers(); applyLedFixedLayers();