From d904741f43d0b85dd985e2f2dc1e1cebbe3bbe16 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Fri, 19 Sep 2014 01:46:41 +0100 Subject: [PATCH] Update LED throttle mode to use rcData instead of rcThrottle, avoid having to reference min/maxThrottle. Range was not being calculated correctly. Throttle color now blends with the current color of the LED so that at mid throttle any orientation color is still correct when mixing Throttle and Flight Mode on an LED. Fix tabs. Reduce nesting level. --- src/main/drivers/light_ws2811strip.c | 5 +++++ src/main/drivers/light_ws2811strip.h | 2 ++ src/main/io/ledstrip.c | 18 ++++++++++++------ src/main/io/ledstrip.h | 1 + 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/drivers/light_ws2811strip.c b/src/main/drivers/light_ws2811strip.c index 0820e33eb..107bbeaa7 100644 --- a/src/main/drivers/light_ws2811strip.c +++ b/src/main/drivers/light_ws2811strip.c @@ -42,6 +42,11 @@ void setLedHsv(uint16_t index, const hsvColor_t *color) ledColorBuffer[index] = *color; } +void getLedHsv(uint16_t index, hsvColor_t *color) +{ + *color = ledColorBuffer[index]; +} + void setLedValue(uint16_t index, const uint8_t value) { ledColorBuffer[index].v = value; diff --git a/src/main/drivers/light_ws2811strip.h b/src/main/drivers/light_ws2811strip.h index efca5a470..0efadbebe 100644 --- a/src/main/drivers/light_ws2811strip.h +++ b/src/main/drivers/light_ws2811strip.h @@ -31,6 +31,8 @@ void ws2811LedStripDMAEnable(void); void ws2811UpdateStrip(void); void setLedHsv(uint16_t index, const hsvColor_t *color); +void getLedHsv(uint16_t index, hsvColor_t *color); + void scaleLedValue(uint16_t index, const uint8_t scalePercent); void setLedValue(uint16_t index, const uint8_t value); diff --git a/src/main/io/ledstrip.c b/src/main/io/ledstrip.c index c9c087a98..3ee0082f8 100644 --- a/src/main/io/ledstrip.c +++ b/src/main/io/ledstrip.c @@ -643,15 +643,21 @@ void applyLedIndicatorLayer(uint8_t indicatorFlashState) void applyLedThrottleLayer() { const ledConfig_t *ledConfig; + hsvColor_t color; uint8_t ledIndex; for (ledIndex = 0; ledIndex < ledCount; ledIndex++) { - ledConfig = &ledConfigs[ledIndex]; - if(ledConfig->flags & LED_FUNCTION_THROTTLE) { - int hue = scaleRange(rcCommand[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, hsv_lightBlue.h, hsv_red.h); - hsvColor_t color = {hue , 0 , 255}; - setLedHsv(ledIndex, &color); - } + ledConfig = &ledConfigs[ledIndex]; + if(!(ledConfig->flags & LED_FUNCTION_THROTTLE)) { + continue; + } + + getLedHsv(ledIndex, &color); + + int scaled = scaleRange(rcData[THROTTLE], PWM_RANGE_MIN, PWM_RANGE_MAX, -60, +60); + scaled += HSV_HUE_MAX; + color.h = scaled % HSV_HUE_MAX; + setLedHsv(ledIndex, &color); } } diff --git a/src/main/io/ledstrip.h b/src/main/io/ledstrip.h index 139021ad6..f3a7195f5 100644 --- a/src/main/io/ledstrip.h +++ b/src/main/io/ledstrip.h @@ -65,3 +65,4 @@ void generateLedConfig(uint8_t ledIndex, char *ledConfigBuffer, size_t bufferSiz bool parseColor(uint8_t index, char *colorConfig); void applyDefaultColors(hsvColor_t *colors, uint8_t colorCount); +