Add LED control.
authorAlexander Koenig <alex@lisas.de>
Wed, 2 Apr 2014 20:53:16 +0000 (20:53 +0000)
committerAlexander Koenig <alex@lisas.de>
Wed, 2 Apr 2014 20:53:16 +0000 (20:53 +0000)
vompilirc.py

index 9e1a48d20ecf24071c2f3dc928a5aeb3ccf5c4c5..085121d0da0b725efd9212d3bcf86f2739c2af91 100755 (executable)
@@ -23,7 +23,7 @@ __author__ = "Alexander K├Ânig"
 __email__ = "alex@lisas.de"
 __license__ = "GPLv2"
 
-import pylirc, time, socket, os, signal, subprocess
+import pylirc, time, socket, os, signal, subprocess, sys
 
 vomp_host = '127.0.0.1'
 vomp_port = 2000
@@ -117,6 +117,24 @@ child_pipe = None
 repeaters = [ VOMP_CHANNELUP, VOMP_CHANNELDOWN ]
 debug = False
 
+def led_off():
+       os.system('echo 0 | sudo tee /sys/class/leds/led0/brightness')
+
+def led_on():
+        os.system('echo 1 | sudo tee /sys/class/leds/led0/brightness')
+
+def set_mode(newmode):
+       global mode
+       if mode != newmode:
+               if newmode == VOMPILIRC_MODE_OFF:
+                       # we switch from either xbmc or vomp to off
+                       led_off()
+               elif mode == VOMPILIRC_MODE_OFF:
+                       # we switch from off to either xbmc or vomp
+                       led_on()
+
+               mode = newmode
+
 def start_vomp():
        global mode
        global child_pipe
@@ -124,7 +142,7 @@ def start_vomp():
        if debug:
                print 'Starting vompclient'
        
-       mode = VOMPILIRC_MODE_VOMP
+       set_mode(VOMPILIRC_MODE_VOMP)
        child_pipe = subprocess.Popen(['vompclient','-n'])
 
 def start_xbmc():
@@ -134,7 +152,7 @@ def start_xbmc():
        if debug:
                print 'Starting XBMC'
        
-       mode = VOMPILIRC_MODE_XBMC
+       set_mode(VOMPILIRC_MODE_XBMC)
        child_pipe = subprocess.Popen(['/usr/lib/xbmc/xbmc.bin', '--standalone'])
 
 
@@ -166,7 +184,7 @@ def stop_child(force_off=False):
                tv_power(off=True)
                
        child_pipe = None
-       mode = VOMPILIRC_MODE_OFF
+       set_mode(VOMPILIRC_MODE_OFF)
 
 def signal_handler(signum, frame):
        if debug: print 'Exiting...'