changeset 478:c7534a417c6d

read and send some HID events. might be working Ignore-this: 38af5a3d964d010176b0fb1e922a04db
author drewp@bigasterisk.com
date Sat, 20 Apr 2019 23:56:57 -0700
parents 498f5cc6fc33
children 9ab114450284
files service/bluetoothButtons/bluetooth_buttons.py
diffstat 1 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/service/bluetoothButtons/bluetooth_buttons.py	Sat Apr 20 23:56:57 2019 -0700
@@ -0,0 +1,26 @@
+import hidraw
+import os
+import requests
+import json
+
+fileno = os.open('/dev/hidraw0', os.O_RDWR)
+h = hidraw.HIDRaw(fileno)
+
+keys = {
+    b'\x02\xb6\x00': 'left',
+    b'\x02\xe9\x00': 'top',
+    b'\x02\xb5\x00': 'right',
+    b'\x02\xcd\x00': 'middle',
+}
+
+while True:
+    buf = os.read(fileno, 16)
+    print('got %r' % buf)
+    addr = h.getPhysicalAddress().decode('ascii')
+
+    if buf in keys:
+        msg = {'addr': addr, 'key': keys[buf]}
+        print(msg)
+        requests.post('http://bang6:10011/bluetoothButton',
+                      data=json.dumps(msg))
+# to use port 10014