-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpiosupport.py
56 lines (50 loc) · 2.07 KB
/
gpiosupport.py
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
import evdev
import select
import requests
CCW = "http://127.0.0.1:14711/commands/rotary-ccw"
CW = "http://127.0.0.1:14711/commands/rotary-cw"
SP = "http://127.0.0.1:14711/commands/start-picture"
CO = "http://127.0.0.1:14711/commands/start-collage"
PR = "http://127.0.0.1:14711/commands/print"
CU = "http://127.0.0.1:14711/commands/start-custom"
RB = "http://127.0.0.1:14711/commands/rotary-btn-press"
SD = "http://127.0.0.1:14711/commands/shutdown-now"
MUSB = "http://127.0.0.1:14711/commands/start-move2usb"
def send_request(url):
try:
response = requests.get(url)
print(f"Request to {url}responded with status code: {response.status_code}")
except requests.RequestException as e:
print(f"Request to {url} failed: {e}")
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
devices = {dev.fd: dev for dev in devices}
value = 1
print("Value: {0}".format(value))
done = False
while not done:
r, w, x = select.select(devices, [], [])
for fd in r:
for event in devices[fd].read():
event = evdev.util.categorize(event)
if isinstance(event, evdev.events.RelEvent):
value = value + event.event.value
print("Value: {0}".format(value))
if event.event.value == 1:
send_request(CW)
elif event.event.value == -1:
send_request(CCW)
elif isinstance(event, evdev.events.KeyEvent):
if event.keycode == "KEY_ENTER" and event.keystate == event.key_up:
send_request(RB)
if event.keycode == "KEY_T" and event.keystate == event.key_up:
send_request(SP)
if event.keycode == "KEY_C" and event.keystate == event.key_up:
send_request(CO)
if event.keycode == "KEY_P" and event.keystate == event.key_up:
send_request(PR)
if event.keycode == "KEY_U" and event.keystate == event.key_up:
send_request(CU)
if event.keycode == "KEY_S" and event.keystate == event.key_up:
send_request(SD)
if event.keycode == "KEY_M" and event.keystate == event.key_up:
send_request(MUSB)