Skip to content

Commit bc24937

Browse files
committed
minor improvements from upstream
* add checkSettingsPIN() and get_random_wheel_index() functions * add on/off state to UDP data * small robustness improvements
1 parent aff4de3 commit bc24937

File tree

5 files changed

+53
-15
lines changed

5 files changed

+53
-15
lines changed

wled00/fcn_declare.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,11 @@ void releaseJSONBufferLock();
370370
uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLen);
371371
uint8_t extractModeSlider(uint8_t mode, uint8_t slider, char *dest, uint8_t maxLen, uint8_t *var = nullptr);
372372
int16_t extractModeDefaults(uint8_t mode, const char *segVar);
373+
void checkSettingsPIN(const char *pin);
373374
uint16_t __attribute__((pure)) crc16(const unsigned char* data_p, size_t length); // WLEDMM: added attribute pure
374375
um_data_t* simulateSound(uint8_t simulationId);
375376
// WLEDMM enumerateLedmaps(); moved to FX.h
377+
uint8_t get_random_wheel_index(uint8_t pos);
376378
CRGB getCRGBForBand(int x, uint8_t *fftResult, int pal); //WLEDMM netmindz ar palette
377379
char *cleanUpName(char *in); // to clean up a name that was read from file
378380

wled00/led.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ void stateUpdated(byte callMode) {
105105
if (stateChanged) currentPreset = 0; //something changed, so we are no longer in the preset
106106

107107
if (callMode != CALL_MODE_NOTIFICATION && callMode != CALL_MODE_NO_NOTIFY) notify(callMode);
108+
if (bri != briOld && nodeBroadcastEnabled) sendSysInfoUDP(); // update on state
108109

109110
//set flag to update ws and mqtt
110111
interfaceUpdateCallMode = callMode;
@@ -193,12 +194,15 @@ void handleTransitions()
193194
if (tper >= 1.0f)
194195
{
195196
strip.setTransitionMode(false);
197+
// restore (global) transition time if not called from UDP notifier or single/temporary transition from JSON (also playlist)
198+
if (jsonTransitionOnce) strip.setTransition(transitionDelay);
196199
transitionActive = false;
200+
jsonTransitionOnce = false;
197201
tperLast = 0;
198202
applyFinalBri();
199203
return;
200204
}
201-
if (tper - tperLast < 0.004) return;
205+
if (tper - tperLast < 0.004f) return;
202206
tperLast = tper;
203207
briT = briOld + ((bri - briOld) * tper);
204208

@@ -208,7 +212,7 @@ void handleTransitions()
208212

209213

210214
// legacy method, applies values from col, effectCurrent, ... to selected segments
211-
void colorUpdated(byte callMode){
215+
void colorUpdated(byte callMode) {
212216
applyValuesToSelectedSegs();
213217
stateUpdated(callMode);
214218
}

wled00/udp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ void sendSysInfoUDP()
712712
#else
713713
data[38] = NODE_TYPE_ID_UNDEFINED;
714714
#endif
715+
if (bri) data[38] |= 0x80U; // add on/off state
715716
data[39] = ip[3]; // unit ID == last IP number
716717

717718
uint32_t build = VERSION;

wled00/util.cpp

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ bool requestJSONBufferLock(uint8_t module)
204204
{
205205
unsigned long now = millis();
206206

207-
while (jsonBufferLock && millis()-now < 1200) delay(1); // wait for fraction for buffer lock
207+
while (jsonBufferLock && millis()-now < 1100) delay(1); // wait for fraction for buffer lock
208208

209209
if (jsonBufferLock) {
210210
USER_PRINT(F("ERROR: Locking JSON buffer failed! (still locked by "));
@@ -239,9 +239,10 @@ uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLe
239239
{
240240
if (src == JSON_mode_names || src == nullptr) {
241241
if (mode < strip.getModeCount()) {
242-
char lineBuffer[256];
242+
char lineBuffer[256] = { '\0' };
243243
//strcpy_P(lineBuffer, (const char*)pgm_read_dword(&(WS2812FX::_modeData[mode])));
244-
strcpy_P(lineBuffer, strip.getModeData(mode));
244+
strncpy_P(lineBuffer, strip.getModeData(mode), sizeof(lineBuffer)/sizeof(char)-1);
245+
lineBuffer[sizeof(lineBuffer)/sizeof(char)-1] = '\0'; // terminate string
245246
size_t len = strlen(lineBuffer);
246247
size_t j = 0;
247248
for (; j < maxLen && j < len; j++) {
@@ -253,6 +254,12 @@ uint8_t extractModeName(uint8_t mode, const char *src, char *dest, uint8_t maxLe
253254
} else return 0;
254255
}
255256

257+
if (src == JSON_palette_names && mode > GRADIENT_PALETTE_COUNT) {
258+
snprintf_P(dest, maxLen, PSTR("~ Custom %d~"), 255-mode);
259+
dest[maxLen-1] = '\0';
260+
return strlen(dest);
261+
}
262+
256263
uint8_t qComma = 0;
257264
bool insideQuotes = false;
258265
uint8_t printedChars = 0;
@@ -363,9 +370,9 @@ uint8_t extractModeSlider(uint8_t mode, uint8_t slider, char *dest, uint8_t maxL
363370
int16_t extractModeDefaults(uint8_t mode, const char *segVar)
364371
{
365372
if (mode < strip.getModeCount()) {
366-
char lineBuffer[128] = "";
367-
strncpy_P(lineBuffer, strip.getModeData(mode), 127);
368-
lineBuffer[127] = '\0'; // terminate string
373+
char lineBuffer[256] = { '\0' };
374+
strncpy_P(lineBuffer, strip.getModeData(mode), sizeof(lineBuffer)/sizeof(char)-1);
375+
lineBuffer[sizeof(lineBuffer)/sizeof(char)-1] = '\0'; // terminate string
369376
if (lineBuffer[0] != 0) {
370377
char* startPtr = strrchr(lineBuffer, ';'); // last ";" in FX data
371378
if (!startPtr) return -1;
@@ -381,6 +388,16 @@ int16_t extractModeDefaults(uint8_t mode, const char *segVar)
381388
}
382389

383390

391+
void checkSettingsPIN(const char* pin) {
392+
if (!pin) return;
393+
if (!correctPIN && millis() - lastEditTime < PIN_RETRY_COOLDOWN) return; // guard against PIN brute force
394+
bool correctBefore = correctPIN;
395+
correctPIN = (strlen(settingsPIN) == 0 || strncmp(settingsPIN, pin, 4) == 0);
396+
if (correctBefore != correctPIN) createEditHandler(correctPIN);
397+
lastEditTime = millis();
398+
}
399+
400+
384401
uint16_t crc16(const unsigned char* data_p, size_t length) {
385402
uint8_t x;
386403
uint16_t crc = 0xFFFF;
@@ -401,9 +418,9 @@ uint16_t crc16(const unsigned char* data_p, size_t length) {
401418
// (only 2 used as stored in 1 bit in segment options, consider switching to a single global simulation type)
402419
typedef enum UM_SoundSimulations {
403420
UMS_BeatSin = 0,
404-
UMS_WeWillRockYou
405-
//UMS_10_13,
406-
//UMS_14_3
421+
UMS_WeWillRockYou,
422+
UMS_10_13,
423+
UMS_14_3
407424
} um_soundSimulations_t;
408425

409426
um_data_t* simulateSound(uint8_t simulationId)
@@ -491,7 +508,7 @@ um_data_t* simulateSound(uint8_t simulationId)
491508
fftResult[i] = 0;
492509
}
493510
break;
494-
/*case UMS_10_3:
511+
case UMS_10_13:
495512
for (int i = 0; i<16; i++)
496513
fftResult[i] = inoise8(beatsin8(90 / (i+1), 0, 200)*15 + (ms>>10), ms>>3);
497514
volumeSmth = fftResult[8];
@@ -500,11 +517,11 @@ um_data_t* simulateSound(uint8_t simulationId)
500517
for (int i = 0; i<16; i++)
501518
fftResult[i] = inoise8(beatsin8(120 / (i+1), 10, 30)*10 + (ms>>14), ms>>3);
502519
volumeSmth = fftResult[8];
503-
break;*/
520+
break;
504521
}
505522

506523
samplePeak = random8() > 250;
507-
FFT_MajorPeak = 21 + (volumeSmth*volumeSmth) / 8.0f; // WLEDMM 21hz...8200hz
524+
FFT_MajorPeak = 21 + (volumeSmth*volumeSmth) / 8.0f; // walk thru full range of 21hz...8200hz
508525
maxVol = 31; // this gets feedback fro UI
509526
binNum = 8; // this gets feedback fro UI
510527
volumeRaw = volumeSmth;
@@ -545,6 +562,20 @@ CRGB getCRGBForBand(int x, uint8_t *fftResult, int pal) {
545562
return value;
546563
}
547564

565+
/*
566+
* Returns a new, random color wheel index with a minimum distance of 42 from pos.
567+
*/
568+
uint8_t get_random_wheel_index(uint8_t pos) {
569+
uint8_t r = 0, x = 0, y = 0, d = 0;
570+
while (d < 42) {
571+
r = random8();
572+
x = abs(pos - r);
573+
y = 255 - x;
574+
d = MIN(x, y);
575+
}
576+
return r;
577+
}
578+
548579
// WLEDMM extended "trim string" function to support enumerateLedmaps
549580
// The function takes char* as input, and removes all leading and trailing "decorations" like spaces, tabs, line endings, quotes, colons
550581
// The conversion is "in place" (destructive).

wled00/wled.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
// version code in format yymmddb (b = daily build)
11-
#define VERSION 2402252
11+
#define VERSION 2404090
1212

1313
// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
1414
#define _MoonModules_WLED_

0 commit comments

Comments
 (0)