forked from techdiem/RasPi-OLED-Menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholed.py
61 lines (54 loc) · 2.37 KB
/
oled.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
import platform
print("Starting OLED display on", platform.node(), ":")
print()
#Only avaiable on raspberry pi
try:
from RPi import GPIO
except:
print("This software needs to run on a RasPi, because it uses GPIO pins to communicate with the hardware.")
exit()
import helperFunctions
import threading
from globalParameters import globalParameters
from setupHandler import device, client, shutdown
from time import sleep
import screens.idlescreen
import screens.mainmenu
import screens.playlistmenu
import screens.radiomenu
import screens.shutdownmenu
import screens.emptyscreen
updaterun = threading.Event()
while True:
try:
sleep(0.2)
#Draw active screen to display
if globalParameters.activemenu == 0: screens.idlescreen.draw(device)
elif globalParameters.activemenu == 1: screens.mainmenu.draw(device)
elif globalParameters.activemenu == 2: screens.radiomenu.draw(device)
elif globalParameters.activemenu == 3: screens.shutdownmenu.draw(device)
elif globalParameters.activemenu == 4: screens.playlistmenu.draw(device)
elif globalParameters.activemenu == 5: screens.emptyscreen.draw(device)
#Send trigger event to active screen
if globalParameters.trigger == True:
globalParameters.trigger = False
if globalParameters.activemenu == 0: screens.idlescreen.trigger()
elif globalParameters.activemenu == 1: screens.mainmenu.trigger()
elif globalParameters.activemenu == 2: screens.radiomenu.trigger()
elif globalParameters.activemenu == 3: screens.shutdownmenu.trigger()
elif globalParameters.activemenu == 4: screens.playlistmenu.trigger()
elif globalParameters.activemenu == 5: screens.emptyscreen.trigger(device) #Needs device to turn on screen
#Run update procedure in separate thread
if globalParameters.activemenu != globalParameters.oldactivemenu:
globalParameters.oldactivemenu = globalParameters.activemenu
updaterun.set()
if globalParameters.activemenu == 0:
updaterun.clear()
updateThread = threading.Thread(target=screens.idlescreen.update, args=(updaterun,))
updateThread.start()
sleep(0.2)
except KeyboardInterrupt:
print("Exiting...")
break
updaterun.set() #Stop screen update procedure
shutdown()