-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.py
48 lines (34 loc) · 1.19 KB
/
service.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
import time
import xbmc
import xbmcaddon
triggers = [
'none', # Off
'default-on', # On
'heartbeat', # Heartbeat
]
led_trigger_path = '/sys/class/leds/blue:heartbeat/trigger'
class SettingsMonitor(xbmc.Monitor):
def __init__(self, settings_changed):
xbmc.Monitor.__init__(self)
self._settings_changed_handler = settings_changed
def onSettingsChanged(self):
self._settings_changed_handler()
def set_trigger(trigger):
with open(led_trigger_path, 'w') as t:
t.write(triggers[trigger])
if __name__ == '__main__':
addon = xbmcaddon.Addon()
def update_trigger():
trigger = int(addon.getSetting('trigger'))
if trigger >= len(triggers):
trigger = 0
xbmc.log('Setting trigger to: %s' % triggers[trigger], level=xbmc.LOGDEBUG)
set_trigger(trigger)
monitor = SettingsMonitor(update_trigger)
xbmc.log('Starting ODROID-C2 Led control', level=xbmc.LOGDEBUG)
update_trigger()
# Just wait till Kodi is ready to quit
monitor.waitForAbort()
xbmc.log('Stopping ODROID-C2 Led control, setting trigger back to heartbeat', level=xbmc.LOGDEBUG)
# Set back to default heartbeat
set_trigger(2)