Skip to content

Commit

Permalink
Merge pull request #7618 from jeffhendrix/led_channel
Browse files Browse the repository at this point in the history
Add ability to adjust LED Strip color with RC channel
  • Loading branch information
DzikuVx committed Feb 24, 2022
2 parents 6e8de91 + d8746b0 commit acf5e54
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -39,6 +39,7 @@ Hyon Lim
Hubert Jozwiak
James Harrison
Jan Staal
Jeff Hendrix
Jeremy Waters
Joe Hermaszewski
Joe Poser
Expand Down
4 changes: 3 additions & 1 deletion docs/LedStrip.md
Expand Up @@ -115,6 +115,7 @@ Each LED has one base function:
* `G` - `G`PS state.
* `S` - R`S`SSI level.
* `L` - Battery `L`evel.
* `H` - C`H`annel.

And each LED has overlays:

Expand All @@ -125,7 +126,7 @@ And each LED has overlays:
* `O` - Lars`O`n Scanner (Cylon Effect).
* `N` - Blink on la`N`ding (throttle < 50%).

`cc` specifies the color number (0 based index).
`cc` specifies the color number (0 based index), or Channel number to adjust Hue

Example:

Expand All @@ -137,6 +138,7 @@ led 3 0,15:SD:AWI:0
led 4 7,7::C:1
led 5 8,8::C:2
led 6 8,9::B:1
led 7 8,10::H:6
```

To erase an led, and to mark the end of the chain, use `0,0::` as the second argument, like this:
Expand Down
17 changes: 15 additions & 2 deletions src/main/io/ledstrip.c
Expand Up @@ -73,7 +73,7 @@
#include "telemetry/telemetry.h"


PG_REGISTER_WITH_RESET_FN(ledStripConfig_t, ledStripConfig, PG_LED_STRIP_CONFIG, 0);
PG_REGISTER_WITH_RESET_FN(ledStripConfig_t, ledStripConfig, PG_LED_STRIP_CONFIG, 1);

static bool ledStripInitialised = false;
static bool ledStripEnabled = true;
Expand Down Expand Up @@ -220,7 +220,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 baseFunctionCodes[LED_BASEFUNCTION_COUNT] = { 'C', 'F', 'A', 'L', 'S', 'G', 'R', 'H' };
static const char overlayCodes[LED_OVERLAY_COUNT] = { 'T', 'O', 'B', 'N', 'I', 'W' };

#define CHUNK_BUFFER_SIZE 11
Expand Down Expand Up @@ -438,6 +438,7 @@ static void applyLedFixedLayers(void)

int fn = ledGetFunction(ledConfig);
int hOffset = HSV_HUE_MAX;
uint8_t channel = 0;

switch (fn) {
case LED_FUNCTION_COLOR:
Expand Down Expand Up @@ -470,6 +471,18 @@ static void applyLedFixedLayers(void)
hOffset += scaleRange(getRSSI() * 100, 0, 1023, -30, 120);
break;

case LED_FUNCTION_CHANNEL:
channel = ledGetColor(ledConfig) - 1;
color = HSV(RED);
hOffset = scaleRange(rxGetChannelValue(channel), PWM_RANGE_MIN, PWM_RANGE_MAX, -1, 360);
// add black and white to range of colors
if (hOffset < 0) {
color = HSV(BLACK);
} else if (hOffset > HSV_HUE_MAX) {
color = HSV(WHITE);
}
break;

default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/io/ledstrip.h
Expand Up @@ -24,7 +24,7 @@
#define LED_CONFIGURABLE_COLOR_COUNT 16
#define LED_MODE_COUNT 6
#define LED_DIRECTION_COUNT 6
#define LED_BASEFUNCTION_COUNT 7
#define LED_BASEFUNCTION_COUNT 8
#define LED_OVERLAY_COUNT 6
#define LED_SPECIAL_COLOR_COUNT 11

Expand Down Expand Up @@ -124,6 +124,7 @@ typedef enum {
LED_FUNCTION_RSSI,
LED_FUNCTION_GPS,
LED_FUNCTION_THRUST_RING,
LED_FUNCTION_CHANNEL,
} ledBaseFunctionId_e;

typedef enum {
Expand Down

0 comments on commit acf5e54

Please sign in to comment.