-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkludge.py
More file actions
executable file
·57 lines (52 loc) · 1.83 KB
/
kludge.py
File metadata and controls
executable file
·57 lines (52 loc) · 1.83 KB
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
49
50
51
52
53
54
55
56
57
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3Packages.requests -p xdotool
import requests, json
import subprocess
def transition(source, old, new):
# vim kludge
if source == "sensor-rechts":
if old is None:
return
if old == 0 and new > 0.1:
print("[vim] Insert")
subprocess.run("xdotool key 'i'", shell=True)
elif old > 0 and new == 0:
print("[vim] Exit")
subprocess.run("xdotool key 'Escape'", shell=True)
if source == "sensor-midden":
if old is None:
return
pass
# TODO
# push to talk
if source == "sensor-links":
if old is None:
return
if old == 0 and new > 0.1:
print("[mic] Unmuting")
subproces.run("pacmd suspend-source alsa_input.usb-Blue_Microphones_Yeti_Stereo_Microphone_REV8-00.analog-stereo 0", shell=True)
elif old > 0 and new == 0:
print("[mic] Muting")
subproces.run("pacmd suspend-source alsa_input.usb-Blue_Microphones_Yeti_Stereo_Microphone_REV8-00.analog-stereo 1", shell=True)
url = "http://192.168.100.109/events"
headers = {"Accept": "text/event-stream"}
r = requests.get(url, headers=headers, stream=True)
cmd = None
raw_data = None
states = {}
for line in r.iter_lines():
line = line.decode("utf8")
if line == '':
continue
last_cmd = cmd
last_raw_data = raw_data
cmd, raw_data = line.split(":",1)
raw_data = raw_data.strip()
if last_cmd == "event" and last_raw_data == "state" and cmd == "data":
message = json.loads(raw_data)
source = message["id"]
state = message["value"]
old_state = states.get(message["id"], None)
if old_state != state:
transition(source, old_state, state)
states[source] = state