Skip to content

Commit 345d7c3

Browse files
committed
rename to fastled_slim, add hsv2rgb() convenience aliases, fix FX usage
1 parent ffaefe5 commit 345d7c3

8 files changed

Lines changed: 60 additions & 59 deletions

File tree

usermods/user_fx/user_fx.cpp

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static const char _data_FX_MODE_DIFFUSIONFIRE[] PROGMEM = "Diffusion Fire@!,Spar
117117

118118
static void mode_spinning_wheel(void) {
119119
if (SEGLEN < 1) FX_FALLBACK_STATIC;
120-
120+
121121
unsigned strips = SEGMENT.nrOfVStrips();
122122
if (strips == 0) FX_FALLBACK_STATIC;
123123

@@ -148,15 +148,13 @@ static void mode_spinning_wheel(void) {
148148

149149
// Handle random seeding globally (outside the virtual strip)
150150
if (SEGENV.call == 0) {
151-
random16_set_seed(hw_random16());
152151
SEGENV.aux1 = (255 << 8) / SEGLEN; // Cache the color scaling
153152
}
154153

155154
// Check if settings changed (do this once, not per virtual strip)
156155
uint32_t settingssum = SEGMENT.speed + SEGMENT.intensity + SEGMENT.custom1 + SEGMENT.custom3 + SEGMENT.check1 + SEGMENT.check3;
157156
bool settingsChanged = (SEGENV.aux0 != settingssum);
158157
if (settingsChanged) {
159-
random16_add_entropy(hw_random16());
160158
SEGENV.aux0 = settingssum;
161159
}
162160

@@ -166,7 +164,7 @@ static void mode_spinning_wheel(void) {
166164
uint8_t spinnerSize = map(SEGMENT.custom1, 0, 255, 1, 10);
167165
uint16_t spin_delay = map(SEGMENT.custom3, 0, 31, 2000, 15000);
168166
uint32_t now = strip.now;
169-
167+
170168
for (unsigned stripNr = 0; stripNr < strips; stripNr += spinnerSize) {
171169
uint32_t* stripState = &state[stripNr * stateVarsPerStrip];
172170
// Check if this spinner is stopped AND has waited its delay
@@ -211,23 +209,23 @@ static void mode_spinning_wheel(void) {
211209
// Initialize or restart
212210
if (needsReset && SEGMENT.check1) { // spin the spinner(s) only if the "Spin me!" checkbox is enabled
213211
state[CUR_POS_IDX] = 0;
214-
212+
215213
// Set velocity
216214
uint16_t speed = map(SEGMENT.speed, 0, 255, 300, 800);
217215
if (speed == 300) { // random speed (user selected 0 on speed slider)
218-
state[VELOCITY_IDX] = random16(200, 900) * 655; // fixed-point velocity scaling (approx. 65536/100)
216+
state[VELOCITY_IDX] = hw_random16(200, 900) * 655; // fixed-point velocity scaling (approx. 65536/100)
219217
} else {
220-
state[VELOCITY_IDX] = random16(speed - 100, speed + 100) * 655;
218+
state[VELOCITY_IDX] = hw_random16(speed - 100, speed + 100) * 655;
221219
}
222-
220+
223221
// Set slowdown start time
224222
uint16_t slowdown = map(SEGMENT.intensity, 0, 255, 3000, 5000);
225223
if (slowdown == 3000) { // random slowdown start time (user selected 0 on intensity slider)
226-
state[SLOWDOWN_TIME_IDX] = now + random16(2000, 6000);
224+
state[SLOWDOWN_TIME_IDX] = now + hw_random16(2000, 6000);
227225
} else {
228-
state[SLOWDOWN_TIME_IDX] = now + random16(slowdown - 1000, slowdown + 1000);
226+
state[SLOWDOWN_TIME_IDX] = now + hw_random16(slowdown - 1000, slowdown + 1000);
229227
}
230-
228+
231229
state[PHASE_IDX] = 0;
232230
state[STOP_TIME_IDX] = 0;
233231
state[WOBBLE_STEP_IDX] = 0;
@@ -250,10 +248,10 @@ static void mode_spinning_wheel(void) {
250248
// Slowing phase - apply deceleration
251249
uint32_t decel = velocity / 80;
252250
if (decel < 100) decel = 100;
253-
251+
254252
velocity = (velocity > decel) ? velocity - decel : 0;
255253
state[VELOCITY_IDX] = velocity;
256-
254+
257255
// Check if stopped
258256
if (velocity < 2000) {
259257
velocity = 0;
@@ -270,7 +268,7 @@ static void mode_spinning_wheel(void) {
270268
uint32_t wobble_step = state[WOBBLE_STEP_IDX];
271269
uint16_t stop_pos = state[STOP_POS_IDX];
272270
uint32_t elapsed = now - state[WOBBLE_TIME_IDX];
273-
271+
274272
if (wobble_step == 0 && elapsed >= 200) {
275273
// Move back one LED from stop position
276274
uint16_t back_pos = (stop_pos == 0) ? SEGLEN - 1 : stop_pos - 1;
@@ -291,13 +289,13 @@ static void mode_spinning_wheel(void) {
291289
state[STOP_TIME_IDX] = now;
292290
}
293291
}
294-
292+
295293
// Update position (phases 0 and 1 only)
296294
if (phase == 0 || phase == 1) {
297295
pos_fixed += velocity;
298296
state[CUR_POS_IDX] = pos_fixed;
299297
}
300-
298+
301299
// Draw LED for all phases
302300
uint16_t pos = (pos_fixed >> 16) % SEGLEN;
303301

@@ -321,7 +319,7 @@ static void mode_spinning_wheel(void) {
321319
for (uint8_t y = 0; y < spinnerSize; y++) {
322320
uint16_t drawPos = (pos + y) % SEGLEN;
323321
int16_t drawStrip = stripNr + x;
324-
322+
325323
// Wrap horizontally if needed, or skip if out of bounds
326324
if (drawStrip >= 0 && drawStrip < strips) {
327325
SEGMENT.setPixelColor(indexToVStrip(drawPos, drawStrip), color);
@@ -370,7 +368,7 @@ typedef struct LavaParticle {
370368

371369
static void mode_2D_lavalamp(void) {
372370
if (!strip.isMatrix || !SEGMENT.is2D()) FX_FALLBACK_STATIC; // not a 2D set-up
373-
371+
374372
const uint16_t cols = SEG_W;
375373
const uint16_t rows = SEG_H;
376374
constexpr float MAX_BLOB_RADIUS = 20.0f; // cap to prevent frame rate drops on large matrices
@@ -405,7 +403,7 @@ static void mode_2D_lavalamp(void) {
405403

406404
uint8_t size = currentSize;
407405
uint8_t numParticles = currentNumParticles;
408-
406+
409407
// blob size based on matrix width
410408
const float minSize = cols * 0.15f; // Minimum 15% of width
411409
const float maxSize = cols * 0.4f; // Maximum 40% of width
@@ -427,7 +425,7 @@ static void mode_2D_lavalamp(void) {
427425
lavaParticles[i].y = rows - 1;
428426
lavaParticles[i].vx = (hw_random16(7) - 3) / 250.0f;
429427
lavaParticles[i].vy = -(hw_random16(20) + 10) / 100.0f * 0.3f;
430-
428+
431429
lavaParticles[i].size = minSize + (float)hw_random16(rangeInt);
432430
if (lavaParticles[i].size > MAX_BLOB_RADIUS) lavaParticles[i].size = MAX_BLOB_RADIUS;
433431

@@ -444,7 +442,7 @@ static void mode_2D_lavalamp(void) {
444442

445443
// Fade background slightly for trailing effect
446444
SEGMENT.fadeToBlackBy(40);
447-
445+
448446
// Update and draw particles
449447
int activeCount = 0;
450448
unsigned long currentMillis = strip.now;
@@ -460,21 +458,21 @@ static void mode_2D_lavalamp(void) {
460458
}
461459

462460
LavaParticle *p = &lavaParticles[i];
463-
461+
464462
// Physics update
465463
p->x += p->vx;
466464
p->y += p->vy;
467-
465+
468466
// Optional particle/blob attraction
469467
if (SEGMENT.check2) {
470468
for (int j = 0; j < MAX_LAVA_PARTICLES; j++) {
471469
if (i == j || !lavaParticles[j].active) continue;
472-
470+
473471
LavaParticle *other = &lavaParticles[j];
474-
472+
475473
// Skip attraction if moving in same vertical direction (both up or both down)
476474
if ((p->vy < 0 && other->vy < 0) || (p->vy > 0 && other->vy > 0)) continue;
477-
475+
478476
float dx = other->x - p->x;
479477
float dy = other->y - p->y;
480478

@@ -580,7 +578,7 @@ static void mode_2D_lavalamp(void) {
580578
// Get color
581579
uint32_t color;
582580
color = SEGMENT.color_from_palette(p->hue, true, PALETTE_SOLID_WRAP, 0);
583-
581+
584582
// Extract RGB and apply life/opacity
585583
uint8_t w = (W(color) * 255) >> 8;
586584
uint8_t r = (R(color) * 255) >> 8;
@@ -600,7 +598,7 @@ static void mode_2D_lavalamp(void) {
600598
for (int dx = -(int)p->size - 1; dx <= (int)p->size + 1; dx++) {
601599
int px = centerX + dx;
602600
int py = centerY + dy;
603-
601+
604602
if (px < 0 || px >= cols || py < 0 || py >= rows) continue;
605603

606604
// Sub-pixel distance: measure from true float center to pixel center
@@ -667,34 +665,34 @@ static void drawMagma(const uint16_t width, const uint16_t height, float *ff_y,
667665
static void drawLavaBombs(const uint16_t width, const uint16_t height, float *particleData, float gravity, uint8_t particleCount) {
668666
for (uint16_t i = 0; i < particleCount; i++) {
669667
uint16_t idx = i * 4;
670-
668+
671669
particleData[idx + 3] -= gravity;
672670
particleData[idx + 0] += particleData[idx + 2];
673671
particleData[idx + 1] += particleData[idx + 3];
674-
672+
675673
float posX = particleData[idx + 0];
676674
float posY = particleData[idx + 1];
677-
675+
678676
if (posY > height + height / 4) {
679677
particleData[idx + 3] = -particleData[idx + 3] * 0.8f;
680678
}
681-
679+
682680
if (posY < (float)(height / 8) - 1.0f || posX < 0 || posX >= width) {
683681
particleData[idx + 0] = hw_random(0, width * 100) / 100.0f;
684682
particleData[idx + 1] = hw_random(0, height * 25) / 100.0f;
685683
particleData[idx + 2] = hw_random(-75, 75) / 100.0f;
686-
684+
687685
float baseVelocity = hw_random(60, 120) / 100.0f;
688686
if (hw_random8() < 50) {
689687
baseVelocity *= 1.6f;
690688
}
691689
particleData[idx + 3] = baseVelocity;
692690
continue;
693691
}
694-
692+
695693
int16_t xi = (int16_t)posX;
696694
int16_t yi = (int16_t)posY;
697-
695+
698696
if (xi >= 0 && xi < width && yi >= 0 && yi < height) {
699697
// Get a random color from the current palette
700698
uint8_t randomIndex = hw_random8(64, 128);
@@ -705,24 +703,24 @@ static void drawLavaBombs(const uint16_t width, const uint16_t height, float *pa
705703
float yf = posY - yi;
706704
float ix = 1.0f - xf;
707705
float iy = 1.0f - yf;
708-
706+
709707
uint8_t w0 = 255 * ix * iy;
710708
uint8_t w1 = 255 * xf * iy;
711709
uint8_t w2 = 255 * ix * yf;
712710
uint8_t w3 = 255 * xf * yf;
713-
711+
714712
int16_t yFlipped = height - 1 - yi; // Flip Y coordinate
715-
713+
716714
SEGMENT.addPixelColorXY(xi, yFlipped, pcolor.scale8(w0));
717715
if (xi + 1 < width)
718716
SEGMENT.addPixelColorXY(xi + 1, yFlipped, pcolor.scale8(w1));
719717
if (yFlipped - 1 >= 0)
720718
SEGMENT.addPixelColorXY(xi, yFlipped - 1, pcolor.scale8(w2));
721-
if (xi + 1 < width && yFlipped - 1 >= 0)
719+
if (xi + 1 < width && yFlipped - 1 >= 0)
722720
SEGMENT.addPixelColorXY(xi + 1, yFlipped - 1, pcolor.scale8(w3));
723721
}
724722
}
725-
}
723+
}
726724

727725
static void mode_2D_magma(void) {
728726
if (!strip.isMatrix || !SEGMENT.is2D()) FX_FALLBACK_STATIC; // not a 2D set-up
@@ -746,7 +744,7 @@ static void mode_2D_magma(void) {
746744
uint32_t settingsKey = (uint32_t)SEGMENT.speed | ((uint32_t)SEGMENT.intensity << 8) |
747745
((uint32_t)SEGMENT.custom1 << 16) | ((uint32_t)SEGMENT.custom2 << 24);
748746
bool settingsChanged = (*settingsSumPtr != settingsKey);
749-
747+
750748
if (SEGENV.call == 0 || settingsChanged) {
751749
// Intensity slider controls magma height
752750
uint16_t intensity = SEGMENT.intensity;
@@ -772,7 +770,7 @@ static void mode_2D_magma(void) {
772770
particleData[idx + 0] = hw_random(0, width * 100) / 100.0f;
773771
particleData[idx + 1] = hw_random(0, height * 25) / 100.0f;
774772
particleData[idx + 2] = hw_random(-75, 75) / 100.0f;
775-
773+
776774
float baseVelocity = hw_random(60, 120) / 100.0f;
777775
if (hw_random8() < 50) {
778776
baseVelocity *= 1.6f;
@@ -793,7 +791,7 @@ static void mode_2D_magma(void) {
793791

794792
// Gravity control
795793
float gravity = map(SEGMENT.custom2, 0, 255, 5, 20) / 100.0f;
796-
794+
797795
// Number of particles (lava bombs)
798796
uint8_t particleCount = map(SEGMENT.custom1, 0, 255, 0, MAGMA_MAX_PARTICLES);
799797
particleCount = constrain(particleCount, 0, MAGMA_MAX_PARTICLES);
@@ -1035,7 +1033,7 @@ static const char _data_FX_MODE_ANTS[] PROGMEM = "Ants@Ant speed,# of ants,Ant s
10351033
// Build morse code pattern into a buffer
10361034
static void build_morsecode_pattern(const char *morse_code, uint8_t *pattern, uint8_t *wordIndex, uint16_t &index, uint8_t currentWord, int maxSize) {
10371035
const char *c = morse_code;
1038-
1036+
10391037
// Build the dots and dashes into pattern array
10401038
while (*c != '\0') {
10411039
// it's a dot which is 1 pixel
@@ -1082,7 +1080,7 @@ static void build_morsecode_pattern(const char *morse_code, uint8_t *pattern, ui
10821080

10831081
static void mode_morsecode(void) {
10841082
if (SEGLEN < 1) FX_FALLBACK_STATIC;
1085-
1083+
10861084
// A-Z in Morse Code
10871085
static const char * letters[] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
10881086
"-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
@@ -1286,7 +1284,7 @@ class UserFxUsermod : public Usermod {
12861284
// strip.addEffect(255, &mode_your_effect3, _data_FX_MODE_YOUR_EFFECT3);
12871285
}
12881286

1289-
1287+
12901288
///////////////////////////////////////////////////////////////////////////////////////////////
12911289
// If you want configuration options in the usermod settings page, implement these methods //
12921290
///////////////////////////////////////////////////////////////////////////////////////////////

wled00/FX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5007,7 +5007,7 @@ void mode_ColorClouds()
50075007

50085008
uint32_t pixel;
50095009
if (SEGMENT.palette) { pixel = SEGMENT.color_from_palette(hue, false, true, 0, vol); }
5010-
else { hsv2rgb(CHSV32(hue, 255, vol), pixel); }
5010+
else { pixel = CRGBW(CHSV32(hue, 255, vol)); }
50115011

50125012
// Suppress extremely dark pixels to avoid flickering of plain r/g/b.
50135013
if (int(R(pixel)) + G(pixel) + B(pixel) <= 2) {
@@ -6130,7 +6130,7 @@ void mode_2Dcrazybees(void) {
61306130
uint8_t posX, posY, aimX, aimY, hue;
61316131
int8_t deltaX, deltaY, signX, signY, error;
61326132
void aimed(uint16_t w, uint16_t h) {
6133-
//random16_set_seed(millis());
6133+
//prng.setSeed(millis());
61346134
aimX = prng.random8(0, w);
61356135
aimY = prng.random8(0, h);
61366136
hue = prng.random8();

wled00/colors.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
#ifndef WLED_COLORS_H
33
#define WLED_COLORS_H
4-
#include "src/dependencies/fastled/fastled_fcn.h"
4+
#include "src/dependencies/fastled_slim/fastled_slim.h"
55
/*
66
* Color structs and color utility functions
77
*/
@@ -25,7 +25,7 @@
2525
#define B(c) (byte(c))
2626
#define W(c) (byte((c) >> 24))
2727

28-
struct CRGBW;
28+
struct CRGBW; // forward declations
2929
struct CHSV32;
3030

3131
extern bool gammaCorrectCol;
@@ -196,4 +196,10 @@ inline CHSV32& CHSV32::operator= (const CRGBW& rgb) { // assignment from 32bit r
196196
rgb2hsv(rgb, *this);
197197
return *this;
198198
}
199+
200+
// explicit hsv2rgb conversions for compatibility
201+
inline CRGBW hsv2rgb(const CHSV32& hsv) { return CRGBW(hsv); }
202+
inline void hsv2rgb(const CHSV32& hsv, CRGBW& rgb) { rgb = CRGBW(hsv); }
203+
inline void hsv2rgb(const CHSV32& hsv, uint32_t& rgb) { rgb = CRGBW(hsv).color32; }
204+
199205
#endif

wled00/palettes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "wled.h"
2-
#include "src/dependencies/fastled/fastled_fcn.h"
2+
#include "src/dependencies/fastled_slim/fastled_slim.h"
33

44
/*
55
* WLED Color palettes

wled00/src/dependencies/fastled/LICENSE.txt renamed to wled00/src/dependencies/fastled_slim/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013 FastLED
3+
Copyright (c) 2013 FastLED modified by @dedehai
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

wled00/src/dependencies/fastled/fastled_fcn.cpp renamed to wled00/src/dependencies/fastled_slim/fastled_slim.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "fastled_fcn.h"
1+
#include "fastled_slim.h"
22

33
// Code originally from FastLED version 3.6.0. Optimized for WLED use by @dedehai
44
// Licensed unter MIT license, see LICENSE.txt for details

0 commit comments

Comments
 (0)