Commit 06412991 authored by Daniel STAN's avatar Daniel STAN

remote: stdin est aussi un input possible

parent c0a0ee7b
......@@ -4,6 +4,8 @@ import dbus
from subprocess import call
import requests
import collections
import select
import sys
SERIALPORT = "/dev/ttyUSB0"
BAUDRATE = 9600
......@@ -33,47 +35,42 @@ spotify = dbus.Interface(proxy, dbus_interface='org.mpris.MediaPlayer2.Player')
def volume(p):
call(["amixer", "-D", "pulse", "sset", "Master", p])
# Light control
def light_old(p):
x = requests.get('http://gladys.home:8000/domo/')
y = requests.post('http://gladys.home:8000/domo/enable/',
data={'num': str(p), 'csrfmiddlewaretoken': x.cookies['csrftoken']},
cookies={'csrftoken': x.cookies['csrftoken']},
)
if y.status_code != 200:
raise Exception("Bad http result %d " % y.status_code)
_states = collections.defaultdict(bool)
def light(p):
"""Light control"""
p = str(p)
ser.write("%s%s;" % ('f' if _states[p] else 'o', p))
ser.flush()
_states[p] = not _states[p]
def process_line(response):
if response.startswith(CONTROL):
key = response[len(CONTROL):].strip().lower()
print key
if key == 'pause':
spotify.PlayPause()
elif key == 'prev':
spotify.Previous()
elif key == 'next':
spotify.Next()
elif key == 'vol+':
volume('10%+')
elif key == 'vol-':
volume('10%-')
else:
try:
ikey = int(key)
except ValueError:
ikey = None
if ikey and ikey in xrange(1,5):
light(ikey)
if ser.isOpen():
try:
while True:
response = ser.readline()
if response.startswith(CONTROL):
key = response[len(CONTROL):].strip().lower()
print key
if key == 'pause':
spotify.PlayPause()
elif key == 'prev':
spotify.Previous()
elif key == 'next':
spotify.Next()
elif key == 'vol+':
volume('10%+')
elif key == 'vol-':
volume('10%-')
else:
try:
ikey = int(key)
except ValueError:
ikey = None
if ikey and ikey in xrange(1,5):
light(ikey)
todo, _, _ = select.select([ser, sys.stdin], [], [])
for sock in todo:
process_line(sock.readline())
ser.close()
except Exception as e:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment