-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunMe.py
executable file
·150 lines (113 loc) · 3.86 KB
/
runMe.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
#!/usr/bin/python3
"""This software is designed to be used with :
- a Raspberry PI
- an Audio Amp, driven with a relay
- a LCD Screen (ILI9341 or 40, 320x240) on SPI
- KODI running on the PI
- an USB IR Remonte controller, which should return decoded events on /dev/hidrawX
(This part should be easily changed, by modifying the Hardware.py file...)
The POWER key of the remote would turn on the AMP and the LCD Screen.
Volume keys would ...change the volume !
The MUSIC, MOVIES, TV keys would select which audio source should be selected...
The SETTINGS key would enter a main menu, allowing to change the balance, fader, subwoofer settings...
While in the SETTINGS menu, no key-presses are transmitted to KODI,
while outside the settings menu, ARROWS, ESC and OK keys are transmitted to KODI
LGTV IP should be set on line :
webos_client = WebOsClient('192.168.0.112')
Install dependencies with :
sudo apt-get install python3-numpy python3-pil
Install SPI :
in /boot/config.txt, ensure that dtparam=spi=on is not commented.
DETECTION D'un CD/DVD : blkid /dev/sr0
"""
import time
import threading
import mpd
import libs.config
from libs.hardware import *
from libs.lcd import LCD
from libs.settings import *
from pylgtv import WebOsClient
from libs.ping import Ping
LGTVIP = '192.168.0.112'
webosClient = WebOsClient(LGTVIP)
# Global variables
lastRefreshTime = time.clock()
isInMenu = False
# End Global variables
# Instanciate Hardware controller Class
hw = Hardware()
sets = Settings()
# Init the LCD Object with a reference to hw object reference
lcd = LCD(sets)
def changeVolume(newVolume):
global hw
"""This function is used to change the volume (by calling the method of the HARDWARE object.)
It shows the VOLUME screen (big number on LCD) and then go back to the previous screen.
"""
sets.setVolume(newVolume)
lcd.setNewDisplayFunction("showVolume")
threading.Timer(3, lcd.setPreviousDisplayFunction).start()
# Define a timer to reset LCD Brightness
LCDBrightTimer = threading.Timer(3, hw.setLCDBrightIdle)
# Define a MPD client :
mpdClient = mpd.MPDClient(use_unicode=True)
mpdClient.connect("localhost", 6600)
#
# Main loop :
#
while True:
# Display the screen if we passed more than 0.1 s (= 10 fps)
# We cannot do better than 10 fps with python LCD driving...
# We could do better with FBTFT driver....
if (time.clock() + 0.1) > lastRefreshTime :
lastRefreshTime = time.clock()
lcd.doDisplay()
# Handle Input events :
eventName=hw.handleInputEvents()
if eventName != "":
print ("Recognized event : " + eventName)
if eventName == "POWER":
if hw.isPoweredOn == True:
hw.setPowerOff()
lcd.setNewDisplayFunction("showClock")
LCDBrightTimer.cancel()
pass
else:
hw.setPowerOn()
lcd.setNewDisplayFunction("showMainScreen")
pass
if hw.isPoweredOn == True:
# Set LCD Bright for 3 seconds
hw.setLCDBrightPower()
# Reset the current timer if yet possible...
LCDBrightTimer.cancel()
# Define a timer to reset LCD Brightness
LCDBrightTimer = threading.Timer(3, hw.setLCDBrightIdle)
LCDBrightTimer.start()
# Only handle actions if we are powered-on !
if eventName == "VOL_UP":
curVolume=sets.getVolume()
if curVolume<32 :
curVolume+=1
changeVolume(curVolume)
if eventName == "VOL_DN":
curVolume=sets.getVolume()
if curVolume>0 :
curVolume-=1
changeVolume(curVolume)
if eventName == "MUSIC":
if sets.getAudioSource != eventName :
sets.setAudioSource(eventName)
if isInMenu == False :
if eventName == "KEY_LEFT" :
hw.sendKey("")
else:
kodirpc.kodiSendKey(eventName)
# Check if MPD has changed state (STOPPED/PAUSED > Playing)
# if it did, we turn on and change to MUSIC source
# Check if TV is alive and source is Live TV.
# if it is, we turn on and change to TV source
if (Ping(LGTVIP)):
print(webosClient.get_input())
time.sleep(0.05)