From e0ed02219df4cac5413c8de835db67068926ca41 Mon Sep 17 00:00:00 2001 From: sheaivey Date: Fri, 9 Jun 2017 18:39:57 -0700 Subject: [PATCH] =?UTF-8?q?Adding=20VTX=20LED=20strip=20overlay=20Squashed?= =?UTF-8?q?=20commits:=20[6f4441f]=20Default=20to=20values=20out=20of=20ra?= =?UTF-8?q?nge=20for=20initial=20check.=20[85c1fa4]=20updating=20comments.?= =?UTF-8?q?=20[24c004b]=20cleaning=20up=20loose=20ends=20[83e015f]=20show?= =?UTF-8?q?=20led=20for=20each=20power=20level=20[8f0d8ee]=20replacing=20?= =?UTF-8?q?=E2=80=9Cblink=20on=20landing=E2=80=9D=20with=20VTX=20overlay.?= =?UTF-8?q?=20[663aea3]=20Stubbing=20out=20the=20initial=20VTX=20overlay?= =?UTF-8?q?=20functionality.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/io/ledstrip.c | 102 +++++++++++++++++++++++++++++++++++++---- src/main/io/ledstrip.h | 3 +- 2 files changed, 95 insertions(+), 10 deletions(-) diff --git a/src/main/io/ledstrip.c b/src/main/io/ledstrip.c index 2418684bd0..9b0154d1a0 100644 --- a/src/main/io/ledstrip.c +++ b/src/main/io/ledstrip.c @@ -40,6 +40,7 @@ #include "drivers/light_ws2811strip.h" #include "drivers/serial.h" +#include "drivers/vtx_common.h" #include "fc/config.h" #include "fc/rc_controls.h" @@ -57,6 +58,7 @@ #include "io/gps.h" #include "io/ledstrip.h" #include "io/serial.h" +#include "io/vtx_string.h" #include "rx/rx.h" @@ -258,7 +260,7 @@ static const hsvColor_t* getSC(ledSpecialColorIds_e index) static const char directionCodes[LED_DIRECTION_COUNT] = { 'N', 'E', 'S', 'W', 'U', 'D' }; static const char baseFunctionCodes[LED_BASEFUNCTION_COUNT] = { 'C', 'F', 'A', 'L', 'S', 'G', 'R' }; -static const char overlayCodes[LED_OVERLAY_COUNT] = { 'T', 'O', 'B', 'N', 'I', 'W' }; +static const char overlayCodes[LED_OVERLAY_COUNT] = { 'T', 'O', 'B', 'V', 'I', 'W' }; #define CHUNK_BUFFER_SIZE 11 @@ -488,16 +490,16 @@ static void applyLedFixedLayers() if (ledGetOverlayBit(ledConfig, LED_OVERLAY_THROTTLE)) //smooth fade with selected Aux channel of all HSV values from previousColor through color to nextColor { - int centerPWM = (PWM_RANGE_MIN + PWM_RANGE_MAX) / 2; - if (auxInput < centerPWM) + int centerPWM = (PWM_RANGE_MIN + PWM_RANGE_MAX) / 2; + if (auxInput < centerPWM) { - color.h = scaleRange(auxInput, PWM_RANGE_MIN, centerPWM, previousColor.h, color.h); + color.h = scaleRange(auxInput, PWM_RANGE_MIN, centerPWM, previousColor.h, color.h); 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, centerPWM, PWM_RANGE_MAX, color.h, nextColor.h); + color.h = scaleRange(auxInput, centerPWM, PWM_RANGE_MAX, color.h, nextColor.h); color.s = scaleRange(auxInput, centerPWM, PWM_RANGE_MAX, color.s, nextColor.s); color.v = scaleRange(auxInput, centerPWM, PWM_RANGE_MAX, color.v, nextColor.v); } @@ -574,6 +576,85 @@ static void applyLedWarningLayer(bool updateNow, timeUs_t *timer) } } +#ifdef VTX_COMMON +static void applyLedVtxLayer(bool updateNow, timeUs_t *timer) +{ + static uint16_t frequency = 0; + static uint8_t power = 255; + static uint8_t pit = 255; + static uint8_t showSettings = false; + static uint16_t lastCheck = 0; + static bool active = false; + static bool blink = false; + uint8_t band = 255, channel = 255; + uint16_t check = 0; + + if (updateNow) { + // keep counter running, so it stays in sync with vtx + active = vtxCommonGetBandAndChannel(&band, &channel); + vtxCommonGetPowerIndex(&power); + vtxCommonGetPitMode(&pit); + + frequency = vtx58frequencyTable[band][channel]; + + // check if last vtx values have changed. + check = pit + (power << 1) + (band << 4) + (channel << 8); + if(!showSettings && check != lastCheck) { + // display settings for 3 seconds. + showSettings = 15; + } + lastCheck = check; // quick way to check if any settings changed. + + if(showSettings) { + showSettings--; + } + blink = !blink; + *timer += HZ_TO_US(5); // check 5 times a second + } + + if(!active) { // no vtx device detected + return; + } + + hsvColor_t color = {0, 0, 0}; + if(showSettings) { // show settings + uint8_t vtxLedCount = 0; + for (int i = 0; i < ledCounts.count && vtxLedCount < 6; ++i) { + const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[i]; + if (ledGetOverlayBit(ledConfig, LED_OVERLAY_VTX)) { + if(vtxLedCount == 0) { + color.h = HSV(GREEN).h; + color.s = HSV(GREEN).s; + color.v = blink ? 15 : 0; // blink received settings + } + else if(vtxLedCount > 0 && power >= vtxLedCount && !pit) { // show power + color.h = HSV(ORANGE).h; + color.s = HSV(ORANGE).s; + color.v = blink ? 15 : 0; // blink received settings + } + else { // turn rest off + color.h = HSV(BLACK).h; + color.s = HSV(BLACK).s; + color.v = HSV(BLACK).v; + } + setLedHsv(i, &color); + ++vtxLedCount; + } + } + } + else { // show frequency + // calculate the VTX color based on frequency + int hue = constrain((frequency - 5645.0 ) * 1.2, 0, 360); + // if we ever want to wrap the hue around the wheel for L band frequencies... + //hue = (hue+(hue<0)*((0-hue)/360+1)*361)%361; + color.h = hue; + color.s = 0; + color.v = pit ? (blink ? 15 : 0) : 255; // blink when in pit mode` + applyLedHsv(LED_MOV_OVERLAY(LED_FLAG_OVERLAY(LED_OVERLAY_VTX)), &color); + } +} +#endif + static void applyLedBatteryLayer(bool updateNow, timeUs_t *timer) { static bool flash = false; @@ -855,8 +936,7 @@ static void applyLedBlinkLayer(bool updateNow, timeUs_t *timer) for (int i = 0; i < ledCounts.count; ++i) { const ledConfig_t *ledConfig = &ledStripConfig()->ledConfigs[i]; - if (ledGetOverlayBit(ledConfig, LED_OVERLAY_BLINK) || - (ledGetOverlayBit(ledConfig, LED_OVERLAY_LANDING_FLASH) && scaledThrottle < 50)) { + if (ledGetOverlayBit(ledConfig, LED_OVERLAY_BLINK)) { setLedHsv(i, getSC(LED_SCOLOR_BLINKBACKGROUND)); } } @@ -904,6 +984,9 @@ typedef enum { timGps, #endif timWarning, +#ifdef VTX_COMMON + timVtx, +#endif timIndicator, #ifdef USE_LED_ANIMATION timAnimation, @@ -930,6 +1013,9 @@ static applyLayerFn_timed* layerTable[] = { [timGps] = &applyLedGpsLayer, #endif [timWarning] = &applyLedWarningLayer, +#ifdef VTX_COMMON + [timVtx] = &applyLedVtxLayer, +#endif [timIndicator] = &applyLedIndicatorLayer, #ifdef USE_LED_ANIMATION [timAnimation] = &applyLedAnimationLayer, diff --git a/src/main/io/ledstrip.h b/src/main/io/ledstrip.h index 9dfbe4e403..3c03e254f2 100644 --- a/src/main/io/ledstrip.h +++ b/src/main/io/ledstrip.h @@ -116,7 +116,7 @@ typedef enum { LED_OVERLAY_THROTTLE, LED_OVERLAY_LARSON_SCANNER, LED_OVERLAY_BLINK, - LED_OVERLAY_LANDING_FLASH, + LED_OVERLAY_VTX, LED_OVERLAY_INDICATOR, LED_OVERLAY_WARNING } ledOverlayId_e; @@ -192,4 +192,3 @@ void applyDefaultLedStripConfig(ledConfig_t *ledConfig); void applyDefaultColors(hsvColor_t *colors); void applyDefaultModeColors(modeColorIndexes_t *modeColors); void applyDefaultSpecialColors(specialColorIndexes_t *specialColors); -