Skip to content

Commit

Permalink
Merge branch 'master' into travis_all_features
Browse files Browse the repository at this point in the history
  • Loading branch information
pille authored Apr 25, 2020
2 parents 2788dd1 + b102808 commit 69a2ac8
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 60 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

### Development versions after 0.9.1 release

#### Build 2004230

- Added brightness and power for individual segments
- Added `on` and `bri` properties to Segment object in JSON API
- Added `C3` an `SB` commands to HTTP get API
- Merged pull request #865 for 5CH_Shojo_PCB environment

#### Build 2004220

- Added Candle Multi effect
- Added Palette capability to Pacifica effect

#### Build 2004190

- Added TM1814 type LED defines

#### Build 2004120

- Added Art-Net support
Expand Down
9 changes: 8 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extra_configs =
# Release binaries follow
default_envs = nodemcuv2, esp01, esp01_1m_ota, esp01_1m_full, esp32dev, custom_WS2801, custom_APA102, custom_LEDPIN_16, custom_LEDPIN_4, custom32_LEDPIN_16

# Single binaries
# Single binaries (uncomment your board)
; default_envs = nodemcuv2
; default_envs = esp01
; default_envs = esp01_1m_ota
Expand All @@ -33,6 +33,7 @@ default_envs = nodemcuv2, esp01, esp01_1m_ota, esp01_1m_full, esp32dev, custom_W
; default_envs = esp8285_4CH_MagicHome
; default_envs = esp8285_4CH_H801
; default_envs = esp8285_5CH_H801
; default_envs = d1_mini_5CH_Shojo_PCB

[common]
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -246,6 +247,12 @@ platform = ${common.platform_latest}
board_build.ldscript = ${common.ldscript_1m0m}
build_flags = ${common.build_flags_esp8266} -D WLED_DISABLE_HUESYNC -D WLED_USE_ANALOG_LEDS -D WLED_USE_H801 -D WLED_ENABLE_5CH_LEDS

[env:d1_mini_5CH_Shojo_PCB]
board = d1_mini
platform = ${common.platform_latest}
board_build.ldscript = ${common.ldscript_4m1m}
build_flags = ${common.build_flags_esp8266} -D WLED_USE_ANALOG_LEDS -D SHOJO_PCB -D WLED_ENABLE_5CH_LEDS

# ------------------------------------------------------------------------------
# DEVELOPMENT BOARDS
# ------------------------------------------------------------------------------
Expand Down
123 changes: 86 additions & 37 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
uint16_t WS2812FX::mode_static(void) {
fill(SEGCOLOR(0));
return (SEGMENT.getOption(7)) ? FRAMETIME : 500; //update faster if in transition
return (SEGMENT.getOption(SEG_OPTION_TRANSITIONAL)) ? FRAMETIME : 500; //update faster if in transition
}


Expand Down Expand Up @@ -2719,50 +2719,92 @@ uint16_t WS2812FX::mode_popcorn(void) {
//Inspired by https://github.com/avanhanegem/ArduinoCandleEffectNeoPixel
//and https://cpldcpu.wordpress.com/2016/01/05/reverse-engineering-a-real-candle/

uint16_t WS2812FX::mode_candle()
uint16_t WS2812FX::candle(bool multi)
{
if (SEGENV.call == 0) {
SEGENV.aux0 = 128; SEGENV.aux1 = 132; SEGENV.step = 1;
}
bool newTarget = false;

uint8_t s = SEGENV.aux0, target = SEGENV.aux1, fadeStep = SEGENV.step;

if (target > s) { //fade up
s = qadd8(s, fadeStep);
if (s >= target) newTarget = true;
} else {
s = qsub8(s, fadeStep);
if (s <= target) newTarget = true;
if (multi)
{
//allocate segment data
uint16_t dataSize = (SEGLEN -1) *3;
if (!SEGENV.allocateData(dataSize)) return candle(false); //allocation failed
}
SEGENV.aux0 = s;

for (uint16_t i = 0; i < SEGLEN; i++) {
setPixelColor(i, color_blend(color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), SEGCOLOR(1), 255-s));
}
//max. flicker range controlled by intensity
uint8_t valrange = SEGMENT.intensity;
uint8_t rndval = valrange >> 1;

//step (how much to move closer to target per frame) coarsely set by speed
uint8_t speedFactor = 4;
if (SEGMENT.speed > 252) { //epilepsy
speedFactor = 1;
} else if (SEGMENT.speed > 99) { //regular candle (mode called every ~25 ms, so 4 frames to have a new target every 100ms)
speedFactor = 2;
} else if (SEGMENT.speed > 49) { //slower fade
speedFactor = 3;
} //else 4 (slowest)

if (newTarget)
uint16_t numCandles = (multi) ? SEGLEN : 1;

for (uint16_t i = 0; i < numCandles; i++)
{
uint8_t valrange = SEGMENT.intensity;
uint8_t rndval = valrange >> 1;
target = random8(rndval) + random8(rndval);
if (target < (rndval >> 1)) target = (rndval >> 1) + random8(rndval);
uint8_t offset = (255 - valrange) >> 1;
target += offset;

uint8_t dif = (target > s) ? target - s : s - target;

//how much to move closer to target per frame
fadeStep = dif >> 2; //mode called every ~25 ms, so 4 frames to have a new target every 100ms
if (fadeStep == 0) fadeStep = 1;
uint16_t d = 0; //data location

uint8_t s = SEGENV.aux0, s_target = SEGENV.aux1, fadeStep = SEGENV.step;
if (i > 0) {
d = (i-1) *3;
s = SEGENV.data[d]; s_target = SEGENV.data[d+1]; fadeStep = SEGENV.data[d+2];
}
if (fadeStep == 0) { //init vals
s = 128; s_target = 130 + random8(4); fadeStep = 1;
}

bool newTarget = false;
if (s_target > s) { //fade up
s = qadd8(s, fadeStep);
if (s >= s_target) newTarget = true;
} else {
s = qsub8(s, fadeStep);
if (s <= s_target) newTarget = true;
}

if (newTarget) {
s_target = random8(rndval) + random8(rndval);
if (s_target < (rndval >> 1)) s_target = (rndval >> 1) + random8(rndval);
uint8_t offset = (255 - valrange) >> 1;
s_target += offset;

uint8_t dif = (s_target > s) ? s_target - s : s - s_target;

SEGENV.step = fadeStep;
SEGENV.aux1 = target;
fadeStep = dif >> speedFactor;
if (fadeStep == 0) fadeStep = 1;
}

if (i > 0) {
setPixelColor(i, color_blend(SEGCOLOR(1), color_from_palette(i, true, PALETTE_SOLID_WRAP, 0), s));

SEGENV.data[d] = s; SEGENV.data[d+1] = s_target; SEGENV.data[d+2] = fadeStep;
} else {
for (uint16_t j = 0; j < SEGLEN; j++) {
setPixelColor(j, color_blend(SEGCOLOR(1), color_from_palette(j, true, PALETTE_SOLID_WRAP, 0), s));
}

SEGENV.aux0 = s; SEGENV.aux1 = s_target; SEGENV.step = fadeStep;
}
}

return FRAMETIME;
}

uint16_t WS2812FX::mode_candle()
{
return candle(false);
}


uint16_t WS2812FX::mode_candle_multi()
{
return candle(true);
}


/*
/ Fireworks in starburst effect
Expand Down Expand Up @@ -2901,9 +2943,9 @@ uint16_t WS2812FX::mode_exploding_fireworks(void)

fill(BLACK);

bool actuallyReverse = SEGMENT.getOption(1);
bool actuallyReverse = SEGMENT.getOption(SEG_OPTION_REVERSED);
//have fireworks start in either direction based on intensity
SEGMENT.setOption(1, SEGENV.step);
SEGMENT.setOption(SEG_OPTION_REVERSED, SEGENV.step);

Spark* sparks = reinterpret_cast<Spark*>(SEGENV.data);
Spark* flare = sparks; //first spark is flare data
Expand Down Expand Up @@ -2994,7 +3036,7 @@ uint16_t WS2812FX::mode_exploding_fireworks(void)
}
}

SEGMENT.setOption(1, actuallyReverse);
SEGMENT.setOption(SEG_OPTION_REVERSED, actuallyReverse);

return FRAMETIME;
}
Expand Down Expand Up @@ -3205,6 +3247,13 @@ uint16_t WS2812FX::mode_pacifica()
CRGBPalette16 pacifica_palette_3 =
{ 0x000208, 0x00030E, 0x000514, 0x00061A, 0x000820, 0x000927, 0x000B2D, 0x000C33,
0x000E39, 0x001040, 0x001450, 0x001860, 0x001C70, 0x002080, 0x1040BF, 0x2060FF };

if (SEGMENT.palette) {
pacifica_palette_1 = currentPalette;
pacifica_palette_2 = currentPalette;
pacifica_palette_3 = currentPalette;
}

// Increment the four "color index start" counters, one for each wave layer.
// Each is incremented at a different speed, and the speeds vary over time.
uint16_t sCIStart1 = SEGENV.aux0, sCIStart2 = SEGENV.aux1, sCIStart3 = SEGENV.step, sCIStart4 = SEGENV.step >> 16;
Expand Down
19 changes: 13 additions & 6 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,21 @@

// options
// bit 7: segment is in transition mode
// bits 2-6: TBD
// bits 3-6: TBD
// bit 2: segment is on
// bit 1: reverse segment
// bit 0: segment is selected
#define NO_OPTIONS (uint8_t)0x00
#define TRANSITIONAL (uint8_t)0x80
#define SEGMENT_ON (uint8_t)0x04
#define REVERSE (uint8_t)0x02
#define SELECTED (uint8_t)0x01
#define IS_TRANSITIONAL ((SEGMENT.options & TRANSITIONAL) == TRANSITIONAL)
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
#define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED )
#define IS_SEGMENT_ON ((SEGMENT.options & SEGMENT_ON ) == SEGMENT_ON )
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
#define IS_SELECTED ((SEGMENT.options & SELECTED ) == SELECTED )

#define MODE_COUNT 102
#define MODE_COUNT 103

#define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1
Expand Down Expand Up @@ -199,6 +202,7 @@
#define FX_MODE_RIPPLE_RAINBOW 99
#define FX_MODE_HEARTBEAT 100
#define FX_MODE_PACIFICA 101
#define FX_MODE_CANDLE_MULTI 102

class WS2812FX {
typedef uint16_t (WS2812FX::*mode_ptr)(void);
Expand Down Expand Up @@ -389,6 +393,7 @@ class WS2812FX {
_mode[FX_MODE_RIPPLE_RAINBOW] = &WS2812FX::mode_ripple_rainbow;
_mode[FX_MODE_HEARTBEAT] = &WS2812FX::mode_heartbeat;
_mode[FX_MODE_PACIFICA] = &WS2812FX::mode_pacifica;
_mode[FX_MODE_CANDLE_MULTI] = &WS2812FX::mode_candle_multi;

_brightness = DEFAULT_BRIGHTNESS;
currentPalette = CRGBPalette16(CRGB::Black);
Expand Down Expand Up @@ -574,7 +579,8 @@ class WS2812FX {
mode_percent(void),
mode_ripple_rainbow(void),
mode_heartbeat(void),
mode_pacifica(void);
mode_pacifica(void),
mode_candle_multi(void);


private:
Expand Down Expand Up @@ -607,6 +613,7 @@ class WS2812FX {
// mode helper functions
uint16_t
blink(uint32_t, uint32_t, bool strobe, bool),
candle(bool),
color_wipe(bool, bool),
scan(bool),
theater_chase(uint32_t, uint32_t, bool),
Expand Down Expand Up @@ -660,7 +667,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([
"Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Meteor Smooth","Railway","Ripple",
"Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern","Solid Pattern Tri","Spots","Spots Fade","Glitter","Candle","Fireworks Starburst",
"Fireworks 1D","Bouncing Balls","Sinelon","Sinelon Dual","Sinelon Rainbow","Popcorn","Drip","Plasma","Percent","Ripple Rainbow",
"Heartbeat","Pacifica"
"Heartbeat","Pacifica","Candle Multi"
])=====";


Expand Down
27 changes: 22 additions & 5 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,23 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w)
default: col.G = g; col.R = b; col.B = r; break; //5 = GBR
}
col.W = w;

//color_blend(BLACK, (uint32_t)col, SEGMENT.opacity);

uint16_t skip = _skipFirstMode ? LED_SKIP_AMOUNT : 0;
if (SEGLEN) {//from segment

//color_blend(getpixel, col, SEGMENT.opacity); (pseudocode for future blending of segments)
if (IS_SEGMENT_ON)
{
if (SEGMENT.opacity < 255) {
col.R = scale8(col.R, SEGMENT.opacity);
col.G = scale8(col.G, SEGMENT.opacity);
col.B = scale8(col.B, SEGMENT.opacity);
col.W = scale8(col.W, SEGMENT.opacity);
}
} else {
col = BLACK;
}

/* Set all the pixels in the group, ensuring _skipFirstMode is honored */
bool reversed = reverseMode ^ IS_REVERSE;
uint16_t realIndex = realPixelIndex(i);
Expand Down Expand Up @@ -483,11 +495,16 @@ void WS2812FX::resetSegments() {
_segments[0].speed = DEFAULT_SPEED;
_segments[0].stop = _length;
_segments[0].grouping = 1;
_segments[0].setOption(0, 1); //select
_segments[0].setOption(SEG_OPTION_SELECTED, 1);
_segments[0].setOption(SEG_OPTION_ON, 1);
_segments[0].opacity = 255;

for (uint16_t i = 1; i < MAX_NUM_SEGMENTS; i++)
{
_segments[i].colors[0] = color_wheel(i*51);
_segments[i].grouping = 1;
_segments[i].setOption(SEG_OPTION_ON, 1);
_segments[i].opacity = 255;
_segment_runtimes[i].reset();
}
_segment_runtimes[0].reset();
Expand All @@ -512,7 +529,7 @@ void WS2812FX::setShowCallback(show_callback cb)
void WS2812FX::setTransitionMode(bool t)
{
_segment_index = getMainSegmentId();
SEGMENT.setOption(7,t);
SEGMENT.setOption(SEG_OPTION_TRANSITIONAL, t);
if (!t) return;
unsigned long waitMax = millis() + 20; //refresh after 20 ms if transition enabled
if (SEGMENT.mode == FX_MODE_STATIC && SEGENV.next_time > waitMax) SEGENV.next_time = waitMax;
Expand Down Expand Up @@ -795,7 +812,7 @@ bool WS2812FX::segmentsAreIdentical(Segment* a, Segment* b)
if (a->speed != b->speed) return false;
if (a->intensity != b->intensity) return false;
if (a->palette != b->palette) return false;
//if (a->getOption(1) != b->getOption(1)) return false; //reverse
//if (a->getOption(SEG_OPTION_REVERSED) != b->getOption(SEG_OPTION_REVERSED)) return false;
return true;
}

Expand Down
9 changes: 8 additions & 1 deletion wled00/NpbWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//#define USE_APA102 // Uncomment for using APA102 LEDs.
//#define USE_WS2801 // Uncomment for using WS2801 LEDs (make sure you have NeoPixelBus v2.5.6 or newer)
//#define USE_LPD8806 // Uncomment for using LPD8806
//#define USE_TM1814 // Uncomment for using TM1814 LEDs (make sure you have NeoPixelBus v2.5.7 or newer)
//#define USE_TM1814 // Uncomment for using TM1814 LEDs (make sure you have NeoPixelBus v2.5.7 or newer)
//#define USE_P9813 // Uncomment for using P9813 LEDs (make sure you have NeoPixelBus v2.5.8 or newer)
//#define WLED_USE_ANALOG_LEDS //Uncomment for using "dumb" PWM controlled LEDs (see pins below, default R: gpio5, G: 12, B: 15, W: 13)
//#define WLED_USE_H801 //H801 controller. Please uncomment #define WLED_USE_ANALOG_LEDS as well
Expand Down Expand Up @@ -62,6 +62,13 @@
#define GPIN 4 //G pin for analog LED strip
#define BPIN 14 //B pin for analog LED strip
#define WPIN 5 //W pin for analog LED strip
#elif defined(SHOJO_PCB)
//PWM pins - to use with Shojo PCB (https://www.bastelbunker.de/esp-rgbww-wifi-led-controller-vbs-edition/)
#define RPIN 14 //R pin for analog LED strip
#define GPIN 4 //G pin for analog LED strip
#define BPIN 5 //B pin for analog LED strip
#define WPIN 15 //W pin for analog LED strip
#define W2PIN 12 //W2 pin for analog LED strip
#else
//PWM pins - PINs 5,12,13,15 are used with Magic Home LED Controller
#define RPIN 5 //R pin for analog LED strip
Expand Down
6 changes: 6 additions & 0 deletions wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
#define HUE_ERROR_TIMEOUT 251
#define HUE_ERROR_ACTIVE 255

//Segment option byte bits
#define SEG_OPTION_SELECTED 0
#define SEG_OPTION_REVERSED 1
#define SEG_OPTION_ON 2
#define SEG_OPTION_TRANSITIONAL 7

//EEPROM size
#define EEPSIZE 2560 //Maximum is 4096

Expand Down
Loading

0 comments on commit 69a2ac8

Please sign in to comment.