-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathleds.cpp
2656 lines (1890 loc) · 119 KB
/
leds.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
//
//
//#define FASTLED_DISABELED
// ******** IDEAS
// FFT adjuster +-1,10,50 on trigger value
// FFT Delay py frame, would need another buffer
// FFT auto mode 2... lock ratio of channels to each other and just move it + or minus automatically
// FFT Booster on each color to brighten it up by x
// make a new color creator from fft!
// add fire animation link it to FFT if possible!
#include "config_TPM.h" // Load the main config
#include "leds.h"
#include "leds_def_values.h" // include the default values for led settings
#include "tools.h"
#include "wifi-ota.h"
#include "config_fs.h"
#include "tpm_artnet.h"
#include "osc.h"
//#include "msgeq7_fft.h"
//#define FASTLED_ALLOW_INTERRUPTS 0
#define FASTLED_ESP32_FLASH_LOCK 1
//#define FASTLED_RMT_MAX_CHANNELS 1
//#define FASTLED_RMT_BUILTIN_DRIVER
#include <FastLED.h>
#include <RunningAverage.h> // For Auto FFT
#include <QueueArray.h> // For buffering incoming FFT packets
#include <TPM-FX.h>
tpm_fx tpm_fx; //load the FX lib
#define ANALOG_IN_DEVIDER 16 // devide analog in by this value to get into a 0-255 range
/*#include <SPI.h>
byte address = 0x00;
SPIClass * hspi = NULL;
void Test()
{
hspi = new SPIClass(HSPI);
hspi->begin(SPI_SCK_PIN,-1,SPI_MOSI_PIN,AUDIO_DPOT_CS);
Serial.println("END Setup");
}
*/
// -- The core to run FastLED.show()
#define FASTLED_SHOW_CORE 1
void LEDS_G_artnet_master_out();
void LEDS_run_layers(uint8_t deckSelected);
void LEDS_G_run_LOAD_SAVE_SHOW_Loop();
uint8_t LEDS_fft_calc_fxbin_result(uint8_t fxbin);
extern void osc_StC_FFT_vizIt(); // of open stage controll to send the fft data
// -- Task handles for use in the notifications
static TaskHandle_t FastLEDshowTaskHandle = 0;
static TaskHandle_t userTaskHandle = 0;
// *************** External Functions
// from wifi-ota.cpp
extern artnet_struct artnet_cfg;
extern artnet_node_struct artnetNode[ARTNET_NR_NODES_TPM];
//CRGB GlobalColor_result;
// ***************** the 2 decks
deck_struct deck[1] ;
//save_struct saves[8];
// ***************** the 16 Saves in memory
//deck_cfg_struct *mem_confs[8] ;
//deck_cfg_struct mem_confs[8] ;
// ************** FFT Variables
// FFT Average Buffers for Auto FFT
uint8_t FFT_stage1_sample_count = 0; // used to count the samples in FFT Stage 1 for pulling into Stage 2
#define FFT_AVERAGE_SAMPLES 30 //30 //60 // How many samples to take for the FFT average = Stage 1
RunningAverage fft_bin0(FFT_AVERAGE_SAMPLES); // Buffers for the FFT values
RunningAverage fft_bin1(FFT_AVERAGE_SAMPLES);
RunningAverage fft_bin2(FFT_AVERAGE_SAMPLES);
RunningAverage fft_bin3(FFT_AVERAGE_SAMPLES);
RunningAverage fft_bin4(FFT_AVERAGE_SAMPLES);
RunningAverage fft_bin5(FFT_AVERAGE_SAMPLES);
RunningAverage fft_bin6(FFT_AVERAGE_SAMPLES);
#define FFT_AVERAGE_SAMPLES_STAGE2 6 // How many samples to take in Stage 2 auto FFT average
RunningAverage fft_bin0stage2(FFT_AVERAGE_SAMPLES_STAGE2); // Buffers for auto FFT Stage 2
RunningAverage fft_bin1stage2(FFT_AVERAGE_SAMPLES_STAGE2); // one stage to is keppt every second. so with 10 samples we have an average+max of the last 10 seconds.
RunningAverage fft_bin2stage2(FFT_AVERAGE_SAMPLES_STAGE2);
RunningAverage fft_bin3stage2(FFT_AVERAGE_SAMPLES_STAGE2);
RunningAverage fft_bin4stage2(FFT_AVERAGE_SAMPLES_STAGE2);
RunningAverage fft_bin5stage2(FFT_AVERAGE_SAMPLES_STAGE2);
RunningAverage fft_bin6stage2(FFT_AVERAGE_SAMPLES_STAGE2);
// FFT
QueueArray <uint8_t> FFT_fifo;
uint8_t fft_fps;
uint8_t fft_bin_results[7];
// ********************* LED Setup FastLed
CRGBArray<MAX_NUM_LEDS> tmp_array; // used as a buffer before mirroring reversing.
led_controls_struct led_cnt = { 150,30 }; // global
led_cfg_struct led_cfg = { DEF_MAX_BRI ,DEF_MAX_BRI,0, 0, 1,1,1 ,DEF_LED_MODE, NUM_LEDS ,DEF_PLAY_MODE, {DEF_DATA1_START_NR,DEF_DATA2_START_NR, DEF_DATA3_START_NR, DEF_DATA4_START_NR}, {DEF_DATA1_NR_LEDS, DEF_DATA2_NR_LEDS, DEF_DATA3_NR_LEDS,DEF_DATA4_NR_LEDS }, DEF_APA102_DATARATE, 5 , 0,15, POT_SENSE_DEF ,0 }; // The basic led config
uint16_t play_conf_time_min[MAX_NR_SAVES] = {5,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
uint8_t squencer_bool[NR_Confbits] = {0,0}; // to hold what saves o play in sequence mode
/** show() for ESP32
* Call this function instead of FastLED.show(). It signals core 0 to issue a show,
* then waits for a notification that it is done.
*/
void FastLEDshowESP32()
{
if (userTaskHandle == 0) {
// -- Store the handle of the current task, so that the show task can
// notify it when it's done
userTaskHandle = xTaskGetCurrentTaskHandle();
// -- Trigger the show task
xTaskNotifyGive(FastLEDshowTaskHandle);
// -- Wait to be notified that it's done
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
ulTaskNotifyTake(pdTRUE, xMaxBlockTime);
userTaskHandle = 0;
}
}
/** show Task
* This function runs on core 0 and just waits for requests to call FastLED.show()
*/
void FastLEDshowTask(void *pvParameters)
{
// -- Run forever...
for(;;) {
// -- Wait for the trigger
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
// -- Do the show (synchronously)
FastLED.show();
// -- Notify the calling task
xTaskNotifyGive(userTaskHandle);
}
}
void LEDS_show()
{
if(deck[0].cfg.fft_config.fft_menu_bri != 0)
FastLED.setBrightness(LEDS_get_real_bri() );
else
FastLED.setBrightness(deck[0].cfg.led_master_cfg.bri);
if (get_bool(ARTNET_SEND) == true) LEDS_G_artnet_master_out(); // Send out the artnet data if enabled
else FastLEDshowESP32();
//FastLED.show();
//FastLED[0].showLeds(deck[0].led_master_cfg.bri);
//FastLED[1].showLeds(deck[0].led_master_cfg.bri);
//FastLED[2].showLeds(deck[0].led_master_cfg.bri);
}
void LEDS_setLED_show(uint8_t ledNr, uint8_t color[3])
{
deck[0].run.leds[ledNr].r = color[0];
deck[0].run.leds[ledNr].g = color[1];
deck[0].run.leds[ledNr].b = color[2];
LEDS_show();
}
// ************* FUNCTIONS
void LEDS_fadeout()
{
// make a fadout loop goddamit!
deck[0].run.leds.fadeToBlackBy(255);
yield();
FastLED.show();
yield();
}
/*
void LEDS_Copy_strip(uint16_t start_LED, int nr_LED, uint16_t ref_LED)
{
// copy a strip to somewhere else
if (nr_LED != 0 && (nr_LED + start_LED <= MAX_NUM_LEDS))
{
if (nr_LED < 0) leds((start_LED - nr_LED - 1), (start_LED)) = leds((ref_LED), (ref_LED - nr_LED - 1));
else leds((start_LED), (start_LED + nr_LED - 1)) = leds((ref_LED), (ref_LED + nr_LED - 1));
}
}
// global effects
void LEDS_G_flipstrip(uint16_t start_LED, uint16_t nr_leds)
{
// a function to reverse a strip
CRGB buffer_strip[nr_leds];
for (int i = 0; i < nr_leds; i++)
{
//leds[start_LED + i] = buffer_strip[nr_leds - i - 1];
buffer_strip[nr_leds - i - 1] = leds[start_LED + i];
}
memcpy8(&leds[start_LED], &buffer_strip, nr_leds * 3);
//memmove8
//memcpy8(dest, src, bytecount)
}
*/
void LED_master_rgb(uint16_t Start_led , uint16_t number_of_leds )
{
// fade RGB if we are not on full
if (deck[0].cfg.led_master_cfg.r != 255)
for (int i = Start_led; i < Start_led + number_of_leds; i++)
deck[0].run.leds[i].r = deck[0].run.leds[i].r * deck[0].cfg.led_master_cfg.r / 255;
if (deck[0].cfg.led_master_cfg.g != 255)
for (int i = Start_led; i < Start_led + number_of_leds; i++)
deck[0].run.leds[i].g = deck[0].run.leds[i].g * deck[0].cfg.led_master_cfg.g / 255;
if (deck[0].cfg.led_master_cfg.b != 255)
for (int i = Start_led; i < Start_led + number_of_leds; i++)
deck[0].run.leds[i].b = deck[0].run.leds[i].b * deck[0].cfg.led_master_cfg.b / 255;
}
void LEDS_G_AutoCalcPal(uint8_t deckNo, uint8_t iform)
{
//deck[0].cfg.form_fx_pal[formNr].index_add_led
//deck[0].cfg.form_fx_pal[formNr].index_add_frame );
uint16_t leds = 1;
switch (deck[deckNo].cfg.form_fx_pal[iform].autoPalMode)
{
case Ap_M1: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds); break;
case Ap_M2: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 2); break;
case Ap_M3: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 3); break;
case Ap_M4: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 4); break;
case Ap_M5: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 5); break;
case Ap_M6: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 6); break;
case Ap_M7: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 7); break;
case Ap_M8: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 8); break;
case Ap_M9: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 9); break;
case Ap_M10: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds / 10); break;
case Ap_D2: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 2); break;
case Ap_D3: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 3); break;
case Ap_D4: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 4); break;
case Ap_D5: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 5); break;
case Ap_D6: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 6); break;
case Ap_D7: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 7); break;
case Ap_D8: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 8); break;
case Ap_D9: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 9); break;
case Ap_D10: leds = (deck[deckNo].cfg.form_cfg[iform].nr_leds * 10); break;
default: break;
}
debugMe(String(leds) + " xxxx " + String(iform) + " x " + String(deck[deckNo].cfg.form_cfg[iform].nr_leds) );
if (leds != 0 && deck[deckNo].cfg.form_fx_pal[iform].autoPalMode != Ap_MANUAL ) deck[deckNo].cfg.form_fx_pal[iform].index_add_led = calc_rounded_devision(MAX_INDEX_LONG , leds);
osc_queu_MSG_int("/ostc/form/pal/ald/" + String(iform), deck[0].cfg.form_fx_pal[iform].index_add_led );
}
void LEDS_G_LoadSAveFade(boolean Save, uint8_t confNr)
{
write_bool(FADE_INOUT, true);
write_bool(FADE_INOUT_FADEBACK, false);
write_bool(FADE_INOUT_SAVE, Save);
led_cfg.fade_inout_val = 0;
led_cfg.next_config_loadsave = confNr;
led_cfg.confSwitch_time = micros() ;
}
void LEDS_FX1_increment_indexes(uint8_t DeckNo)
{
for (uint8_t z=0 ; z< NR_FX_BYTES ; z++)
{
if (deck[DeckNo].fx1_cfg.form_menu_strobe[z] != 0)
{
deck[DeckNo].run.form_fx_strobe[z].frame_pos++;
if (deck[DeckNo].run.form_fx_strobe[z].frame_pos >= deck[DeckNo].fx1_cfg.form_fx_strobe_bytes[z].on_frames + deck[DeckNo].fx1_cfg.form_fx_strobe_bytes[z].off_frames)
deck[DeckNo].run.form_fx_strobe[z].frame_pos = 0;
}
}
}
void LEDS_G_pre_show_processing()
{ // the leds pre show prcessing
// run the effects and set the brightness.
LEDS_FX1_increment_indexes(0);
if(led_cfg.ledMode == 0 || led_cfg.ledMode == 2 || led_cfg.ledMode == 4 )
{
LED_master_rgb(0, led_cfg.NrLeds );
}
else
{
if(get_bool(DATA1_ENABLE)) LED_master_rgb(led_cfg.DataStart_leds[0] , led_cfg.DataNR_leds[0] );
if(get_bool(DATA2_ENABLE)) LED_master_rgb(led_cfg.DataStart_leds[1] , led_cfg.DataNR_leds[1] );
if(get_bool(DATA3_ENABLE)) LED_master_rgb(led_cfg.DataStart_leds[2] , led_cfg.DataNR_leds[2] );
if(get_bool(DATA4_ENABLE)) LED_master_rgb(led_cfg.DataStart_leds[3] , led_cfg.DataNR_leds[3] );
}
if(!get_bool(POT_DISABLE) || get_bool(POTS_LVL_MASTER))
{
//uint8_t bri = led_cfg.max_bri * deck[0].led_master_cfg.bri / 255;
uint8_t bri = analogRead(POTI_BRI_PIN) / ANALOG_IN_DEVIDER;
if (bri > led_cnt.PotBriLast + led_cfg.PotSens || bri < led_cnt.PotBriLast - led_cfg.PotSens)
{
deck[0].cfg.led_master_cfg.bri = map(bri, 0, 255, 0, led_cfg.max_bri);
led_cnt.PotBriLast = bri;
}
//FastLED.setBrightness(deck[0].led_master_cfg.bri); moved to show
//debugMe(deck[0].led_master_cfg.bri);
uint8_t fps = analogRead(POTI_FPS_PIN) / ANALOG_IN_DEVIDER;
//deck[0].led_master_cfg.pal_fps = fps /4;
///*
if (fps > led_cnt.PotFPSLast + led_cfg.PotSens || fps < led_cnt.PotFPSLast - led_cfg.PotSens)
{
deck[0].cfg.led_master_cfg.pal_fps = map(fps, 0, 255, 1, MAX_PAL_FPS); //*/
led_cnt.PotFPSLast = fps;
}
//Serial.println(fps);
}
//LED_G_bit_run();
//= led_cfg.max_br * deck[0].led_master_cfg.bri / 255
}
boolean LEDS_checkIfAudioSelected()
{ // check if there are audi strips if so return true
//for (byte zp = 0; zp < _M_NR_STRIP_BYTES_; zp++) if (strip_menu[zp][_M_AUDIO_] != 0) return true;
for (byte zf = 0; zf < _M_NR_FORM_BYTES_; zf++) if ((deck[0].cfg.form_menu_fft[zf][_M_FORM_FFT_RUN] != 0) ) return true;
if(deck[0].cfg.fft_config.fft_menu_bri != 0) return true;
if(deck[0].cfg.fft_config.fft_fxbin[0].menu_select != 0) return true;
if(deck[0].cfg.fft_config.fft_fxbin[1].menu_select != 0) return true;
if(deck[0].cfg.fft_config.fft_fxbin[2].menu_select != 0) return true;
if(deck[0].cfg.fft_config.fft_menu_fps != 0) return true;
for (byte zf = 0; zf < NR_FX_BYTES; zf++)
{
if ((deck[0].fx1_cfg.form_menu_fx1[zf][_M_FORM_FX1_RUN] != 0) ) return true;
if ((deck[0].fx1_cfg.form_menu_strobe[zf][_M_FORM_STROBE_RUN] != 0) ) return true;
if ((deck[0].fx1_cfg.form_menu_clock[zf][_M_FORM_CLOCK_RUN] != 0) ) return true;
if ((deck[0].fx1_cfg.form_menu_eyes[zf][_M_FORM_EYES_RUN] != 0) ) return true;
}
return false;
}
// **************************Pallets **************
void LEDS_pal_load(CRGBPalette16* palref, uint8_t pal_no, uint8_t pal_menu)
{
// deck_struct localDEckCopy;
// localDEckCopy = *deckref;
//*deckref = localDEckCopy;
// load a pallete from the default (FastLed)
//debugMe("Load pal" + String(pal_menu));
if (pal_no < NR_PALETTS && pal_menu < NR_PALETTS_SELECT + 1 )
switch (pal_menu)
{
case 0: *palref = deck[0].cfg.LEDS_pal_cur[0]; break;
case 1: *palref = deck[0].cfg.LEDS_pal_cur[1]; break;
case 2: *palref = deck[0].cfg.LEDS_pal_cur[2]; break;
case 3: *palref = deck[0].cfg.LEDS_pal_cur[3]; break;
case 4: *palref = deck[0].cfg.LEDS_pal_cur[4]; break;
case 5: *palref = deck[0].cfg.LEDS_pal_cur[5]; break;
case 6: *palref = deck[0].cfg.LEDS_pal_cur[6]; break;
case 7: *palref = deck[0].cfg.LEDS_pal_cur[7]; break;
/* case 8: *palref = deck[0].cfg.LEDS_pal_cur[8]; break;
case 9: *palref = deck[0].cfg.LEDS_pal_cur[9]; break;
case 10: *palref = deck[0].cfg.LEDS_pal_cur[10]; break;
case 11: *palref = deck[0].cfg.LEDS_pal_cur[11]; break;
case 12: *palref = deck[0].cfg.LEDS_pal_cur[12]; break;
case 13: *palref = deck[0].cfg.LEDS_pal_cur[13]; break;
case 14: *palref = deck[0].cfg.LEDS_pal_cur[14]; break;
case 15: *palref = deck[0].cfg.LEDS_pal_cur[15]; break;
*/
case 19: for (int i = 0; i < 16; i++) { *palref[i] = CHSV(random8(), 255, random8());} break;
case 20: *palref = RainbowColors_p; break;
case 21: *palref = RainbowStripeColors_p; break;
case 22: *palref = CloudColors_p; break;
case 23: *palref = PartyColors_p; break;
case 24: *palref = OceanColors_p; break;
case 25: *palref = ForestColors_p; break;
case 26: *palref = HeatColors_p; break;
case 27: *palref = LavaColors_p; break;
case 28: *palref = pal_red_green; break;
case 29: *palref = pal_red_blue; break;
case 30: *palref = pal_green_blue; break;
case 31: *palref = pal_black_white_Narrow; break;
case 32: *palref = pal_black_white_wide; break;
default: *palref = RainbowColors_p; break;
//*deckref = localDEckCopy;
}
}
void LEDS_pal_load(deck_struct* deckref, uint8_t pal_no, uint8_t pal_menu)
{
// NOK not loading!
deck_struct localDEckCopy;
localDEckCopy = *deckref;
//*deckref = localDEckCopy;
// load a pallete from the default (FastLed)
//debugMe("Load pal" + String(pal_menu));
if (pal_no < NR_PALETTS && pal_menu < NR_PALETTS_SELECT + 1 )
switch (pal_menu)
{
case 0: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[0]; break;
case 1: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[1]; break;
case 2: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[2]; break;
case 3: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[3]; break;
case 4: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[4]; break;
case 5: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[5]; break;
case 6: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[6]; break;
case 7: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[7]; break;
/* case 8: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[8]; break;
case 9: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[9]; break;
case 10: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[10]; break;
case 11: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[11]; break;
case 12: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[12]; break;
case 13: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[13]; break;
case 14: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[14]; break;
case 15: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = localDEckCopy.cfg.LEDS_pal_cur[15]; break;
*/
case 19: for (int i = 0; i < 16; i++) { localDEckCopy.cfg.LEDS_pal_cur[pal_no][i] = CHSV(random8(), 255, random8());} break;
case 20: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = RainbowColors_p; break;
case 21: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = RainbowStripeColors_p; break;
case 22: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = CloudColors_p; break;
case 23: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = PartyColors_p; break;
case 24: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = OceanColors_p; break;
case 25: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = ForestColors_p; break;
case 26: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = HeatColors_p; break;
case 27: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = LavaColors_p; break;
case 28: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = pal_red_green; break;
case 29: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = pal_red_blue; break;
case 30: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = pal_green_blue; break;
case 31: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = pal_black_white_Narrow; break;
case 32: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = pal_black_white_wide; break;
default: localDEckCopy.cfg.LEDS_pal_cur[pal_no] = RainbowColors_p; break;
*deckref = localDEckCopy;
}
}
void LEDS_pal_reset_index()
{ // reset all the pallete indexes
// Should only be stuff in the RUN Struct.
for (int z = 0; z < _M_NR_FORM_BYTES_; z++)
{
for (int i = 0; i < 8; i++) {
deck[0].run.form_fx_pal[i+(z * 8)].index = constrain(deck[0].cfg.form_fx_pal[i+ (z * 8)].index_start,0,255);
deck[0].run.form_fx_pal[i + (z * 8)].indexLong = deck[0].cfg.form_fx_pal[i + (z * 8)].index_start;
deck[0].run.form_fx_modify[i+(z * 8)].RotateFramePos = 0;
deck[0].run.form_fx_fft[i+(z * 8)].extend_tick = 0;
//debugMe(String(i + (z * 8) ) + " -- " + String(deck[0].form_fx_pal[i + (z * 8)].indexLong));
//(deck[0].run.form_fx_pal[i + (z * 8)].indexLong >= 4096) deck[0].run.form_fx_pal[i + (z * 8)].indexLong = deck[0].run.form_fx_pal[i + (z * 8)].indexLong -4096;
}
}
for (int z = 0; z < NR_FX_PARTS; z++)
{
deck[0].run.form_fx_clock[z].pal_index = deck[0].fx1_cfg.form_fx_clock[z].offset;
deck[0].run.form_fx_dots[z].indexLong = 0;
}
//for (int z = 0; z < NR_FX_BYTES; z++)
}
void LEDS_PAL_invert(uint8_t pal = 0)
{
for(int pal_pos = 0; pal_pos < 16; pal_pos++)
{
deck[0].cfg.LEDS_pal_cur[pal][pal_pos].r = qsub8(255, deck[0].cfg.LEDS_pal_cur[pal][pal_pos].r );
deck[0].cfg.LEDS_pal_cur[pal][pal_pos].g = qsub8(255, deck[0].cfg.LEDS_pal_cur[pal][pal_pos].g );
deck[0].cfg.LEDS_pal_cur[pal][pal_pos].b = qsub8(255, deck[0].cfg.LEDS_pal_cur[pal][pal_pos].b );
}
}
void LEDS_pal_write(uint8_t pal, uint8_t no, uint8_t color , uint8_t value)
{
// write incoming color information into a pallete entry
switch (color)
{
case 0:
deck[0].cfg.LEDS_pal_cur[pal][no].r = value;
break;
case 1:
deck[0].cfg.LEDS_pal_cur[pal][no].g = value;
break;
case 2:
deck[0].cfg.LEDS_pal_cur[pal][no].b = value;
break;
}
}
void LEDS_pal_write(CRGBPalette16* palref, uint8_t pal, uint8_t no, uint8_t color , uint8_t value)
{
CRGBPalette16 LocalPalCopy;
LocalPalCopy = *palref;
// write incoming color information into a pallete entry
switch (color)
{
case 0:
LocalPalCopy[no].r = value;
break;
case 1:
LocalPalCopy[no].g = value;
break;
case 2:
LocalPalCopy[no].b = value;
break;
}
*palref = LocalPalCopy;
}
uint8_t LEDS_pal_read(uint8_t pal, uint8_t no, uint8_t color)
{ // read the color info for 1 color in a pallete
if (pal < NR_PALETTS)
{
switch(color)
{
case 0:
return deck[0].cfg.LEDS_pal_cur[pal][no].r;
break;
case 1:
return deck[0].cfg.LEDS_pal_cur[pal][no].g;
break;
case 2:
return deck[0].cfg.LEDS_pal_cur[pal][no].b;
break;
}
return 0;
}
if (pal >=NR_PALETTS && pal <= 32)
{
CRGBPalette16 TempPal;
switch (pal)
{
case 16: TempPal = RainbowColors_p; break;
case 17: TempPal = RainbowStripeColors_p; break;
case 18: TempPal = CloudColors_p; break;
case 19: TempPal = PartyColors_p; break;
case 20: TempPal = OceanColors_p; break;
case 21: TempPal = ForestColors_p; break;
case 22: TempPal = HeatColors_p; break;
case 23: TempPal = LavaColors_p; break;
case 24: TempPal = pal_red_green; break;
case 25: TempPal = pal_red_blue; break;
case 26: TempPal = pal_green_blue; break;
case 27: TempPal = pal_black_white_Narrow; break;
case 28: TempPal = pal_black_white_wide; break;
}
switch(color)
{
case 0:
return TempPal[no].r;
break;
case 1:
return TempPal[no].g;
break;
case 2:
return TempPal[no].b;
break;
}
return 0;
}
return 0;
}
uint8_t LEDS_pal_read(CRGBPalette16* palref, uint8_t pal, uint8_t no, uint8_t color)
{ // read the color info for 1 color in a pallete
CRGBPalette16 LocalPalCopy;
LocalPalCopy = *palref;
if (pal < NR_PALETTS)
{
switch(color)
{
case 0:
return LocalPalCopy[no].r;
break;
case 1:
return LocalPalCopy[no].g;
break;
case 2:
return LocalPalCopy[no].b;
break;
}
return 0;
}
if (pal >=NR_PALETTS && pal <= 32)
{
CRGBPalette16 TempPal;
switch (pal)
{
case 16: TempPal = RainbowColors_p; break;
case 17: TempPal = RainbowStripeColors_p; break;
case 18: TempPal = CloudColors_p; break;
case 19: TempPal = PartyColors_p; break;
case 20: TempPal = OceanColors_p; break;
case 21: TempPal = ForestColors_p; break;
case 22: TempPal = HeatColors_p; break;
case 23: TempPal = LavaColors_p; break;
case 24: TempPal = pal_red_green; break;
case 25: TempPal = pal_red_blue; break;
case 26: TempPal = pal_green_blue; break;
case 27: TempPal = pal_black_white_Narrow; break;
case 28: TempPal = pal_black_white_wide; break;
}
switch(color)
{
case 0:
return TempPal[no].r;
break;
case 1:
return TempPal[no].g;
break;
case 2:
return TempPal[no].b;
break;
}
return 0;
}
return 0;
}
// ****************************** ARTNET
void LEDS_G_artnet_send_universe(uint8_t node_Nr,uint8_t universe, uint16_t in_pixel , uint8_t nr_pixels = 170)
{
// Set the out universe and IP
ARTNET_set_node( node_Nr, artnetNode[node_Nr].startU + universe );
for (uint16_t set_pixel = 0; set_pixel < nr_pixels; set_pixel++)
{
ARNET_set_pixel( set_pixel, scale8(deck[0].run.leds[in_pixel].r ,deck[0].cfg.led_master_cfg.bri ) , scale8(deck[0].run.leds[in_pixel].g,deck[0].cfg.led_master_cfg.bri ) , scale8(deck[0].run.leds[in_pixel].b, deck[0].cfg.led_master_cfg.bri));
//ARNET_set_pixel( set_pixel, 255 , 125 , 10 );
in_pixel++;
}
// Send out the Artnet Frame
ARTNET_send_node(node_Nr);
}
void LEDS_G_artnet_master_out()
{
uint16_t pixel = 0;
uint8_t universeCounter = 0;
for (uint8_t nodeNR = 0; nodeNR < ARTNET_NR_NODES_TPM; nodeNR++ )
{
for (uint8_t setUni = 0; setUni < artnetNode[nodeNR].numU; setUni++ )
{
LEDS_G_artnet_send_universe(nodeNR,setUni, pixel , 170 ) ;
universeCounter++;
pixel = universeCounter * 170;
//pixel = universeCounter * 170;
}
}
}
void LEDS_artnet_in(uint16_t universe, uint16_t length, uint8_t sequence, uint8_t* data)
{ // process the ARTNET information and send it to the leds
//debugMe("in artnet uni:" + String(universe));
//debugMe(String( artnet_cfg.startU));
if ((universe >= artnet_cfg.startU) && (universe < artnet_cfg.startU + artnet_cfg.numU))
{
//FastLED.show();
byte internal_universe = universe - artnet_cfg.startU;
uint8_t max_length = length / 3;
//debugMe(max_length);
// read universe and put into the right part of the display buffer
for (int i = 0; i < max_length ; i++)
{
int led = i + (internal_universe * 170);
//debugMe(led);
if (led < MAX_NUM_LEDS)
{
if (!get_bool(ARTNET_REMAPPING))
{
deck[0].run.leds[led].r = data[i * 3];
deck[0].run.leds[led].g = data[i * 3 + 1];
deck[0].run.leds[led].b = data[i * 3 + 2];
}
else
{
tpm_fx.fadeLedArray(deck[0].run.leds, 0, led_cfg.NrLeds, 255 );
deck[0].run.leds_FFT_history[led].r = data[i * 3];
deck[0].run.leds_FFT_history[led].g = data[i * 3 + 1];
deck[0].run.leds_FFT_history[led].b = data[i * 3 + 2];
}
//debugMe(leds[led].r);
}
}
yield();
//LED_G_bit_run();
}
yield();
if(get_bool(ARTNET_REMAPPING)) {if (universe == artnet_cfg.startU + artnet_cfg.numU-1 ) { LEDS_run_layers(0);LEDS_G_pre_show_processing(); LEDS_G_run_LOAD_SAVE_SHOW_Loop();} }
// Only run show and process on the last universe.
else FastLEDshowESP32(); // if not remapping show as it comes in.
//FastLED.show();
yield();
}
// ********************* FFT Functions
void LEDS_FFT_enqueue(uint8_t invalue)
{ // put the invalue into the FFT buffer
FFT_fifo.enqueue(invalue);
}
void LEDS_FFT_auto()
{ // automatically calculate the trigger value and set it
uint8_t DeckNo = 0;
if (FFT_stage1_sample_count >= deck[DeckNo].cfg.led_master_cfg.pal_fps) // trigger on the FPS so that we get one stage 2 sammple a second
{
fft_bin0stage2.addValue(deck[DeckNo].run.fft_data[0].avarage);
fft_bin1stage2.addValue(deck[DeckNo].run.fft_data[1].avarage);
fft_bin2stage2.addValue(deck[DeckNo].run.fft_data[2].avarage);
fft_bin3stage2.addValue(deck[DeckNo].run.fft_data[3].avarage);
fft_bin4stage2.addValue(deck[DeckNo].run.fft_data[4].avarage);
fft_bin5stage2.addValue(deck[DeckNo].run.fft_data[5].avarage);
fft_bin6stage2.addValue(deck[DeckNo].run.fft_data[6].avarage);
if (bitRead(deck[DeckNo].cfg.fft_config.fft_bin_autoTrigger, 0)) deck[DeckNo].cfg.fft_config.trigger[0] = constrain((fft_bin0stage2.getFastAverage() + fft_bin0stage2.GetMaxInBuffer()) / 2, deck[0].cfg.fft_config.fftAutoMin, deck[0].cfg.fft_config.fftAutoMax);
if (bitRead(deck[DeckNo].cfg.fft_config.fft_bin_autoTrigger, 1)) deck[DeckNo].cfg.fft_config.trigger[1] = constrain((fft_bin1stage2.getFastAverage() + fft_bin1stage2.GetMaxInBuffer()) / 2, deck[0].cfg.fft_config.fftAutoMin, deck[0].cfg.fft_config.fftAutoMax);
if (bitRead(deck[DeckNo].cfg.fft_config.fft_bin_autoTrigger, 2)) deck[DeckNo].cfg.fft_config.trigger[2] = constrain((fft_bin2stage2.getFastAverage() + fft_bin2stage2.GetMaxInBuffer()) / 2, deck[0].cfg.fft_config.fftAutoMin, deck[0].cfg.fft_config.fftAutoMax);
if (bitRead(deck[DeckNo].cfg.fft_config.fft_bin_autoTrigger, 3)) deck[DeckNo].cfg.fft_config.trigger[3] = constrain((fft_bin3stage2.getFastAverage() + fft_bin3stage2.GetMaxInBuffer()) / 2, deck[0].cfg.fft_config.fftAutoMin, deck[0].cfg.fft_config.fftAutoMax);
if (bitRead(deck[DeckNo].cfg.fft_config.fft_bin_autoTrigger, 4)) deck[DeckNo].cfg.fft_config.trigger[4] = constrain((fft_bin4stage2.getFastAverage() + fft_bin4stage2.GetMaxInBuffer()) / 2, deck[0].cfg.fft_config.fftAutoMin, deck[0].cfg.fft_config.fftAutoMax);
if (bitRead(deck[DeckNo].cfg.fft_config.fft_bin_autoTrigger, 5)) deck[DeckNo].cfg.fft_config.trigger[5] = constrain((fft_bin5stage2.getFastAverage() + fft_bin5stage2.GetMaxInBuffer()) / 2, deck[0].cfg.fft_config.fftAutoMin, deck[0].cfg.fft_config.fftAutoMax);
if (bitRead(deck[DeckNo].cfg.fft_config.fft_bin_autoTrigger, 6)) deck[DeckNo].cfg.fft_config.trigger[6] = constrain((fft_bin6stage2.getFastAverage() + fft_bin6stage2.GetMaxInBuffer()) / 2, deck[0].cfg.fft_config.fftAutoMin, deck[0].cfg.fft_config.fftAutoMax);
//fft_data[7].trigger = fft_bin7stage2.getFastAverage();
// debugMe("max bin 0" + String(fft_bin0stage2.GetMaxInBuffer()));
FFT_stage1_sample_count = 0;
}
}
void LEDS_FFT_calc_avarage()
{ // automatically calculate the average fft values
uint8_t deckNo = 0;
fft_bin0.addValue(fft_bin_results[0]);
fft_bin1.addValue(fft_bin_results[1]);
fft_bin2.addValue(fft_bin_results[2]);
fft_bin3.addValue(fft_bin_results[3]);
fft_bin4.addValue(fft_bin_results[4]);
fft_bin5.addValue(fft_bin_results[5]);
fft_bin6.addValue(fft_bin_results[6]);
deck[deckNo].run.fft_data[0].avarage = fft_bin0.getFastAverage();
deck[deckNo].run.fft_data[1].avarage = fft_bin1.getFastAverage();
deck[deckNo].run.fft_data[2].avarage = fft_bin2.getFastAverage();
deck[deckNo].run.fft_data[3].avarage = fft_bin3.getFastAverage();
deck[deckNo].run.fft_data[4].avarage = fft_bin4.getFastAverage();
deck[deckNo].run.fft_data[5].avarage = fft_bin5.getFastAverage();
deck[deckNo].run.fft_data[6].avarage = fft_bin6.getFastAverage();
deck[deckNo].run.fft_data[0].max = fft_bin0.GetMaxInBuffer();
deck[deckNo].run.fft_data[1].max = fft_bin1.GetMaxInBuffer();
deck[deckNo].run.fft_data[2].max = fft_bin2.GetMaxInBuffer();
deck[deckNo].run.fft_data[3].max = fft_bin3.GetMaxInBuffer();
deck[deckNo].run.fft_data[4].max = fft_bin4.GetMaxInBuffer();
deck[deckNo].run.fft_data[5].max = fft_bin5.GetMaxInBuffer();
deck[deckNo].run.fft_data[6].max = fft_bin6.GetMaxInBuffer();
/*
fft_data[0].max = fft_bin0stage2.GetMaxInBuffer();
fft_data[1].max = fft_bin1stage2.GetMaxInBuffer();
fft_data[2].max = fft_bin2stage2.GetMaxInBuffer();
fft_data[3].max = fft_bin3stage2.GetMaxInBuffer();
fft_data[4].max = fft_bin4stage2.GetMaxInBuffer();
fft_data[5].max = fft_bin5stage2.GetMaxInBuffer();
fft_data[6].max = fft_bin6stage2.GetMaxInBuffer();
*/
//if (get_bool(FFT_AUTO))
{
FFT_stage1_sample_count++;
LEDS_FFT_auto();
}
}
void LEDS_MSGEQ7_setup() {
pinMode(MSGEQ7_INPUT_PIN, INPUT);
pinMode(MSGEQ7_STROBE_PIN, OUTPUT);
pinMode(MSGEQ7_RESET_PIN, OUTPUT);
digitalWrite(MSGEQ7_RESET_PIN, LOW);
digitalWrite(MSGEQ7_STROBE_PIN, HIGH);
}
void LEDS_MSGEQ7_get() // get the FFT data and put it in fft_data[i].value
{
//noInterrupts();
digitalWrite(MSGEQ7_STROBE_PIN, LOW);
digitalWrite(MSGEQ7_RESET_PIN, HIGH);
digitalWrite(MSGEQ7_RESET_PIN, LOW);
//delayMicroseconds(36);
for (int i = 0; i<7; i++)
{
digitalWrite(MSGEQ7_STROBE_PIN, HIGH);
digitalWrite(MSGEQ7_STROBE_PIN, LOW);
delayMicroseconds(36);
fft_bin_results[i] = analogRead(MSGEQ7_INPUT_PIN) / ANALOG_IN_DEVIDER; //
//digitalWrite(MSGEQ7_STROBE_PIN, HIGH);
//delayMicroseconds(40);
}
//interrupts();
/*
for (int i = 0; i < 7; i++)
{
debugMe(fft_data[i].value, false);
debugMe(" - ", false);
}
debugMe(" x ", true);
//*/
}
void LEDS_FFT_process()
{ // process the fft data and genereat a color