forked from Maschine2501/NR1-UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnr1ui.py
4420 lines (4237 loc) · 270 KB
/
nr1ui.py
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
#!/usr/bin/python3
# ____ ____ ___ __ ___ __ _ ______ ___
# / __ )/ __ \/ | / / / / | / / / | / / __ < /
# / __ / /_/ / /| |/ / / / |/ / / |/ / /_/ / /
# / /_/ / _, _/ ___ / /_/ / /| / / /| / _, _/ /
# /_____/_/ |_/_/ |_\____/_/ |_/ /_/ |_/_/ |_/_/
# __ __ ____ __ ___
# / / / /__ ___ ____ / _/__ / /____ ____/ _/__ ________
# / /_/ (_-</ -_) __/ _/ // _ \/ __/ -_) __/ _/ _ `/ __/ -_)
# \____/___/\__/_/ /___/_//_/\__/\__/_/ /_/ \_,_/\__/\__/
#
# For more Informations visit: https://github.com/Maschine2501/NR1-UI
# _ __ __ ___ ___ ___ __ _
# | |__ _ _ | \/ / __|_ ) __|/ \/ |
# | '_ \ || | | |\/| \__ \/ /|__ \ () | |
# |_.__/\_, | |_| |_|___/___|___/\__/|_|
# |__/
#________________________________________________________________________________________
#________________________________________________________________________________________
#
# ____ __
# / _/___ ___ ____ ____ _____/ /______ _
# / // __ `__ \/ __ \/ __ \/ ___/ __/ ___/ (_)
# _/ // / / / / / /_/ / /_/ / / / /_(__ ) _
#/___/_/ /_/ /_/ .___/\____/_/ \__/____/ (_)
# /_/
from __future__ import unicode_literals
import requests
import os
import sys
import time
import threading
import signal
import json
import pycurl
import pprint
import subprocess
import RPi.GPIO as GPIO
from time import*
from datetime import timedelta as timedelta
from threading import Thread
from socketIO_client import SocketIO
from datetime import datetime as datetime
from io import BytesIO
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from modules.pushbutton import PushButton
from modules.rotaryencoder import RotaryEncoder
import uuid
import numpy as np
from ConfigurationFiles.PreConfiguration import*
import urllib.request
from urllib.parse import* #from urllib import*
from urllib.parse import urlparse
from urllib.parse import urlencode
import ssl
import re
import fnmatch
sleep(5.0)
# Socket-IO-Configuration for Rest API
volumio_host = 'localhost'
volumio_port = 3000
volumioIO = SocketIO(volumio_host, volumio_port)
# Logic to prevent freeze if FIFO-Out for Cava is missing:
ReNewMPDconf = {'endpoint': 'music_service/mpd', 'method': 'createMPDFile', 'data': ''}
if SpectrumActive == True:
with open('/etc/mpd.conf') as f1:
if '/tmp/mpd.fifo' in f1.read():
print("CAVA1 Fifo-Output is present in mpd.conf")
else:
print('CAVA1 FIFO-Output in /etc/mpd.conf is missing!')
print('Rebuilding mpd.conf now, this will take ~5 seconds.')
volumioIO.emit('callMethod', ReNewMPDconf)
sleep(4.0)
with open('/etc/mpd.conf') as f2:
if '/tmp/mpd2.fifo' in f2.read():
print("CAVA2 Fifo-Output is present in mpd.conf")
else:
print('CAVA2 FIFO-Output in /etc/mpd.conf is missing!')
print('Rebuilding mpd.conf now, this will take ~5 seconds.')
volumioIO.emit('callMethod', ReNewMPDconf)
sleep(4.0)
#________________________________________________________________________________________
#
# ______ _____ __ _
# / ____/___ ____ / __(_)___ ___ ___________ _/ /_(_)___ ____ _
# / / / __ \/ __ \/ /_/ / __ `/ / / / ___/ __ `/ __/ / __ \/ __ \ (_)
#/ /___/ /_/ / / / / __/ / /_/ / /_/ / / / /_/ / /_/ / /_/ / / / / _
#\____/\____/_/ /_/_/ /_/\__, /\__,_/_/ \__,_/\__/_/\____/_/ /_/ (_)
# /____/
#
if DisplayTechnology == 'spi1322':
if SpectrumActive == True:
ScreenList = ['Spectrum-Center', 'No-Spectrum', 'Modern', 'VU-Meter-2', 'VU-Meter-Bar']
if SpectrumActive == False:
ScreenList = ['No-Spectrum']
if DisplayTechnology == 'Braun':
if SpectrumActive == True:
ScreenList = ['Spectrum-Center', 'No-Spectrum', 'Modern', 'VU-Meter-2', 'VU-Meter-Bar']
if SpectrumActive == False:
ScreenList = ['No-Spectrum']
if DisplayTechnology == 'spi1351':
if SpectrumActive == True:
ScreenList = ['No-Spectrum', 'Spectrum-Center']
if SpectrumActive == False:
ScreenList = ['No-Spectrum']
if DisplayTechnology == 'st7735':
if SpectrumActive == True:
ScreenList = ['No-Spectrum', 'Spectrum-Center']
if SpectrumActive == False:
ScreenList = ['No-Spectrum']
if DisplayTechnology == 'i2c1306':
if SpectrumActive == True:
ScreenList = ['Progress-Bar', 'Essential', 'Spectrum-Screen']
if SpectrumActive == False:
ScreenList = ['Progress-Bar', 'Essential']
NowPlayingLayoutSave=open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt').readline().rstrip()
print('Layout selected during setup: ', NowPlayingLayout)
print('Last manually selected Layout: ', NowPlayingLayoutSave)
if DisplayTechnology == 'spi1322':
if NowPlayingLayout not in ScreenList:
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('No-Spectrum')
WriteScreen1.close
NowPlayingLayout = 'No-Spectrum'
if DisplayTechnology == 'spi1351':
if NowPlayingLayout not in ScreenList:
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('No-Spectrum')
WriteScreen1.close
NowPlayingLayout = 'No-Spectrum'
if DisplayTechnology == 'st7735':
if NowPlayingLayout not in ScreenList:
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('No-Spectrum')
WriteScreen1.close
NowPlayingLayout = 'No-Spectrum'
if DisplayTechnology == 'Braun':
if NowPlayingLayout not in ScreenList:
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('No-Spectrum')
WriteScreen1.close
NowPlayingLayout = 'No-Spectrum'
if DisplayTechnology == 'i2c1306':
if NowPlayingLayout not in ScreenList:
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('Progress-Bar')
WriteScreen1.close
NowPlayingLayout = 'Progress-Bar'
if NowPlayingLayoutSave != NowPlayingLayout:
if NowPlayingLayoutSave not in ScreenList and SpectrumActive == False:
if DisplayTechnology == 'i2c1306':
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('Progress-Bar')
WriteScreen1.close
NowPlayingLayout = 'Progress-Bar'
if DisplayTechnology == 'spi1322':
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('No-Spectrum')
WriteScreen1.close
NowPlayingLayout = 'No-Spectrum'
if DisplayTechnology == 'spi1351':
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('No-Spectrum')
WriteScreen1.close
NowPlayingLayout = 'No-Spectrum'
if DisplayTechnology == 'st7735':
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('No-Spectrum')
WriteScreen1.close
NowPlayingLayout = 'No-Spectrum'
if DisplayTechnology == 'Braun':
WriteScreen1 = open('/home/volumio/NR1-UI/ConfigurationFiles/LayoutSet.txt', 'w')
WriteScreen1.write('No-Spectrum')
WriteScreen1.close
NowPlayingLayout = 'No-Spectrum'
else:
NowPlayingLayout = NowPlayingLayoutSave
#config for timers:
oledPlayFormatRefreshTime = 1.5
oledPlayFormatRefreshLoopCount = 3
#________________________________________________________________________________________
#________________________________________________________________________________________
# _____ __ __ __ _____ _ __ _
# / ___// /_____ ______/ /_ ____/ /__ / __(_)___ (_) /_(_)___ ____ _____ _
# \__ \/ __/ __ `/ ___/ __/_____/ __ / _ \/ /_/ / __ \/ / __/ / __ \/ __ \/ ___/ (_)
# ___/ / /_/ /_/ / / / /_/_____/ /_/ / __/ __/ / / / / / /_/ / /_/ / / / (__ ) _
#/____/\__/\__,_/_/ \__/ \__,_/\___/_/ /_/_/ /_/_/\__/_/\____/_/ /_/____/ (_)
#
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
firstStart = True
if DisplayTechnology == 'spi1322':
from luma.core.interface.serial import spi
from luma.oled.device import ssd1322
from modules.display1322 import*
from ConfigurationFiles.ScreenConfig1322 import*
if DisplayTechnology == 'Braun':
from luma.core.interface.serial import spi
from luma.oled.device import ssd1322
from modules.displayBraun import*
from ConfigurationFiles.ScreenConfigBraun import*
if DisplayTechnology == 'i2c1306':
from luma.core.interface.serial import i2c
from luma.oled.device import ssd1306
from modules.display1306 import*
from ConfigurationFiles.ScreenConfig1306 import*
if DisplayTechnology == 'spi1351':
from luma.core.interface.serial import spi
from luma.oled.device import ssd1351
from modules.display1351 import*
from ConfigurationFiles.ScreenConfig1351 import*
if DisplayTechnology == 'st7735':
from luma.core.interface.serial import spi
from luma.lcd.device import st7735
from modules.display7735 import*
from ConfigurationFiles.ScreenConfig7735 import*
if firstStart == True:
if ledTechnology == None:
from modules.StatusLEDempty import*
if ledTechnology == 'GPIOusage':
from modules.StatusLEDgpio import*
if ledTechnology == 'pcf8574usage':
from modules.StatusLEDpcf import*
if StandbyActive == True:
GPIO.setup(13, GPIO.OUT)
GPIO.setup(26, GPIO.IN)
GPIO.output(13, GPIO.HIGH)
b_obj = BytesIO()
crl = pycurl.Curl()
STATE_NONE = -1
STATE_PLAYER = 0
STATE_QUEUE_MENU = 1
STATE_LIBRARY_INFO = 2
STATE_SCREEN_MENU = 3
UPDATE_INTERVAL = 0.034
if DisplayTechnology == 'spi1322' or DisplayTechnology == 'Braun':
interface = spi(device=0, port=0)
oled = ssd1322(interface, rotate=oledrotation)
oled.WIDTH = 256
oled.HEIGHT = 64
if DisplayTechnology == 'i2c1306':
interface = i2c(port=1, address=0x3C)
oled = ssd1306(interface) #, rotate=oledrotation)
oled.WIDTH = 128
oled.HEIGHT = 64
if DisplayTechnology == 'spi1351':
interface = spi(device=0, port=0)
oled = ssd1351(interface, rotate=oledrotation)
oled.WIDTH = 128
oled.HEIGHT = 128
if DisplayTechnology == 'st7735':
interface = spi(port=0, device=0, cs_high=True, gpio_DC=14, gpio_RST=24)
oled = st7735(interface, rotate=oledrotation, width=160, height=128, h_offset=0, v_offset=0, bgr=False)
oled.WIDTH = 160
oled.HEIGHT = 128
oled.state = 'stop'
oled.stateTimeout = 0
oled.playstateIcon = ''
oled.timeOutRunning = False
oled.activeSong = ''
oled.activeArtist = 'VOLuMIO'
oled.playState = 'unknown'
oled.playPosition = 0
oled.seek = 1000
oled.duration = 1.0
oled.modal = False
oled.playlistoptions = []
oled.queue = []
oled.libraryFull = []
oled.libraryNames = []
oled.volumeControlDisabled = True
oled.volume = 100
now = datetime.now() #current date and time
oled.time = now.strftime("%H:%M:%S") #resolves time as HH:MM:SS eg. 14:33:15
oled.date = "" #resolves time as dd.mm.YYYY eg. 17.04.2020
oled.IP = ''
emit_track = False
newStatus = 0 #makes newStatus usable outside of onPushState
oled.activeFormat = '' #makes oled.activeFormat globaly usable
oled.activeSamplerate = '' #makes oled.activeSamplerate globaly usable
oled.activeBitdepth = '' #makes oled.activeBitdepth globaly usable
oled.activeArtists = '' #makes oled.activeArtists globaly usable
oled.activeAlbums = '' #makes oled.activeAlbums globaly usable
oled.activeAlbum = ''
oled.activeAlbumart = ''
oled.activeSongs = '' #makes oled.activeSongs globaly usable
oled.activePlaytime = '' #makes oled.activePlaytime globaly usable
oled.randomTag = False #helper to detect if "Random/shuffle" is set
oled.repeatTag = False #helper to detect if "repeat" is set
oled.ShutdownFlag = False #helper to detect if "shutdown" is running. Prevents artifacts from Standby-Screen during shutdown
varcanc = True #helper for pause -> stop timeout counter
secvar = 0.0
oled.volume = 100
oled.SelectedScreen = NowPlayingLayout
oled.fallingL = False
oled.fallingR = False
oled.prevFallingTimerL = 0
oled.prevFallingTimerR = 0
ScrollArtistTag = 0
ScrollArtistNext = 0
ScrollArtistFirstRound = True
ScrollArtistNextRound = False
ScrollSongTag = 0
ScrollSongNext = 0
ScrollSongFirstRound = True
ScrollSongNextRound = False
ScrollAlbumTag = 0
ScrollAlbumNext = 0
ScrollAlbumFirstRound = True
ScrollAlbumNextRound = False
ScrollSpecsTag = 0
ScrollSpecsNext = 0
ScrollSpecsFirstRound = True
ScrollSpecsNextRound = False
oled.selQueue = ''
oled.repeat = False
oled.bitrate = ''
oled.repeatonce = False
oled.shuffle = False
oled.mute = False
VOLUME_DT = 5
oled.ScreenTimer10 = False
oled.ScreenTimer20 = False
oled.ScreenTimerStamp = 0.0
oled.ScreenTimerStart = True
oled.ScreenTimerChangeTime = 10.0
if DisplayTechnology == 'spi1322':
image = Image.new('RGB', (oled.WIDTH, oled.HEIGHT)) #for Pixelshift: (oled.WIDTH + 4, oled.HEIGHT + 4))
if DisplayTechnology == 'Braun':
image = Image.new('RGB', (oled.WIDTH, oled.HEIGHT)) #for Pixelshift: (oled.WIDTH + 4, oled.HEIGHT + 4))
if DisplayTechnology == 'i2c1306':
image = Image.new('1', (oled.WIDTH, oled.HEIGHT)) #for Pixelshift: (oled.WIDTH + 4, oled.HEIGHT + 4))
if DisplayTechnology == 'spi1351':
image = Image.new('RGB', (oled.WIDTH, oled.HEIGHT)) #for Pixelshift: (oled.WIDTH + 4, oled.HEIGHT + 4))
if DisplayTechnology == 'st7735':
image = Image.new('RGB', (oled.WIDTH, oled.HEIGHT)) #for Pixelshift: (oled.WIDTH + 4, oled.HEIGHT + 4))
oled.clear()
#________________________________________________________________________________________
#________________________________________________________________________________________
#
# ______ __
# / ____/___ ____ / /______ _
# / /_ / __ \/ __ \/ __/ ___/ (_)
# / __/ / /_/ / / / / /_(__ ) _
#/_/ \____/_/ /_/\__/____/ (_)
#
if DisplayTechnology == 'spi1322' or DisplayTechnology == 'Braun':
font = load_font('NotoSansTC-Bold.otf', 18) #used for Artist ('Oxanium-Bold.ttf', 20)
font2 = load_font('NotoSansTC-Light.otf', 12) #used for all menus
font3 = load_font('NotoSansTC-Regular.otf', 16) #used for Song ('Oxanium-Regular.ttf', 18)
font4 = load_font('Oxanium-Medium.ttf', 12) #used for Format/Smplerate/Bitdepth
font5 = load_font('NotoSansTC-Medium.otf', 12) #used for Artist / Screen5
font6 = load_font('NotoSansTC-Regular.otf', 12) #used for Song / Screen5
font7 = load_font('Oxanium-Light.ttf', 10) #used for all other / Screen5
font8 = load_font('NotoSansTC-Regular.otf', 10) #used for Song / Screen5
font9 = load_font('NotoSansTC-Bold.otf', 16) #used for Artist ('Oxanium-Bold.ttf', 20)
font10 = load_font('NotoSansTC-Regular.otf', 14) #used for Artist ('Oxanium-Bold.ttf', 20)
font11 = load_font('Oxanium-Regular.ttf', 10) #used for specs in VUmeter2
font12 = load_font('Oxanium-Regular.ttf', 12) #used for Artist/Song VU Meter2
font13 = load_font('NotoSansTC-Regular.otf', 14) #used for Artist ('Oxanium-Bold.ttf', 20)
font14 = load_font('NotoSansTC-Light.otf', 12) #used for Artist ('Oxanium-Bold.ttf', 20)
mediaicon = load_font('fa-solid-900.ttf', 10) #used for icon in Media-library info
labelfont = load_font('entypo.ttf', 12) #used for Menu-icons
iconfontBottom = load_font('entypo.ttf', 10) #used for icons under the screen / button layout
labelfontfa = load_font('fa-solid-900.ttf', 12) #used for icons under the screen / button layout
labelfontfa2 = load_font('fa-solid-900.ttf', 14)
fontClock = load_font('DSG.ttf', 30) #used for clock
fontDate = load_font('Oxanium-Light.ttf', 12) #used for Date 'DSEG7Classic-Regular.ttf'
fontIP = load_font('Oxanium-Light.ttf', 12) #used for IP 'DSEG7Classic-Regular.ttf'
if DisplayTechnology == 'i2c1306':
font = load_font('NotoSansTC-Regular.otf', 14) #used for Artist font2 = load_font('Oxanium-Light.ttf', 12)
font2 = load_font('NotoSansTC-Light.otf', 10) #used for all menus
font3 = load_font('NotoSansTC-Regular.otf', 12) #used for Song font3 = load_font('Oxanium-Regular.ttf', 14)
font4 = load_font('NotoSansTC-Medium.otf', 10) #used for Format/Smplerate/Bitdepth
font5 = load_font('NotoSansTC-Regular.otf', 10) #used for artist in essential screen
font6 = load_font('NotoSansTC-Regular.otf', 16) #used for Song in essential screen
font7 = load_font('NotoSansTC-Medium.otf', 8) #used for Format/Smplerate/Bitdepth @ essential screen
mediaicon = load_font('fa-solid-900.ttf', 10) #used for icon in Media-library info
iconfont = load_font('entypo.ttf', oled.HEIGHT) #used for play/pause/stop/shuffle/repeat... icons
labelfont = load_font('entypo.ttf', 12) #used for Menu-icons
iconfontBottom = load_font('entypo.ttf', 10) #used for icons under the screen / button layout
fontClock = load_font('DSG.ttf', 24) #used for clock
fontDate = load_font('NotoSansTC-Medium.otf', 10) #used for Date
fontIP = load_font('NotoSansTC-Medium.otf', 10) #used for IP
if DisplayTechnology == 'spi1351':
font = load_font('NotoSansCJK.ttc', 16) #used for Artist NotoSansCJK.ttc
font2 = load_font('NotoSansCJK.ttc', 12) #used for all menus
font3 = load_font('NotoSansCJK.ttc', 14) #used for Song
font4 = load_font('NotoSansCJK.ttc', 12) #used for Format/Smplerate/Bitdepth
font5 = load_font('NotoSansCJK.ttc', 14) #used for Album
mediaicon = load_font('fa-solid-900.ttf', 10) #used for icon in Media-library info
iconfont = load_font('entypo.ttf', oled.HEIGHT) #used for play/pause/stop/shuffle/repeat... icons
labelfont = load_font('entypo.ttf', 12) #used for Menu-icons
iconfontBottom = load_font('entypo.ttf', 10) #used for icons under the screen / button layout
fontClock = load_font('DSG.ttf', 24) #used for clock
fontDate = load_font('NotoSansCJK.ttc', 12) #used for Date
fontIP = load_font('NotoSansCJK.ttc', 12) #used for IP
if DisplayTechnology == 'st7735':
font = load_font('NotoSansCJK.ttc', 16) #used for Artist NotoSansCJK.ttc
font2 = load_font('NotoSansCJK.ttc', 12) #used for all menus
font3 = load_font('NotoSansCJK.ttc', 14) #used for Song
font4 = load_font('NotoSansCJK.ttc', 12) #used for Format/Smplerate/Bitdepth
font5 = load_font('NotoSansCJK.ttc', 14) #used for Album
mediaicon = load_font('fa-solid-900.ttf', 10) #used for icon in Media-library info
iconfont = load_font('entypo.ttf', oled.HEIGHT) #used for play/pause/stop/shuffle/repeat... icons
labelfont = load_font('entypo.ttf', 12) #used for Menu-icons
iconfontBottom = load_font('entypo.ttf', 10) #used for icons under the screen / button layout
fontClock = load_font('DSG.ttf', 31) #used for clock
fontDate = load_font('NotoSansCJK.ttc', 12) #used for Date
fontIP = load_font('NotoSansCJK.ttc', 12) #used for IP
#above are the "imports" for the fonts.
#After the name of the font comes a number, this defines the Size (height) of the letters.
#Just put .ttf file in the 'Volumio-OledUI/fonts' directory and make an import like above.
#________________________________________________________________________________________
#________________________________________________________________________________________
#
# _____ __ ____ __ _
# / ___// /_____ _____ ____/ / /_ __ __ / / ____ ____ _(_)____ _
# \__ \/ __/ __ `/ __ \/ __ / __ \/ / / /_____/ / / __ \/ __ `/ / ___/ (_)
# ___/ / /_/ /_/ / / / / /_/ / /_/ / /_/ /_____/ /___/ /_/ / /_/ / / /__ _
#/____/\__/\__,_/_/ /_/\__,_/_.___/\__, / /_____/\____/\__, /_/\___/ (_)
# /____/ /____/
#
def StandByWatcher():
# listens to GPIO 26. If Signal is High, everything is fine, raspberry will keep doing it's shit.
# If GPIO 26 is Low, Raspberry will shutdown.
StandbySignal = GPIO.input(26)
while True:
StandbySignal = GPIO.input(26)
if StandbySignal == 0:
oled.ShutdownFlag = True
volumioIO.emit('stop')
GPIO.output(13, GPIO.LOW)
sleep(1)
oled.clear()
show_logo(oledShutdownLogo, oled)
volumioIO.emit('shutdown')
elif StandbySignal == 1:
sleep(1)
def sigterm_handler(signal, frame):
oled.ShutdownFlag = True
volumioIO.emit('stop')
GPIO.output(13, GPIO.LOW)
oled.clear()
show_logo("shutdown.ppm", oled)
#________________________________________________________________________________________
#________________________________________________________________________________________
#
# ________ ___ __
# / _/ __ \ / | ____/ /_______ __________ _
# / // /_/ /_____/ /| |/ __ / ___/ _ \/ ___/ ___/ (_)
# _/ // ____/_____/ ___ / /_/ / / / __(__ |__ ) _
#/___/_/ /_/ |_\__,_/_/ \___/____/____/ (_)
#
def GetIP():
lanip = GetLANIP()
LANip = str(lanip.decode('ascii'))
print('LAN IP: ', LANip)
wanip = GetWLANIP()
WLANip = str(wanip.decode('ascii'))
print('Wifi IP: ', WLANip)
if LANip != '':
ip = LANip
elif WLANip != '':
ip = WLANip
else:
ip = "no ip"
oled.IP = ip
def GetLANIP():
cmd = \
"ip addr show eth0 | grep inet | grep -v inet6 | awk '{print $2}' | cut -d '/' -f 1"
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
output = p.communicate()[0]
return output[:-1]
def GetWLANIP():
cmd = \
"ip addr show wlan0 | grep inet | grep -v inet6 | awk '{print $2}' | cut -d '/' -f 1"
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
output = p.communicate()[0]
return output[:-1]
#________________________________________________________________________________________
#________________________________________________________________________________________
# ____ __ __ __
# / __ )____ ____ / /_ / / / /___ _
# / __ / __ \/ __ \/ __/_____/ / / / __ \ (_)
# / /_/ / /_/ / /_/ / /_/_____/ /_/ / /_/ / _
#/_____/\____/\____/\__/ \____/ .___/ (_)
# /_/
#
signal.signal(signal.SIGTERM, sigterm_handler)
if StandbyActive == True and firstStart == True:
StandByListen = threading.Thread(target=StandByWatcher, daemon=True)
StandByListen.start()
if ledActive != True:
firstStart = False
GetIP()
#________________________________________________________________________________________
#________________________________________________________________________________________
#
# ____ _ __ __ __ __ __
# / __ \(_)________ / /___ ___ __ / / / /___ ____/ /___ _/ /____ _
# / / / / / ___/ __ \/ / __ `/ / / /_____/ / / / __ \/ __ / __ `/ __/ _ \ (_)
# / /_/ / (__ ) /_/ / / /_/ / /_/ /_____/ /_/ / /_/ / /_/ / /_/ / /_/ __/ _
#/_____/_/____/ .___/_/\__,_/\__, / \____/ .___/\__,_/\__,_/\__/\___/ (_)
# /_/ /____/ /_/
#
def display_update_service():
while UPDATE_INTERVAL > 0 and oled.ShutdownFlag == False:
prevTime = time()
dt = time() - prevTime
if oled.stateTimeout > 0:
oled.timeOutRunning = True
oled.stateTimeout -= dt
elif oled.stateTimeout <= 0 and oled.timeOutRunning:
oled.timeOutRunning = False
oled.stateTimeout = 0
SetState(STATE_PLAYER)
image.paste("black", [0, 0, image.size[0], image.size[1]])
try:
oled.modal.DrawOn(image)
except AttributeError:
print("render error")
sleep(1)
cimg = image.crop((0, 0, oled.WIDTH, oled.HEIGHT))
oled.display(cimg)
sleep(UPDATE_INTERVAL)
#________________________________________________________________________________________
#________________________________________________________________________________________
#
# ____ __ _ __ _
# / __ \/ /_ (_)__ _____/ /( )_____ _
# / / / / __ \ / / _ \/ ___/ __/// ___/ (_)
#/ /_/ / /_/ / / / __/ /__/ /_ (__ ) _
#\____/_.___/_/ /\___/\___/\__/ /____/ (_)
# /___/
#
def SetState(status):
oled.state = status
if oled.state == STATE_PLAYER:
oled.modal = NowPlayingScreen(oled.HEIGHT, oled.WIDTH)
elif oled.state == STATE_QUEUE_MENU:
oled.modal = MenuScreen(oled.HEIGHT, oled.WIDTH)
elif oled.state == STATE_LIBRARY_INFO:
oled.modal = MediaLibrarayInfo(oled.HEIGHT, oled.WIDTH)
elif oled.state == STATE_SCREEN_MENU:
oled.modal = ScreenSelectMenu(oled.HEIGHT, oled.WIDTH)
#________________________________________________________________________________________
#________________________________________________________________________________________
#
# ____ __ __ __ ____
# / __ \____ _/ /_____ _ / / / /___ _____ ____/ / /__ _____ _
# / / / / __ `/ __/ __ `/_____/ /_/ / __ `/ __ \/ __ / / _ \/ ___/ (_)
# / /_/ / /_/ / /_/ /_/ /_____/ __ / /_/ / / / / /_/ / / __/ / _
#/_____/\__,_/\__/\__,_/ /_/ /_/\__,_/_/ /_/\__,_/_/\___/_/ (_)
#
def JPGPathfinder(String):
print('JPGPathfinder')
albumstring = String
global FullJPGPath
try:
p1 = 'path=(.+?)&metadata'
result = re.search(p1, albumstring)
URL = result.group(1)
URLPath = "/mnt" + URL + '/'
accepted_extensions = ['jpg', 'jpeg', 'gif', 'png', 'bmp']
filenames = [fn for fn in os.listdir(URLPath) if fn.split(".")[-1] in accepted_extensions]
JPGName = filenames[0]
FullJPGPath = URLPath + JPGName
except:
FullJPGPath = '/home/volumio/NR1-UI/NoCover.bmp'
JPGSave(FullJPGPath)
print('FullJPGPath: ', FullJPGPath)
def JPGSave(Path):
print('JPGSave')
FullJPGPath = Path
img = Image.open(FullJPGPath) # puts our image to the buffer of the PIL.Image object
width, height = img.size
asp_rat = width/height
new_width = 90
new_height = 90
new_rat = new_width/new_height
img = img.resize((new_width, new_height), Image.ANTIALIAS)
img.save('/home/volumio/album.bmp')
def JPGSaveURL(link):
print('JPGSaveURL')
try:
httpLink = urllib.parse.quote(link).replace('%3A',':')
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(httpLink, context=ctx) as url:
with open('temp.jpg', 'wb') as f:
f.write(url.read())
img = Image.open('temp.jpg')
except:
img = Image.open('/home/volumio/NR1-UI/NoCover.bmp')
width, height = img.size
asp_rat = width/height
new_width = 90
new_height = 90
new_rat = new_width/new_height
img = img.resize((new_width, new_height), Image.ANTIALIAS)
img.save('/home/volumio/album.bmp')
def onPushState(data):
if oled.state != 3:
global OPDsave
global newStatus #global definition for newStatus, used at the end-loop to update standby
global newSong
global newArtist
global newFormat
global varcanc
global secvar
global ScrollArtistTag
global ScrollArtistNext
global ScrollArtistFirstRound
global ScrollArtistNextRound
global ScrollSongTag
global ScrollSongNext
global ScrollSongFirstRound
global ScrollSongNextRound
global ScrollAlbumTag
global ScrollAlbumNext
global ScrollAlbumFirstRound
global ScrollAlbumNextRound
global ScrollSpecsTag
global ScrollSpecsNext
global ScrollSpecsFirstRound
global ScrollSpecsNextRound
OPDsave = data
#print('data: ', str(data).encode('utf-8'))
if 'title' in data:
newSong = data['title']
else:
newSong = ''
if newSong is None:
newSong = ''
if newSong == 'HiFiBerry ADC':
newSong = 'Bluetooth-Audio'
if 'artist' in data:
newArtist = data['artist']
else:
newArtist = ''
if newArtist is None and newSong != 'HiFiBerry ADC': #volumio can push NoneType
newArtist = ''
if newArtist == '' and newSong == 'HiFiBerry ADC':
newArtist = 'Line-Input:'
if 'trackType' in data:
newFormat = data['trackType']
oled.activeFormat = newFormat
else:
newFormat = ''
if newFormat is None:
newFormat = ''
if newFormat == True and newSong != 'HiFiBerry ADC':
newFormat = 'WebRadio'
oled.activeFormat = newFormat
if newFormat == True and newSong == 'HiFiBerry ADC':
newFormat = 'Live-Stream'
oled.activeFormat = newFormat
if 'samplerate' in data:
newSamplerate = data['samplerate']
oled.activeSamplerate = newSamplerate
else:
newSamplerate = ' '
oled.activeSamplerate = newSamplerate
if newSamplerate is None:
newSamplerate = ' '
oled.activeSamplerate = newSamplerate
if 'bitrate' in data:
oled.bitrate = data['bitrate']
else:
bitrate = ''
if oled.bitrate is None:
oled.bitrate = ''
if 'bitdepth' in data:
newBitdepth = data['bitdepth']
oled.activeBitdepth = newBitdepth
else:
newBitdepth = ' '
oled.activeBitdepth = newBitdepth
if newBitdepth is None:
newBitdepth = ' '
oled.activeBitdepth = newBitdepth
if 'position' in data: # current position in queue
oled.playPosition = data['position'] # didn't work well with volumio ver. < 2.5
else:
oled.playPosition = None
if 'status' in data:
newStatus = data['status']
if 'volume' in data: #get volume on startup and remote control
oled.volume = int(data['volume'])
else:
oled.volume = 100
if 'repeat' in data:
oled.repeat = data['repeat']
if 'repeatSingle' in data:
oled.repeatonce = data['repeatSingle']
if 'random' in data:
oled.shuffle = data['random']
if 'mute' in data:
oled.mute = data['mute']
if ledActive == True and 'channels' in data:
channels = data['channels']
if newStatus != 'stop':
if channels == 2:
StereoLEDon()
else:
StereoLEDoff()
if newStatus == 'stop':
StereoLEDoff()
if 'duration' in data:
oled.duration = data['duration']
else:
oled.duration = None
if oled.duration == int(0):
oled.duration = None
if 'seek' in data:
oled.seek = data['seek']
else:
oled.seek = None
if NR1UIRemoteActive == True:
if 'albumart' in data:
newAlbumart = data['albumart']
else:
newAlbumart = None
if newAlbumart is None:
newAlbumart = 'nothing'
AlbumArtHTTP = newAlbumart.startswith('http')
if 'album' in data:
newAlbum = data['album']
else:
newAlbum = None
if newAlbum is None:
newAlbum = 'No Album'
if newAlbum == '':
newAlbum = 'No Album'
if (newSong != oled.activeSong) or (newArtist != oled.activeArtist) or (newAlbum != oled.activeAlbum): # new song and artist
oled.activeSong = newSong
oled.activeArtist = newArtist
oled.activeAlbum = newAlbum
varcanc = True #helper for pause -> stop timeout counter
secvar = 0.0
ScrollArtistTag = 0
ScrollArtistNext = 0
ScrollArtistFirstRound = True
ScrollArtistNextRound = False
ScrollSongTag = 0
ScrollSongNext = 0
ScrollSongFirstRound = True
ScrollSongNextRound = False
ScrollAlbumTag = 0
ScrollAlbumNext = 0
ScrollAlbumFirstRound = True
ScrollAlbumNextRound = False
ScrollSpecsTag = 0
ScrollSpecsNext = 0
ScrollSpecsFirstRound = True
ScrollSpecsNextRound = False
if oled.state == STATE_PLAYER and newStatus != 'stop': #this is the "NowPlayingScreen"
if ledActive == True:
PlayLEDon()
oled.modal.UpdatePlayingInfo() #here is defined which "data" should be displayed in the class
if oled.state == STATE_PLAYER and newStatus == 'stop': #this is the "Standby-Screen"
if ledActive == True:
PlayLEDoff()
StereoLEDoff()
if newStatus != oled.playState:
varcanc = True #helper for pause -> stop timeout counter
secvar = 0.0
oled.playState = newStatus
if oled.state == STATE_PLAYER:
if oled.playState != 'stop':
if newStatus == 'pause':
if ledActive == True:
PlayLEDoff()
oled.playstateIcon = oledpauseIcon
if newStatus == 'play':
if ledActive == True:
PlayLEDon()
oled.playstateIcon = oledplayIcon
oled.modal.UpdatePlayingInfo()
else:
if ledActive == True:
PlayLEDoff()
StereoLEDoff()
ScrollArtistTag = 0
ScrollArtistNext = 0
ScrollArtistFirstRound = True
ScrollArtistNextRound = False
ScrollSongTag = 0
ScrollSongNext = 0
ScrollSongFirstRound = True
ScrollSongNextRound = False
SetState(STATE_PLAYER)
oled.modal.UpdateStandbyInfo()
if NR1UIRemoteActive == True:
if newAlbumart != oled.activeAlbumart:
oled.activeAlbumart = newAlbumart
if AlbumArtHTTP is True and newFormat == 'WebRadio':
JPGSaveURL(newAlbumart)
else:
albumdecode = urllib.parse.unquote(newAlbumart, encoding='utf-8', errors='replace')
JPGPathfinder(albumdecode)
def onPushCollectionStats(data):
data = json.loads(data.decode("utf-8")) #data import from REST-API (is set when ButtonD short-pressed in Standby)
if "artists" in data: #used for Media-Library-Infoscreen
newArtists = data["artists"]
else:
newArtists = ''
if newArtists is None:
newArtists = ''
if 'albums' in data: #used for Media-Library-Infoscreen
newAlbums = data["albums"]
else:
newAlbums = ''
if newAlbums is None:
newAlbums = ''
if 'songs' in data: #used for Media-Library-Infoscreen
newSongs = data["songs"]
else:
newSongs = ''
if newSongs is None:
newSongs = ''
if 'playtime' in data: #used for Media-Library-Infoscreen
newPlaytime = data["playtime"]
else:
newPlaytime = ''
if newPlaytime is None:
newPlaytime = ''
oled.activeArtists = str(newArtists)
oled.activeAlbums = str(newAlbums)
oled.activeSongs = str(newSongs)
oled.activePlaytime = str(newPlaytime)
if oled.state == STATE_LIBRARY_INFO and oled.playState == 'info': #this is the "Media-Library-Info-Screen"
oled.modal.UpdateLibraryInfo()
def onPushQueue(data):
oled.queue = [track['name'] if 'name' in track else 'no track' for track in data]
#________________________________________________________________________________________
#________________________________________________________________________________________
#
# ____ _ __ __ ___ _
# / __ \(_)________ / /___ ___ __ / |/ /__ ____ __ _( )_____ _
# / / / / / ___/ __ \/ / __ `/ / / /_____/ /|_/ / _ \/ __ \/ / / /// ___/ (_)
# / /_/ / (__ ) /_/ / / /_/ / /_/ /_____/ / / / __/ / / / /_/ / (__ ) _
#/_____/_/____/ .___/_/\__,_/\__, / /_/ /_/\___/_/ /_/\__,_/ /____/ (_)
# /_/ /____/
#
class NowPlayingScreen():
def __init__(self, height, width):
self.height = height
self.width = width
def UpdatePlayingInfo(self):
if DisplayTechnology != 'i2c1306':
self.image = Image.new('RGB', (self.width, self.height))
self.draw = ImageDraw.Draw(self.image)
if DisplayTechnology == 'i2c1306':
self.image = Image.new('1', (self.width, self.height))
self.draw = ImageDraw.Draw(self.image)
def UpdateStandbyInfo(self):
if DisplayTechnology != 'i2c1306':
self.image = Image.new('RGB', (self.width, self.height))
self.draw = ImageDraw.Draw(self.image)
if DisplayTechnology == 'i2c1306':
self.image = Image.new('1', (self.width, self.height))
self.draw = ImageDraw.Draw(self.image)
def DrawOn(self, image):
global ScrollArtistTag
global ScrollArtistNext
global ScrollArtistFirstRound
global ScrollArtistNextRound
global ScrollSongTag
global ScrollSongNext
global ScrollSongFirstRound
global ScrollSongNextRound
global ScrollAlbumTag
global ScrollAlbumNext
global ScrollAlbumFirstRound
global ScrollAlbumNextRound
#__________________________________________________________________________________________________________
# _ ___________ ___ __ __
# _________ (_) < /__ /__ \|__ \ / / ____ ___ ______ __ __/ /______
# / ___/ __ \/ / / / /_ <__/ /__/ / / / / __ `/ / / / __ \/ / / / __/ ___/
# (__ ) /_/ / / / /___/ / __// __/ / /___/ /_/ / /_/ / /_/ / /_/ / /_(__ )
#/____/ .___/_/ /_//____/____/____/ /_____/\__,_/\__, /\____/\__,_/\__/____/
# /_/ /____/
#__________________________________________________________________________________________________________
if NowPlayingLayout == 'Spectrum-Center' and newStatus != 'stop' and DisplayTechnology == 'spi1322':
if newStatus != 'stop' and oled.duration != None:
self.image.paste(('black'), [0, 0, image.size[0], image.size[1]])
cava_fifo = open("/tmp/cava_fifo", 'r')
data = cava_fifo.readline().strip().split(';')
self.ArtistWidth, self.ArtistHeight = self.draw.textsize(oled.activeArtist, font=font)
self.ArtistStopPosition = self.ArtistWidth - self.width + ArtistEndScrollMargin
if self.ArtistWidth >= self.width:
if ScrollArtistFirstRound == True:
ScrollArtistFirstRound = False
ScrollArtistTag = 0
self.ArtistPosition = (Screen2text01)
elif ScrollArtistFirstRound == False and ScrollArtistNextRound == False:
if ScrollArtistTag <= self.ArtistWidth - 1:
ScrollArtistTag += ArtistScrollSpeed
self.ArtistPosition = (-ScrollArtistTag ,Screen2text01[1])
ScrollArtistNext = 0
elif ScrollArtistTag == self.ArtistWidth:
ScrollArtistTag = 0
ScrollArtistNextRound = True
ScrollArtistNext = self.width + ArtistEndScrollMargin
if ScrollArtistNextRound == True:
if ScrollArtistNext >= 0:
self.ArtistPosition = (ScrollArtistNext ,Screen2text01[1])
ScrollArtistNext -= ArtistScrollSpeed
elif ScrollArtistNext == -ArtistScrollSpeed and ScrollArtistNextRound == True:
ScrollArtistNext = 0
ScrollArtistNextRound = False
ScrollArtistFirstRound = False
ScrollArtistTag = 0
self.ArtistPosition = (Screen2text01)
if self.ArtistWidth <= self.width: # center text
self.ArtistPosition = (int((self.width-self.ArtistWidth)/2), Screen2text01[1])
self.draw.text((self.ArtistPosition), oled.activeArtist, font=font, fill='white')
self.SongWidth, self.SongHeight = self.draw.textsize(oled.activeSong, font=font3)
self.SongStopPosition = self.SongWidth - self.width + SongEndScrollMargin
if self.SongWidth >= self.width:
if ScrollSongFirstRound == True: