This repository was archived by the owner on Nov 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsdvx_controller.py
More file actions
65 lines (50 loc) · 1.3 KB
/
Copy pathsdvx_controller.py
File metadata and controls
65 lines (50 loc) · 1.3 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
58
59
60
61
62
63
64
65
#!/usr/bin/python
import RPi.GPIO as GPIO
import signal
import time
import os
import sys
KEY_LIST = {
'V-L1':{'PIN':3,'KEY':'\x14'},#Q
'V-L2':{'PIN':5,'KEY':'\x1a'},#W
'V-R1':{'PIN':35,'KEY':'\x12'},#O
'V-R2':{'PIN':37,'KEY':'\x13'},#P
'BT-A':{'PIN':7,'KEY':'\x07'},#D
'BT-B':{'PIN':11,'KEY':'\x09'},#F
'BT-C':{'PIN':31,'KEY':'\x0d'},#J
'BT-D':{'PIN':33,'KEY':'\x0e'},#K
'FX-L':{'PIN':13,'KEY':'\x0a'},#G
'FX-R':{'PIN':29,'KEY':'\x0b'},#H
'START':{'PIN':15,'KEY':'\x28'},#ENTER
}
f = open("/dev/hidg0","w")
keycode_tmp = "\x00" * 2
def POW(PIN):
GPIO.remove_event_detect(PIN)
os.system('sync;poweroff')
clear(0,0)
def clear(signal,frame):
f.write("\x00" * 8)
f.close()
GPIO.cleanup()
exit()
signal.signal(signal.SIGINT,clear)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
for P in KEY_LIST.keys():
GPIO.setup(KEY_LIST[P]['PIN'],GPIO.IN,pull_up_down=GPIO.PUD_UP)
if sys.argv[1:2] == ['headless']:
RUN = 40
GPIO.setup(RUN,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(RUN,GPIO.FALLING,callback=POW,bouncetime=1000)
while 1:
ks = "\x00" * 2
for K in KEY_LIST.keys():
if GPIO.input(KEY_LIST[K]['PIN']) is GPIO.LOW:
ks += KEY_LIST[K]['KEY']
if keycode_tmp != ks:
keycode_tmp = ks
keycode = ks + "\x00" * ( 8 - len(ks))
f.write(keycode[0:8])
f.flush()
time.sleep(0.01)