Skip to content

Instantly share code, notes, and snippets.

@bmsleight
Created September 8, 2016 22:22
Show Gist options
  • Save bmsleight/b6731b81d4ad2ee011544f65ae98c3d5 to your computer and use it in GitHub Desktop.
Save bmsleight/b6731b81d4ad2ee011544f65ae98c3d5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import evdev
import time
import subprocess
# gatttool -i hci0 -b E0:E5:CF:AD:71:A0 --char-write-req -a 0x0043 -n cc2333 #on
# gatttool -i hci0 -b E0:E5:CF:AD:71:A0 --char-write-req -a 0x0043 -n cc2433 #on
def lamp(light):
if light:
cmd = "/usr/bin/gatttool -i hci0 -b E0:E5:CF:AD:71:A0 --char-write-req -a 0x0043 -n cc2333"
else:
cmd = "/usr/bin/gatttool -i hci0 -b E0:E5:CF:AD:71:A0 --char-write-req -a 0x0043 -n cc2433"
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
while True:
try:
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
toggle = True
for device in devices:
if device.name == 'AB Shutter 3':
for event in device.read_loop():
if event.type == evdev.ecodes.EV_KEY:
print (evdev.categorize(event).keystate)
if evdev.categorize(event).keystate == 0:
if evdev.categorize(event).keycode == "KEY_VOLUMEUP":
if toggle:
print ("On, now off")
else:
print ("Off, no on")
lamp(toggle)
toggle = not toggle
print "UP"
except:
# Bluetooth has goen to sleep ?
pass
time.sleep(1)
# pass
# if event.type == evdev.ecodes.EV_KEY && event.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment