Skip to content

Commit

Permalink
Free more than 2kB of RAM
Browse files Browse the repository at this point in the history
Store Palettes in PROGMEM
F() select long and rarely used strings
Refactor hue error
  • Loading branch information
Aircoookie committed Feb 25, 2020
1 parent 1221661 commit f304a68
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 105 deletions.
1 change: 1 addition & 0 deletions wled00/FX.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ class WS2812FX {
uint8_t _brightness;
static uint16_t _usedSegmentData;

void load_gradient_palette(uint8_t);
void handle_palette(void);
void fill(uint32_t);

Expand Down
25 changes: 17 additions & 8 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ uint8_t WS2812FX::getModeCount()

uint8_t WS2812FX::getPaletteCount()
{
return 13 + gGradientPaletteCount;
return 13 + GRADIENT_PALETTE_COUNT;
}

//TODO transitions
Expand Down Expand Up @@ -707,6 +707,15 @@ CRGB WS2812FX::col_to_crgb(uint32_t color)
}


void WS2812FX::load_gradient_palette(uint8_t index)
{
byte i = constrain(index, 0, GRADIENT_PALETTE_COUNT -1);
byte tcp[72]; //support gradient palettes with up to 18 entries
memcpy_P(tcp, (byte*)pgm_read_dword(&(gGradientPalettes[i])), 72);
targetPalette.loadDynamicGradientPalette(tcp);
}


/*
* FastLED palette modes helper function. Limitation: Due to memory reasons, multiple active segments with FastLED will disable the Palette transitions
*/
Expand All @@ -724,13 +733,13 @@ void WS2812FX::handle_palette(void)
case 0: {//default palette. Differs depending on effect
switch (SEGMENT.mode)
{
case FX_MODE_FIRE_2012 : targetPalette = gGradientPalettes[22]; break;//heat palette
case FX_MODE_COLORWAVES : targetPalette = gGradientPalettes[13]; break;//landscape 33
case FX_MODE_FIRE_2012 : load_gradient_palette(22); break;//heat palette
case FX_MODE_COLORWAVES : load_gradient_palette(13); break;//landscape 33
case FX_MODE_FILLNOISE8 : targetPalette = OceanColors_p; break;
case FX_MODE_NOISE16_1 : targetPalette = gGradientPalettes[17]; break;//Drywet
case FX_MODE_NOISE16_2 : targetPalette = gGradientPalettes[30]; break;//Blue cyan yellow
case FX_MODE_NOISE16_3 : targetPalette = gGradientPalettes[22]; break;//heat palette
case FX_MODE_NOISE16_4 : targetPalette = gGradientPalettes[13]; break;//landscape 33
case FX_MODE_NOISE16_1 : load_gradient_palette(17); break;//Drywet
case FX_MODE_NOISE16_2 : load_gradient_palette(30); break;//Blue cyan yellow
case FX_MODE_NOISE16_3 : load_gradient_palette(22); break;//heat palette
case FX_MODE_NOISE16_4 : load_gradient_palette(13); break;//landscape 33
//case FX_MODE_GLITTER : targetPalette = RainbowColors_p; break;

default: targetPalette = PartyColors_p; break;//palette, bpm
Expand Down Expand Up @@ -787,7 +796,7 @@ void WS2812FX::handle_palette(void)
case 12: //Rainbow stripe colors
targetPalette = RainbowStripeColors_p; break;
default: //progmem palettes
targetPalette = gGradientPalettes[constrain(SEGMENT.palette -13, 0, gGradientPaletteCount -1)];
load_gradient_palette(SEGMENT.palette -13);
}

if (singleSegmentMode && paletteFade) //only blend if just one segment uses FastLED mode
Expand Down
2 changes: 1 addition & 1 deletion wled00/NpbWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//PIN CONFIGURATION
#ifndef LEDPIN
#define LEDPIN 2 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos)
#define LEDPIN 5 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos)
#endif
//#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)
Expand Down
9 changes: 9 additions & 0 deletions wled00/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@
#define TYPE_ANALOG_4CH 9 //analog RGBW
#define TYPE_ANALOG_5CH 10 //analog RGB + WW + CW

//Hue error codes
#define HUE_ERROR_INACTIVE 0
#define HUE_ERROR_UNAUTHORIZED 1
#define HUE_ERROR_LIGHTID 3
#define HUE_ERROR_PUSHLINK 101
#define HUE_ERROR_JSON_PARSING 250
#define HUE_ERROR_TIMEOUT 251
#define HUE_ERROR_ACTIVE 255

#endif
2 changes: 1 addition & 1 deletion wled00/html_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Hue Bridge IP:<br>
<input name="H3" type="number" min="0" max="255" ><br>
<b>Press the pushlink button on the bridge, after that save this page!</b><br>
(when first connecting)<br>
Hue status: <span class="hms"> Internal ESP Error! </span><hr>
Hue status: <span class="hms"> Disabled in this build </span><hr>
<button type="button" onclick="B()">Back</button><button type="submit">Save</button>
</form>
</body>
Expand Down
Loading

0 comments on commit f304a68

Please sign in to comment.