forked from drvolcano/Volumio-ESP32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
1577 lines (1389 loc) · 47.2 KB
/
main.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
/*#################################################################*\
Copyright 2020 Jakob Föger
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
\*#################################################################*/
#include "main.h"
#include "AppDebug.h"
#ifdef DEBUG_MAIN
#define DEBUG_PRINTLN(x) Serial.println(x)
#define DEBUG_PRINT(x) Serial.print(x)
#else
#define DEBUG_PRINTLN(x)
#define DEBUG_PRINT(x)
#endif
JSON parser;
uint32_t LastTime = 0; // Helper for Now-Playing screen-switcher
void drawProgressBar(int x, int y, int widh, int lineThickness, int barThickness, int frameThickness, int frameSpacing, int knobWidth, int knobHeigth, float value)
{
int thickest = (barThickness > knobHeigth) ? barThickness : knobHeigth;
int thickness = frameThickness * 2 + thickest + frameSpacing * 2;
float barlen = value * (widh - 2 * frameThickness - 2 * frameSpacing);
float knobpos = value * (widh - 2 * frameThickness - 2 * frameSpacing - knobWidth);
display.setColor(0, 255, 0); //(63, 164, 101);
display.drawBox(x, y, widh, thickness);
display.setColor(255, 255, 255);
display.drawBox(x + frameThickness, y + frameThickness, widh - 2 * frameThickness, thickness - 2 * frameThickness);
display.setColor(0, 255, 0); //(63, 164, 101);
if (lineThickness > 0)
display.drawBox(x + frameThickness + frameSpacing, y + frameThickness + frameSpacing + (thickest - lineThickness) / 2, widh - 2 * frameThickness - 2 * frameSpacing, lineThickness);
if (knobWidth > 0 && knobHeigth > 0)
{
display.drawBox(x + int(knobpos), y + frameThickness + frameSpacing, knobWidth, knobHeigth);
if (int(barlen) > 0 && barThickness > 0)
display.drawBox(x + frameThickness + frameSpacing, y + frameThickness + frameSpacing + (thickest - barThickness) / 2, int(knobpos), barThickness);
}
else if (int(barlen) > 0 && barThickness > 0)
display.drawBox(x + frameThickness + frameSpacing, y + frameThickness + frameSpacing + (thickest - barThickness) / 2, int(barlen), barThickness);
}
void drawProgressBar(int x, int y, int widh, int style, float value)
{
switch (style)
{
case 0:
drawProgressBar(x, y, widh, 1, 3, 0, 0, 5, 5, value);
break;
case 1:
drawProgressBar(x, y, widh, 0, 4, 1, 1, 0, 0, value);
case 2:
drawProgressBar(x, y, widh, 0, 1, 0, 0, 0, 0, value);
break;
}
}
//#endif
void DisplayMessage(String Message)
{
display.clearScreen();
display.drawBitmap65k(9, 9, 110, 15, LogoVolumio65k);
// display.drawBitmap24bit(0, 0, 128, 128, Stars);
// display.setColor(0, 0, 0);
// display.drawBoxAlpha(0, 0, 128, 128);
display.setColor(255, 255, 255);
int w = display.getUTF8Width(Message.c_str());
display.drawUTF8((DisplayWidth - w) / 2, 3 * MenuItemHeight + MenuItemHeight - (MenuItemHeight - MenuTextHeight) / 2, Message.c_str());
display.flush();
}
String WiFiStatusString()
{
String text = "";
switch (WiFi.status())
{
case WL_CONNECTED:
text = "WL_CONNECTED";
break;
case WL_NO_SHIELD:
text = "WL_CONNECTED";
break;
case WL_IDLE_STATUS:
text = "WL_IDLE_STATUS";
break;
case WL_NO_SSID_AVAIL:
text = "WL_NO_SSID_AVAIL";
break;
case WL_SCAN_COMPLETED:
text = "WL_SCAN_COMPLETED";
break;
case WL_CONNECT_FAILED:
text = "WL_CONNECT_FAILED";
break;
case WL_CONNECTION_LOST:
text = "WL_CONNECTION_LOST";
break;
case WL_DISCONNECTED:
text = "WL_DISCONNECTED";
break;
default:
text = "???";
}
return text;
}
//Interrupt: left encoder Pin A changed
void IRAM_ATTR ISR_LeftEncoder_A()
{
leftEncoder.A_CHANGED();
}
//Interrupt: left encoder Pin B changed
void IRAM_ATTR ISR_LeftEncoder_B()
{
leftEncoder.B_CHANGED();
}
//Interrupt: right encoder Pin A changed
void IRAM_ATTR ISR_RightEncoder_A()
{
rightEncoder.A_CHANGED();
}
//Interrupt: right encoder Pin B changed
void IRAM_ATTR ISR_RightEncoder_B()
{
rightEncoder.B_CHANGED();
}
void menuAction(MenuItemType type, String data)
{
DEBUG_PRINT("Main: menuAction(): ");
waitForSourceUpdate = false;
waitForQueueUpdate = false;
waitForLibraryUpdate = false;
restoreMenuPosition = false;
waitForMenuItemsUpdate = false;
waitForUiConfigSection = false;
switch (type)
{
case MENU_HOME:
DEBUG_PRINT("MENU_HOME");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
restoreMenuPosition = true;
menuMain();
break;
case MENU_BACK:
DEBUG_PRINT("MENU_BACK");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
//Jump 2 menus up and then one down
//Same effect as jumping one up, but minimizes stack size because only action, not full menu can be stored
menuPop();
menuPop();
restoreMenuPosition = true;
menuAction(menuStack[menuStackIndex].Type, menuStack[menuStackIndex].Data);
break;
case MENU_STATUS:
DEBUG_PRINT("MENU_STATUS");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
statusDisplay = true;
break;
case MENU_BROWSE:
DEBUG_PRINT("MENU_BROWSE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
waitForSourceUpdate = true;
volumio.getBrowseSources();
break;
case MENU_BROWSE_SOURCE:
DEBUG_PRINT("MENU_BROWSE_SOURCE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_BACK, menuStack[menuStackIndex - 2].Text, MENU_BACK);
waitForLibraryUpdate = true;
volumio.browseLibrary(data);
break;
case MENU_BROWSE_PLAYLIST:
DEBUG_PRINT("MENU_BROWSE_PLAYLIST");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_BACK, menuStack[menuStackIndex - 2].Text, MENU_BACK);
waitForLibraryUpdate = true;
volumio.browseLibrary(data);
break;
case MENU_BROWSE_FOLDER:
DEBUG_PRINT("MENU_BROWSE_FOLDER");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_BACK, menuStack[menuStackIndex - 2].Text, MENU_BACK);
waitForLibraryUpdate = true;
volumio.browseLibrary(data);
break;
case MENU_BROWSE_SONG:
DEBUG_PRINT("MENU_BROWSE_SONG");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
contextMenuSong(data);
break;
case MENU_BROWSE_RADIOCATEGORY:
DEBUG_PRINT("MENU_BROWSE_RADIOCATEGORY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_BACK, menuStack[menuStackIndex - 2].Text, MENU_BACK);
waitForLibraryUpdate = true;
volumio.browseLibrary(data);
break;
case MENU_BROWSE_WEBRADIO:
DEBUG_PRINT("MENU_BROWSE_WEBRADIO");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
contextMenuWebradio(data);
break;
case MENU_BROWSE_STREAMINGCATEGORY:
DEBUG_PRINT("MENU_BROWSE_STREAMINGCATEGORY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_BACK, menuStack[menuStackIndex - 2].Text, MENU_BACK);
waitForLibraryUpdate = true;
volumio.browseLibrary(data);
break;
case MENU_BROWSE_FOLDER_PLAY:
DEBUG_PRINT("MENU_BROWSE_FOLDER_PLAY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.addPlay(data);
break;
case MENU_BROWSE_FOLDER_ADDTOQUEUE:
DEBUG_PRINT("MENU_BROWSE_FOLDER_ADDTOQUEUE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.addToQueue(data);
break;
case MENU_BROWSE_FOLDER_CLEARANDPLAY:
DEBUG_PRINT("MENU_BROWSE_FOLDER_CLEARANDPLAY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.replaceAndPlay(data);
break;
case MENU_BROWSE_FOLDER_ADDTOPLAYLIST:
DEBUG_PRINT("MENU_BROWSE_FOLDER_ADDTOPLAYLIST");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_BROWSE_FOLDER_ADDTOFAVORITES:
DEBUG_PRINT("MENU_BROWSE_FOLDER_ADDTOFAVORITES");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_BROWSE_SONG_PLAY:
DEBUG_PRINT("MENU_BROWSE_SONG_PLAY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.addPlay(data);
break;
case MENU_BROWSE_SONG_ADDTOQUEUE:
DEBUG_PRINT("MENU_BROWSE_SONG_ADDTOQUEUE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.addToQueue(data);
break;
case MENU_BROWSE_SONG_CLEARANDPLAY:
DEBUG_PRINT("MENU_BROWSE_SONG_CLEARANDPLAY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.replaceAndPlay(data);
break;
case MENU_BROWSE_SONG_ADDTOPLAYLIST:
DEBUG_PRINT("MENU_BROWSE_SONG_ADDTOPLAYLIST");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_BROWSE_SONG_ADDTOFAVORITES:
DEBUG_PRINT("MENU_BROWSE_SONG_ADDTOFAVORITES");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.addToFavourites("mpd", menuStack[menuStackIndex - 1].Text, menuStack[menuStackIndex - 1].Data);
break;
case MENU_BROWSE_WEBRADIO_PLAY:
DEBUG_PRINT("MENU_BROWSE_WEBRADIO_PLAY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.addPlay("webradio", menuStack[menuStackIndex - 1].Text, menuStack[menuStackIndex - 1].Data);
break;
case MENU_BROWSE_WEBRADIO_ADDTOQUEUE:
DEBUG_PRINT("MENU_BROWSE_WEBRADIO_ADDTOQUEUE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.addToQueue("webradio", menuStack[menuStackIndex - 1].Text, menuStack[menuStackIndex - 1].Data);
break;
case MENU_BROWSE_WEBRADIO_CLEARANDPLAY:
DEBUG_PRINT("MENU_BROWSE_WEBRADIO_CLEARANDPLAY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.replaceAndPlay("webradio", menuStack[menuStackIndex - 1].Text, menuStack[menuStackIndex - 1].Data);
break;
case MENU_BROWSE_WEBRADIO_ADDTOPLAYLIST:
DEBUG_PRINT("MENU_BROWSE_WEBRADIO_ADDTOPLAYLIST");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_BROWSE_WEBRADIO_ADDTOFAVORITES:
DEBUG_PRINT("MENU_BROWSE_WEBRADIO_ADDTOFAVORITES");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.addToFavourites("webradio", menuStack[menuStackIndex - 1].Text, menuStack[menuStackIndex - 1].Data);
break;
case MENU_PLAYBACK:
DEBUG_PRINT("MENU_PLAYBACK");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
menuPlayback();
break;
case MENU_PLAYBACK_PREV:
DEBUG_PRINT("MENU_PLAYBACK_PREV");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.prev();
break;
case MENU_PLAYBACK_NEXT:
DEBUG_PRINT("MENU_PLAYBACK_NEXT");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.next();
break;
case MENU_PLAYBACK_PLAY:
DEBUG_PRINT("MENU_PLAYBACK_PLAY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.play();
break;
case MENU_PLAYBACK_PAUSE:
DEBUG_PRINT("MENU_PLAYBACK_PAUSE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.pause();
break;
case MENU_PLAYBACK_TOGGLE:
DEBUG_PRINT("MENU_PLAYBACK_TOGGLE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.toggle();
break;
case MENU_PLAYBACK_STOP:
DEBUG_PRINT("MENU_PLAYBACK_STOP");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.stop();
break;
case MENU_PLAYBACK_RANDOM_SET:
DEBUG_PRINT("MENU_PLAYBACK_RANDOM_SET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.setRandom(true);
break;
case MENU_PLAYBACK_RANDOM_RESET:
DEBUG_PRINT("MENU_PLAYBACK_RANDOM_RESET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.setRandom(false);
break;
case MENU_PLAYBACK_RANDOM_SET_RESET:
DEBUG_PRINT("MENU_PLAYBACK_RANDOM_SET_RESET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.setRandom(volumio.State.random == "false");
break;
case MENU_PLAYBACK_REPEAT_SET:
DEBUG_PRINT("MENU_PLAYBACK_REPEAT_SET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.setRepeat(true);
break;
case MENU_PLAYBACK_REPEAT_RESET:
DEBUG_PRINT("MENU_PLAYBACK_REPEAT_RESET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.setRepeat(false);
break;
case MENU_PLAYBACK_REPEAT_SET_RESET:
DEBUG_PRINT("MENU_PLAYBACK_REPEAT_SET_RESET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.setRepeat(volumio.State.repeat == "false");
break;
case MENU_PLAYBACK_FAVORITE_SET:
DEBUG_PRINT("MENU_PLAYBACK_FAVORITE_SET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_PLAYBACK_FAVORITE_RESET:
DEBUG_PRINT("MENU_PLAYBACK_FAVORITE_RESET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_PLAYBACK_FAVORITE_SET_RESET:
DEBUG_PRINT("MENU_PLAYBACK_FAVORITE_SET_RESET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_PLAYBACK_PLAYLIST_ADD:
DEBUG_PRINT("MENU_PLAYBACK_PLAYLIST_ADD");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_PLAYBACK_MUTE_SET:
DEBUG_PRINT("MENU_PLAYBACK_MUTE_SET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.mute();
break;
case MENU_PLAYBACK_MUTE_RESET:
DEBUG_PRINT("MENU_PLAYBACK_MUTE_RESET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.unmute();
break;
case MENU_PLAYBACK_MUTE_SET_RESET:
DEBUG_PRINT("MENU_PLAYBACK_MUTE_SET_RESET");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_QUEUE:
DEBUG_PRINT("MENU_QUEUE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_CLEAR, locale.TRACK_INFO_BAR.CLEAR_QUEUE, MENU_QUEUE_CLEAR);
waitForQueueUpdate = true;
volumio.getQueue();
break;
case MENU_QUEUE_CLEAR:
DEBUG_PRINT("MENU_QUEUE_CLEAR");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.clearQueue();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_CLEAR, locale.TRACK_INFO_BAR.CLEAR_QUEUE, MENU_QUEUE_CLEAR);
waitForQueueUpdate = true;
volumio.getQueue();
break;
case MENU_QUEUE_RANDOM:
DEBUG_PRINT("MENU_QUEUE_RANDOM");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_QUEUE_REPEAT:
DEBUG_PRINT("MENU_QUEUE_REPEAT");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
break;
case MENU_QUEUE_TRACK:
DEBUG_PRINT("MENU_QUEUE_TRACK");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
contextMenuQueue(atoi(data.c_str()));
break;
case MENU_QUEUE_TRACK_DELETE:
DEBUG_PRINT("MENU_QUEUE_TRACK_DELETE");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.removeQueueItem(atoi(data.c_str()));
menuPop();
menuPop();
menuAction(menuStack[menuStackIndex].Type, menuStack[menuStackIndex].Data);
break;
case MENU_QUEUE_TRACK_PLAY:
DEBUG_PRINT("MENU_QUEUE_TRACK_PLAY");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
volumio.play(atoi(data.c_str()));
menuPop();
menuPop();
menuAction(menuStack[menuStackIndex].Type, menuStack[menuStackIndex].Data);
break;
case MENU_SETTINGS:
DEBUG_PRINT("MENU_SETTINGS");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
volumio.getMenuItems();
waitForMenuItemsUpdate = true;
break;
case MENU_SETTINGS_PLUGIN:
DEBUG_PRINT("MENU_SETTINGS_PLUGIN");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_BACK, menuStack[menuStackIndex - 2].Text, MENU_BACK);
volumio.getUiConfig(data);
waitForUiConfigSection = true;
break;
case MENU_SETTINGS_MODAL:
DEBUG_PRINT("MENU_SETTINGS_MODAL");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_BACK, menuStack[menuStackIndex - 2].Text, MENU_BACK);
volumio.getUiConfig(data);
waitForUiConfigSection = true;
break;
case MENU_SETTINGS_URL:
DEBUG_PRINT("MENU_SETTINGS_URL");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
menuPush();
genMenuStart();
genMenuItem(ICON_HOME, locale.COMMON.HOME, MENU_HOME);
genMenuItem(ICON_BACK, menuStack[menuStackIndex - 2].Text, MENU_BACK);
volumio.getUiConfig(data);
waitForUiConfigSection = true;
break;
case MENU_DARK:
DEBUG_PRINT("MENU_DARK");
DEBUG_PRINT(": ");
DEBUG_PRINTLN(data);
noDisplay = true;
break;
}
}
void setup()
{
//Initialize serial port for debugging
Serial.begin(115200); //Original: 921600
delay(10);
locale = Locale_en();
//Initialize display
//#if Display == Display_SSD1351
display.initialize();
display.clearScreen();
display.flush();
/*
#else
display.begin();
display.enableUTF8Print();
ui.initialize(&display);
#endif
*/
scroll1.initialize();
scroll2.initialize();
scroll3.initialize();
DEBUG_PRINTLN();
//Initialize WiFi
WiFi.enableSTA(true);
WiFi.persistent(false);
WiFi.begin(ssid.c_str(), password.c_str());
WiFi.setAutoConnect(true);
WiFi.setAutoReconnect(true);
WiFi.mode(WIFI_STA);
//Initialize left encoder
leftEncoder.begin(PIN_LeftEncoder_CLK, PIN_LeftEncoder_DT, INPUT_PULLUP);
attachInterrupt(PIN_LeftEncoder_CLK, ISR_LeftEncoder_A, CHANGE);
attachInterrupt(PIN_LeftEncoder_DT, ISR_LeftEncoder_B, CHANGE);
//Initialize right encoder
rightEncoder.begin(PIN_RightEncoder_CLK, PIN_RightEncoder_DT, INPUT_PULLUP);
attachInterrupt(PIN_RightEncoder_CLK, ISR_RightEncoder_A, CHANGE);
attachInterrupt(PIN_RightEncoder_DT, ISR_RightEncoder_B, CHANGE);
//Initialize push button of left encoder
leftSwitch.begin(PIN_LeftEncoder_SW, INPUT_PULLUP);
//Initialize push button of right encoder
rightSwitch.begin(PIN_RightEncoder_SW, INPUT_PULLUP);
//Capacitive touch pins
//actually not used
TouchPin0.begin(PIN_TOUCH0, INPUT_PULLUP);
TouchPin1.begin(PIN_TOUCH1, INPUT_PULLUP);
TouchPin2.begin(PIN_TOUCH2, INPUT_PULLUP);
TouchPin3.begin(PIN_TOUCH3, INPUT_PULLUP);
/*
TouchPin4.begin(PIN_TOUCH4);
TouchPin5.begin(PIN_TOUCH5);
TouchPin6.begin(PIN_TOUCH6);
*/
//Capacitive touch pins
//not useable, pins already used by encoders
/*
TouchPin7.begin(PIN_TOUCH7);
TouchPin8.begin(PIN_TOUCH8);
TouchPin9.begin(PIN_TOUCH9);
*/
}
int py = 0;
bool dir = false;
void loop()
{
unsigned long now = millis();
/*#################################################################*\
|* Connection to WiFi and Voulumio
\*#################################################################*/
//Check if WiFi is connected. If not --> reconnect
/*
while (WiFi.status() != WL_CONNECTED)
{
DEBUG_PRINT("Main: WiFi: Status: ");
DEBUG_PRINTLN(WiFiStatusString());
DisplayMessage(locale.ESP.ConnectWiFi);
delay(1000);
}
*/
// /*
while (WiFi.status() != WL_CONNECTED)
{
DEBUG_PRINT("Main: WiFi: Status: ");
DEBUG_PRINTLN(WiFiStatusString());
DisplayMessage(locale.ESP.ConnectWiFi);
int retrys = 0;
WiFi.reconnect();
delay(1000);
while (WiFi.status() != WL_CONNECTED)
{
WiFi.disconnect();
DEBUG_PRINT("Main: WiFi: Connecting to ");
DEBUG_PRINTLN(ssid);
int laswtifistate = WiFi.status();
WiFi.disconnect();
WiFi.mode(WIFI_OFF);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid.c_str(), password.c_str());
for (int i = 0; i < 10; i++)
{
DEBUG_PRINT("Main: WiFi: Status: ");
DEBUG_PRINTLN(WiFiStatusString());
if (WiFi.status() == WL_CONNECTED)
break;
if (WiFi.status() != laswtifistate)
break;
delay(100);
}
if (retrys++ > 10 && WiFi.status() != WL_CONNECTED)
{
DEBUG_PRINT("Main: WiFi: Too many retrys, restarting ESP");
ESP.restart();
}
}
DEBUG_PRINT("Main: WiFi: IP address: ");
DEBUG_PRINTLN(WiFi.localIP());
DEBUG_PRINTLN();
}
//*/
//Check if Volumio (SocketIO) is connected. If not --> reconnect
while (!volumio.getConnected())
{
DisplayMessage(locale.ESP.ConnectVolumio);
volumio.connect(host, port);
if (!volumio.getConnected())
delay(100);
else
{
volumio.getState();
volumio.getUiSettings();
// volumio.getDeviceInfo();
// volumio.getSystemVersion();
// volumio.getPushType();
// volumio.getPlaylistIndex();
// volumio.getAvailableLanguages();
// volumio.getAudioOutputs();
// volumio.getMenuItems();
// volumio.getUiConfig("miscellanea/my_music");
// volumio.getInstalledPlugins();
// volumio.getAvaliablePlugins();
menuMain();
}
}
/*#################################################################*\
|* Process data from Volumio (pushed Updates)
\*#################################################################*/
volumio.process();
switch (volumio.getPushType())
{
case Volumio::pushBrowseSources: //Volumio pushes list of sources
DEBUG_PRINTLN("Main: Volumio: pushBrowseSources");
//Only if push was requested
if (waitForSourceUpdate)
{
waitForSourceUpdate = false;
while (volumio.readNextSourceItem())
{
DEBUG_PRINT("Main: Volumio: SourceItem: ");
DEBUG_PRINT(volumio.CurrentSourceItem.name);
DEBUG_PRINT(": ");
DEBUG_PRINTLN(volumio.CurrentSourceItem.uri);
genMenuItem(ICON_ARROW, volumio.CurrentSourceItem.name, MENU_BROWSE_SOURCE, volumio.CurrentSourceItem.uri);
}
genMenuEnd();
if (restoreMenuPosition && false)
{
restoreMenuPosition = false;
leftEncoder.setValue(menuStack[menuStackIndex].Position);
menuOffset = menuStack[menuStackIndex].Offset;
}
}
break;
case Volumio::pushBrowseLibrary: //Volumio pushes library content
DEBUG_PRINTLN("Main: Volumio: pushBrowseLibrary");
//Only if push was requested
if (waitForLibraryUpdate)
{
waitForLibraryUpdate = false;
volumio.LibraryPrev.uri = "";
while (volumio.readNextLibraryItem())
{
DEBUG_PRINT("Main: Volumio: LibraryItem: ");
DEBUG_PRINT(volumio.CurrentLibraryItem.type);
DEBUG_PRINT(": ");
DEBUG_PRINT(volumio.CurrentLibraryItem.title);
DEBUG_PRINT(": ");
DEBUG_PRINTLN(volumio.CurrentLibraryItem.uri);
if (volumio.CurrentLibraryItem.type == "song")
genMenuItem(ICON_SONG, volumio.CurrentLibraryItem.title, MENU_BROWSE_SONG, volumio.CurrentLibraryItem.uri);
else if (volumio.CurrentLibraryItem.type == "folder")
genMenuItem(ICON_ARROW, volumio.CurrentLibraryItem.title, MENU_BROWSE_FOLDER, volumio.CurrentLibraryItem.uri);
else if (volumio.CurrentLibraryItem.type == "radio-category")
genMenuItem(ICON_ARROW, volumio.CurrentLibraryItem.title, MENU_BROWSE_RADIOCATEGORY, volumio.CurrentLibraryItem.uri);
else if (volumio.CurrentLibraryItem.type == "mywebradio-category")
genMenuItem(ICON_ARROW, volumio.CurrentLibraryItem.title, MENU_BROWSE_RADIOCATEGORY, volumio.CurrentLibraryItem.uri);
else if (volumio.CurrentLibraryItem.type == "radio-favourites")
genMenuItem(ICON_ARROW, volumio.CurrentLibraryItem.title, MENU_BROWSE_RADIOCATEGORY, volumio.CurrentLibraryItem.uri);
else if (volumio.CurrentLibraryItem.type == "streaming-category")
genMenuItem(ICON_ARROW, volumio.CurrentLibraryItem.title, MENU_BROWSE_STREAMINGCATEGORY, volumio.CurrentLibraryItem.uri);
else if (volumio.CurrentLibraryItem.type == "webradio")
genMenuItem(ICON_ARROW, volumio.CurrentLibraryItem.title, MENU_BROWSE_WEBRADIO, volumio.CurrentLibraryItem.uri);
else if (volumio.CurrentLibraryItem.type == "playlist")
genMenuItem(ICON_ARROW, volumio.CurrentLibraryItem.title, MENU_BROWSE_PLAYLIST, volumio.CurrentLibraryItem.uri);
else
genMenuItem(ICON_ARROW, volumio.CurrentLibraryItem.type, MENU_HOME);
}
while (volumio.readLibraryPrev())
;
DEBUG_PRINT("Main: Volumio: LibraryPrev: ");
DEBUG_PRINTLN(volumio.LibraryPrev.uri);
//If there is an uri for full library, add play options
if (volumio.LibraryInfo.uri != "")
{
DEBUG_PRINT("Main: Volumio: LibraryInfo: ");
DEBUG_PRINT(volumio.LibraryInfo.title);
DEBUG_PRINT(": ");
DEBUG_PRINTLN(volumio.LibraryInfo.uri);
genMenuItem(ICON_PLAY, locale.BROWSER.PLAY, MENU_BROWSE_FOLDER_PLAY, volumio.LibraryInfo.uri);
genMenuItem(ICON_LIST, locale.BROWSER.ADD_TO_QUEUE, MENU_BROWSE_FOLDER_ADDTOQUEUE, volumio.LibraryInfo.uri);
genMenuItem(ICON_LIST, locale.BROWSER.CLEAR_AND_PLAY, MENU_BROWSE_FOLDER_CLEARANDPLAY, volumio.LibraryInfo.uri);
}
genMenuEnd();
if (restoreMenuPosition && false)
{
restoreMenuPosition = false;
leftEncoder.setValue(menuStack[menuStackIndex].Position);
menuOffset = menuStack[menuStackIndex].Offset;
}
}
break;
case Volumio::pushQueue: //Volumio pushes queue content
DEBUG_PRINTLN("Main: Volumio: pushQueue");
//Only if push was requested
if (waitForQueueUpdate)
{
waitForQueueUpdate = false;
//Queue is referenced by index, not uri
int index = 0;
while (volumio.readNextQueueItem())
if (volumio.CurrentQueueItem.name != "")
{
DEBUG_PRINT("Main: Volumio: QueueItem: ");
DEBUG_PRINT(volumio.CurrentQueueItem.name);
DEBUG_PRINT(": ");
DEBUG_PRINTLN(index);
genMenuItem(ICON_SONG, volumio.CurrentQueueItem.name, MENU_QUEUE_TRACK, String(index++));
}
genMenuEnd();
if (restoreMenuPosition && false)
{
restoreMenuPosition = false;
leftEncoder.setValue(menuStack[menuStackIndex].Position);
menuOffset = menuStack[menuStackIndex].Offset;
}
}
break;
case Volumio::pushToastMessage: //Volumio pushes toast message
DEBUG_PRINTLN("Main: Volumio: pushToastMessage");
if (toastActivatesDisplay)
{
if (noDisplay)
statusDisplay = true;
lastinput = now;
noDisplay = false;
}
if (volumio.readPushToastMessage())
{
if (durationShowToast > 0)
toastDisplay = true;
toastStart = now;
}
break;
case Volumio::pushState: //Volumio pushes status update
DEBUG_PRINTLN("Main: Volumio: pushState");
volumio.readState();
waitvolumechange = false;
break;
case Volumio::pushMultiRoomDevices:
DEBUG_PRINTLN("Main: Volumio: pushMultiRoomDevices");
while (volumio.readMultiRoomDevice())
;
break;
case Volumio::pushUiSettings:
DEBUG_PRINTLN("Main: Volumio: pushUiSettings");
volumio.readUiSettings();
DEBUG_PRINT("Main: language = ");
DEBUG_PRINTLN(volumio.UiSettings.language);
if (volumio.UiSettings.language == "de")
locale = Locale_de();
else
locale = Locale_en();
menuMain();
break;
case Volumio::pushDeviceInfo:
DEBUG_PRINTLN("Main: Volumio: pushDeviceInfo");
volumio.readDeviceInfo();
case Volumio::pushSystemVersion:
DEBUG_PRINTLN("Main: Volumio: pushSystemVersion");
volumio.readSystemVersion();
case Volumio::pushMenuItems:
DEBUG_PRINTLN("Main: Volumio: pushMenuItems");
//Only if push was requested
if (waitForMenuItemsUpdate)
{
waitForMenuItemsUpdate = false;
//Queue is referenced by index, not uri
int index = 0;
while (volumio.readNextMenuItem())
if (volumio.CurrentMenuItem.name != "")
{
DEBUG_PRINT("Main: Volumio: MenuItem: ");
DEBUG_PRINT(volumio.CurrentMenuItem.name);
DEBUG_PRINT(": ");
DEBUG_PRINTLN(index);
if (volumio.CurrentMenuItem.params.pluginName != "")
genMenuItem(ICON_ARROW, volumio.CurrentMenuItem.name, MENU_SETTINGS_PLUGIN, volumio.CurrentMenuItem.params.pluginName);
else if (volumio.CurrentMenuItem.params.modalName != "")
genMenuItem(ICON_ARROW, volumio.CurrentMenuItem.name, MENU_SETTINGS_MODAL, volumio.CurrentMenuItem.params.modalName);
else if (volumio.CurrentMenuItem.params.url != "")
genMenuItem(ICON_ARROW, volumio.CurrentMenuItem.name, MENU_SETTINGS_URL, volumio.CurrentMenuItem.params.url);
}
genMenuEnd();