@@ -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
363370int16_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+
384401uint16_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)
402419typedef 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
409426um_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).
0 commit comments