Skip to content

Commit 01c463c

Browse files
blazoncekDedeHai
authored andcommitted
More tuning
- replaced POD new/delete with malloc/free - some more SEGLEN <= 1 - some gnu::pure - more const attributes - some static attributes
1 parent 872465d commit 01c463c

File tree

12 files changed

+109
-108
lines changed

12 files changed

+109
-108
lines changed

wled00/FX.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static const char _data_FX_MODE_STROBE_RAINBOW[] PROGMEM = "Strobe Rainbow@!;,!;
197197
* if (bool rev == true) then LEDs are turned off in reverse order
198198
*/
199199
uint16_t color_wipe(bool rev, bool useRandomColors) {
200-
if (SEGLEN == 1) return mode_static();
200+
if (SEGLEN <= 1) return mode_static();
201201
uint32_t cycleTime = 750 + (255 - SEGMENT.speed)*150;
202202
uint32_t perc = strip.now % cycleTime;
203203
unsigned prog = (perc * 65535) / cycleTime;
@@ -410,7 +410,7 @@ static const char _data_FX_MODE_FADE[] PROGMEM = "Fade@!;!,!;!;01";
410410
* Scan mode parent function
411411
*/
412412
uint16_t scan(bool dual) {
413-
if (SEGLEN == 1) return mode_static();
413+
if (SEGLEN <= 1) return mode_static();
414414
uint32_t cycleTime = 750 + (255 - SEGMENT.speed)*150;
415415
uint32_t perc = strip.now % cycleTime;
416416
int prog = (perc * 65535) / cycleTime;
@@ -1017,7 +1017,7 @@ static const char _data_FX_MODE_COLORFUL[] PROGMEM = "Colorful@!,Saturation;1,2,
10171017
* Emulates a traffic light.
10181018
*/
10191019
uint16_t mode_traffic_light(void) {
1020-
if (SEGLEN == 1) return mode_static();
1020+
if (SEGLEN <= 1) return mode_static();
10211021
for (unsigned i=0; i < SEGLEN; i++)
10221022
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 1));
10231023
uint32_t mdelay = 500;
@@ -1050,7 +1050,7 @@ static const char _data_FX_MODE_TRAFFIC_LIGHT[] PROGMEM = "Traffic Light@!,US st
10501050
*/
10511051
#define FLASH_COUNT 4
10521052
uint16_t mode_chase_flash(void) {
1053-
if (SEGLEN == 1) return mode_static();
1053+
if (SEGLEN <= 1) return mode_static();
10541054
unsigned flash_step = SEGENV.call % ((FLASH_COUNT * 2) + 1);
10551055

10561056
for (unsigned i = 0; i < SEGLEN; i++) {
@@ -1080,7 +1080,7 @@ static const char _data_FX_MODE_CHASE_FLASH[] PROGMEM = "Chase Flash@!;Bg,Fx;!";
10801080
* Prim flashes running, followed by random color.
10811081
*/
10821082
uint16_t mode_chase_flash_random(void) {
1083-
if (SEGLEN == 1) return mode_static();
1083+
if (SEGLEN <= 1) return mode_static();
10841084
unsigned flash_step = SEGENV.call % ((FLASH_COUNT * 2) + 1);
10851085

10861086
for (int i = 0; i < SEGENV.aux1; i++) {
@@ -1162,7 +1162,7 @@ static const char _data_FX_MODE_RUNNING_RANDOM[] PROGMEM = "Stream@!,Zone size;;
11621162
* K.I.T.T.
11631163
*/
11641164
uint16_t mode_larson_scanner(void) {
1165-
if (SEGLEN == 1) return mode_static();
1165+
if (SEGLEN <= 1) return mode_static();
11661166

11671167
const unsigned speed = FRAMETIME * map(SEGMENT.speed, 0, 255, 96, 2); // map into useful range
11681168
const unsigned pixels = SEGLEN / speed; // how many pixels to advance per frame
@@ -1220,7 +1220,7 @@ static const char _data_FX_MODE_DUAL_LARSON_SCANNER[] PROGMEM = "Scanner Dual@!,
12201220
* Firing comets from one end. "Lighthouse"
12211221
*/
12221222
uint16_t mode_comet(void) {
1223-
if (SEGLEN == 1) return mode_static();
1223+
if (SEGLEN <= 1) return mode_static();
12241224
unsigned counter = (strip.now * ((SEGMENT.speed >>2) +1)) & 0xFFFF;
12251225
unsigned index = (counter * SEGLEN) >> 16;
12261226
if (SEGENV.call == 0) SEGENV.aux0 = index;
@@ -1248,7 +1248,7 @@ static const char _data_FX_MODE_COMET[] PROGMEM = "Lighthouse@!,Fade rate;!,!;!"
12481248
* Fireworks function.
12491249
*/
12501250
uint16_t mode_fireworks() {
1251-
if (SEGLEN == 1) return mode_static();
1251+
if (SEGLEN <= 1) return mode_static();
12521252
const uint16_t width = SEGMENT.is2D() ? SEG_W : SEGLEN;
12531253
const uint16_t height = SEG_H;
12541254

@@ -1290,7 +1290,7 @@ static const char _data_FX_MODE_FIREWORKS[] PROGMEM = "Fireworks@,Frequency;!,!;
12901290

12911291
//Twinkling LEDs running. Inspired by https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/Rain.h
12921292
uint16_t mode_rain() {
1293-
if (SEGLEN == 1) return mode_static();
1293+
if (SEGLEN <= 1) return mode_static();
12941294
const unsigned width = SEG_W;
12951295
const unsigned height = SEG_H;
12961296
SEGENV.step += FRAMETIME;
@@ -1356,7 +1356,7 @@ static const char _data_FX_MODE_FIRE_FLICKER[] PROGMEM = "Fire Flicker@!,!;!;!;0
13561356
* Gradient run base function
13571357
*/
13581358
uint16_t gradient_base(bool loading) {
1359-
if (SEGLEN == 1) return mode_static();
1359+
if (SEGLEN <= 1) return mode_static();
13601360
uint16_t counter = strip.now * ((SEGMENT.speed >> 2) + 1);
13611361
uint16_t pp = (counter * SEGLEN) >> 16;
13621362
if (SEGENV.call == 0) pp = 0;
@@ -1401,7 +1401,7 @@ static const char _data_FX_MODE_LOADING[] PROGMEM = "Loading@!,Fade;!,!;!;;ix=16
14011401
* Two dots running
14021402
*/
14031403
uint16_t mode_two_dots() {
1404-
if (SEGLEN == 1) return mode_static();
1404+
if (SEGLEN <= 1) return mode_static();
14051405
unsigned delay = 1 + (FRAMETIME<<3) / SEGLEN; // longer segments should change faster
14061406
uint32_t it = strip.now / map(SEGMENT.speed, 0, 255, delay<<4, delay);
14071407
unsigned offset = it % SEGLEN;
@@ -1852,7 +1852,7 @@ static const char _data_FX_MODE_OSCILLATE[] PROGMEM = "Oscillate";
18521852

18531853
//TODO
18541854
uint16_t mode_lightning(void) {
1855-
if (SEGLEN == 1) return mode_static();
1855+
if (SEGLEN <= 1) return mode_static();
18561856
unsigned ledstart = hw_random16(SEGLEN); // Determine starting location of flash
18571857
unsigned ledlen = 1 + hw_random16(SEGLEN -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
18581858
uint8_t bri = 255/hw_random8(1, 3);
@@ -1938,7 +1938,7 @@ static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;";
19381938

19391939
//eight colored dots, weaving in and out of sync with each other
19401940
uint16_t mode_juggle(void) {
1941-
if (SEGLEN == 1) return mode_static();
1941+
if (SEGLEN <= 1) return mode_static();
19421942

19431943
SEGMENT.fadeToBlackBy(192 - (3*SEGMENT.intensity/4));
19441944
CRGB fastled_col;
@@ -2083,7 +2083,7 @@ static const char _data_FX_MODE_PALETTE[] PROGMEM = "Palette@Shift,Size,Rotation
20832083
// feel of your fire: COOLING (used in step 1 above) (Speed = COOLING), and SPARKING (used
20842084
// in step 3 above) (Effect Intensity = Sparking).
20852085
uint16_t mode_fire_2012() {
2086-
if (SEGLEN == 1) return mode_static();
2086+
if (SEGLEN <= 1) return mode_static();
20872087
const unsigned strips = SEGMENT.nrOfVStrips();
20882088
if (!SEGENV.allocateData(strips * SEGLEN)) return mode_static(); //allocation failed
20892089
byte* heat = SEGENV.data;
@@ -2430,7 +2430,7 @@ static const char _data_FX_MODE_METEOR[] PROGMEM = "Meteor@!,Trail,,,,Gradient,,
24302430

24312431
//Railway Crossing / Christmas Fairy lights
24322432
uint16_t mode_railway() {
2433-
if (SEGLEN == 1) return mode_static();
2433+
if (SEGLEN <= 1) return mode_static();
24342434
unsigned dur = (256 - SEGMENT.speed) * 40;
24352435
uint16_t rampdur = (dur * SEGMENT.intensity) >> 8;
24362436
if (SEGENV.step > dur)
@@ -2721,7 +2721,7 @@ uint16_t mode_halloween_eyes()
27212721
uint32_t blinkEndTime;
27222722
};
27232723

2724-
if (SEGLEN == 1) return mode_static();
2724+
if (SEGLEN <= 1) return mode_static();
27252725
const unsigned maxWidth = strip.isMatrix ? SEG_W : SEGLEN;
27262726
const unsigned HALLOWEEN_EYE_SPACE = MAX(2, strip.isMatrix ? SEG_W>>4: SEGLEN>>5);
27272727
const unsigned HALLOWEEN_EYE_WIDTH = HALLOWEEN_EYE_SPACE/2;
@@ -2906,7 +2906,7 @@ static const char _data_FX_MODE_TRI_STATIC_PATTERN[] PROGMEM = "Solid Pattern Tr
29062906

29072907
static uint16_t spots_base(uint16_t threshold)
29082908
{
2909-
if (SEGLEN == 1) return mode_static();
2909+
if (SEGLEN <= 1) return mode_static();
29102910
if (!SEGMENT.check2) SEGMENT.fill(SEGCOLOR(1));
29112911

29122912
unsigned maxZones = SEGLEN >> 2;
@@ -2962,7 +2962,7 @@ typedef struct Ball {
29622962
* Bouncing Balls Effect
29632963
*/
29642964
uint16_t mode_bouncing_balls(void) {
2965-
if (SEGLEN == 1) return mode_static();
2965+
if (SEGLEN <= 1) return mode_static();
29662966
//allocate segment data
29672967
const unsigned strips = SEGMENT.nrOfVStrips(); // adapt for 2D
29682968
const size_t maxNumBalls = 16;
@@ -3140,7 +3140,7 @@ static const char _data_FX_MODE_ROLLINGBALLS[] PROGMEM = "Rolling Balls@!,# of b
31403140
* Sinelon stolen from FASTLED examples
31413141
*/
31423142
static uint16_t sinelon_base(bool dual, bool rainbow=false) {
3143-
if (SEGLEN == 1) return mode_static();
3143+
if (SEGLEN <= 1) return mode_static();
31443144
SEGMENT.fade_out(SEGMENT.intensity);
31453145
unsigned pos = beatsin16_t(SEGMENT.speed/10,0,SEGLEN-1);
31463146
if (SEGENV.call == 0) SEGENV.aux0 = pos;
@@ -3245,7 +3245,7 @@ typedef struct Spark {
32453245
* modified from https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/Popcorn.h
32463246
*/
32473247
uint16_t mode_popcorn(void) {
3248-
if (SEGLEN == 1) return mode_static();
3248+
if (SEGLEN <= 1) return mode_static();
32493249
//allocate segment data
32503250
unsigned strips = SEGMENT.nrOfVStrips();
32513251
unsigned usablePopcorns = maxNumPopcorn;
@@ -3420,7 +3420,7 @@ typedef struct particle {
34203420
} star;
34213421

34223422
uint16_t mode_starburst(void) {
3423-
if (SEGLEN == 1) return mode_static();
3423+
if (SEGLEN <= 1) return mode_static();
34243424
unsigned maxData = FAIR_DATA_PER_SEG; //ESP8266: 256 ESP32: 640
34253425
unsigned segs = strip.getActiveSegmentsNum();
34263426
if (segs <= (strip.getMaxSegments() /2)) maxData *= 2; //ESP8266: 512 if <= 8 segs ESP32: 1280 if <= 16 segs
@@ -3539,7 +3539,7 @@ static const char _data_FX_MODE_STARBURST[] PROGMEM = "Fireworks Starburst@Chanc
35393539
*/
35403540
uint16_t mode_exploding_fireworks(void)
35413541
{
3542-
if (SEGLEN == 1) return mode_static();
3542+
if (SEGLEN <= 1) return mode_static();
35433543
const int cols = SEGMENT.is2D() ? SEG_W : 1;
35443544
const int rows = SEGMENT.is2D() ? SEG_H : SEGLEN;
35453545

@@ -3677,7 +3677,7 @@ static const char _data_FX_MODE_EXPLODING_FIREWORKS[] PROGMEM = "Fireworks 1D@Gr
36773677
*/
36783678
uint16_t mode_drip(void)
36793679
{
3680-
if (SEGLEN == 1) return mode_static();
3680+
if (SEGLEN <= 1) return mode_static();
36813681
//allocate segment data
36823682
unsigned strips = SEGMENT.nrOfVStrips();
36833683
const int maxNumDrops = 4;
@@ -3773,7 +3773,7 @@ typedef struct Tetris {
37733773
} tetris;
37743774

37753775
uint16_t mode_tetrix(void) {
3776-
if (SEGLEN == 1) return mode_static();
3776+
if (SEGLEN <= 1) return mode_static();
37773777
unsigned strips = SEGMENT.nrOfVStrips(); // allow running on virtual strips (columns in 2D segment)
37783778
unsigned dataSize = sizeof(tetris);
37793779
if (!SEGENV.allocateData(dataSize * strips)) return mode_static(); //allocation failed
@@ -4080,7 +4080,7 @@ static const char _data_FX_MODE_PACIFICA[] PROGMEM = "Pacifica@!,Angle;;!;;pal=5
40804080
* Mode simulates a gradual sunrise
40814081
*/
40824082
uint16_t mode_sunrise() {
4083-
if (SEGLEN == 1) return mode_static();
4083+
if (SEGLEN <= 1) return mode_static();
40844084
//speed 0 - static sun
40854085
//speed 1 - 60: sunrise time in minutes
40864086
//speed 60 - 120 : sunset time in minutes - 60;
@@ -4287,7 +4287,7 @@ static const char _data_FX_MODE_FLOW[] PROGMEM = "Flow@!,Zones;;!;;m12=1"; //ver
42874287
*/
42884288
uint16_t mode_chunchun(void)
42894289
{
4290-
if (SEGLEN == 1) return mode_static();
4290+
if (SEGLEN <= 1) return mode_static();
42914291
SEGMENT.fade_out(254); // add a bit of trail
42924292
unsigned counter = strip.now * (6 + (SEGMENT.speed >> 4));
42934293
unsigned numBirds = 2 + (SEGLEN >> 3); // 2 + 1/8 of a segment
@@ -4338,7 +4338,7 @@ typedef struct Spotlight {
43384338
*/
43394339
uint16_t mode_dancing_shadows(void)
43404340
{
4341-
if (SEGLEN == 1) return mode_static();
4341+
if (SEGLEN <= 1) return mode_static();
43424342
unsigned numSpotlights = map(SEGMENT.intensity, 0, 255, 2, SPOT_MAX_COUNT); // 49 on 32 segment ESP32, 17 on 16 segment ESP8266
43434343
bool initialize = SEGENV.aux0 != numSpotlights;
43444344
SEGENV.aux0 = numSpotlights;
@@ -4800,7 +4800,7 @@ static const char _data_FX_MODE_AURORA[] PROGMEM = "Aurora@!,!;1,2,3;!;;sx=24,pa
48004800
// 16 bit perlinmove. Use Perlin Noise instead of sinewaves for movement. By Andrew Tuline.
48014801
// Controls are speed, # of pixels, faderate.
48024802
uint16_t mode_perlinmove(void) {
4803-
if (SEGLEN == 1) return mode_static();
4803+
if (SEGLEN <= 1) return mode_static();
48044804
SEGMENT.fade_out(255-SEGMENT.custom1);
48054805
for (int i = 0; i < SEGMENT.intensity/16 + 1; i++) {
48064806
unsigned locn = inoise16(strip.now*128/(260-SEGMENT.speed)+i*15000, strip.now*128/(260-SEGMENT.speed)); // Get a new pixel location from moving noise.
@@ -4836,7 +4836,7 @@ static const char _data_FX_MODE_WAVESINS[] PROGMEM = "Wavesins@!,Brightness vari
48364836
//////////////////////////////
48374837
// By: ldirko https://editor.soulmatelights.com/gallery/392-flow-led-stripe , modifed by: Andrew Tuline
48384838
uint16_t mode_FlowStripe(void) {
4839-
if (SEGLEN == 1) return mode_static();
4839+
if (SEGLEN <= 1) return mode_static();
48404840
const int hl = SEGLEN * 10 / 13;
48414841
uint8_t hue = strip.now / (SEGMENT.speed+1);
48424842
uint32_t t = strip.now / (SEGMENT.intensity/8+1);
@@ -6598,7 +6598,7 @@ static const char _data_FX_MODE_MATRIPIX[] PROGMEM = "Matripix@!,Brightness;!,!;
65986598
// * MIDNOISE //
65996599
//////////////////////
66006600
uint16_t mode_midnoise(void) { // Midnoise. By Andrew Tuline.
6601-
if (SEGLEN == 1) return mode_static();
6601+
if (SEGLEN <= 1) return mode_static();
66026602
// Changing xdist to SEGENV.aux0 and ydist to SEGENV.aux1.
66036603

66046604
um_data_t *um_data = getAudioData();
@@ -6689,7 +6689,7 @@ static const char _data_FX_MODE_NOISEMETER[] PROGMEM = "Noisemeter@Fade rate,Wid
66896689
// * PIXELWAVE //
66906690
//////////////////////
66916691
uint16_t mode_pixelwave(void) { // Pixelwave. By Andrew Tuline.
6692-
if (SEGLEN == 1) return mode_static();
6692+
if (SEGLEN <= 1) return mode_static();
66936693
// even with 1D effect we have to take logic for 2D segments for allocation as fill_solid() fills whole segment
66946694

66956695
if (SEGENV.call == 0) {
@@ -6757,7 +6757,7 @@ static const char _data_FX_MODE_PLASMOID[] PROGMEM = "Plasmoid@Phase,# of pixels
67576757
//////////////////////
67586758
// Puddles/Puddlepeak By Andrew Tuline. Merged by @dedehai
67596759
uint16_t mode_puddles_base(bool peakdetect) {
6760-
if (SEGLEN == 1) return mode_static();
6760+
if (SEGLEN <= 1) return mode_static();
67616761
unsigned size = 0;
67626762
uint8_t fadeVal = map(SEGMENT.speed, 0, 255, 224, 254);
67636763
unsigned pos = hw_random16(SEGLEN); // Set a random starting position.
@@ -6807,7 +6807,7 @@ static const char _data_FX_MODE_PUDDLES[] PROGMEM = "Puddles@Fade rate,Puddle si
68076807
// * PIXELS //
68086808
//////////////////////
68096809
uint16_t mode_pixels(void) { // Pixels. By Andrew Tuline.
6810-
if (SEGLEN == 1) return mode_static();
6810+
if (SEGLEN <= 1) return mode_static();
68116811

68126812
if (!SEGENV.allocateData(32*sizeof(uint8_t))) return mode_static(); //allocation failed
68136813
uint8_t *myVals = reinterpret_cast<uint8_t*>(SEGENV.data); // Used to store a pile of samples because WLED frame rate and WLED sample rate are not synchronized. Frame rate is too low.
@@ -6835,7 +6835,7 @@ static const char _data_FX_MODE_PIXELS[] PROGMEM = "Pixels@Fade rate,# of pixels
68356835
// ** Blurz //
68366836
//////////////////////
68376837
uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline.
6838-
if (SEGLEN == 1) return mode_static();
6838+
if (SEGLEN <= 1) return mode_static();
68396839
// even with 1D effect we have to take logic for 2D segments for allocation as fill_solid() fills whole segment
68406840

68416841
um_data_t *um_data = getAudioData();
@@ -6899,7 +6899,7 @@ static const char _data_FX_MODE_DJLIGHT[] PROGMEM = "DJ Light@Speed;;;01f;m12=2,
68996899
// ** Freqmap //
69006900
////////////////////
69016901
uint16_t mode_freqmap(void) { // Map FFT_MajorPeak to SEGLEN. Would be better if a higher framerate.
6902-
if (SEGLEN == 1) return mode_static();
6902+
if (SEGLEN <= 1) return mode_static();
69036903
// Start frequency = 60 Hz and log10(60) = 1.78
69046904
// End frequency = MAX_FREQUENCY in Hz and lo10(MAX_FREQUENCY) = MAX_FREQ_LOG10
69056905

0 commit comments

Comments
 (0)