commit
530c940962
@ -0,0 +1,17 @@ |
||||
{ |
||||
// Use IntelliSense to learn about possible attributes. |
||||
// Hover to view descriptions of existing attributes. |
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
||||
"version": "0.2.0", |
||||
"configurations": [ |
||||
{ |
||||
"name": "Python: Current File", |
||||
"type": "python", |
||||
"request": "launch", |
||||
"program": "${file}", |
||||
//"args": ["/dev/input/event6"], |
||||
"args": ["/dev/input/event6"], |
||||
"console": "integratedTerminal" |
||||
} |
||||
] |
||||
} |
@ -0,0 +1,156 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
# |
||||
# pycontroller.py |
||||
# Reading a USB gamepad & making sense of it ... |
||||
# |
||||
#----------------------------------------------------------------------- |
||||
# lsusb ouput: Bus 002 Device 003: ID 0079:0011 DragonRise Inc. Gamepad |
||||
# input device: /dev/input/event6 |
||||
# |
||||
# Program output (needs to be inspected w/ each new controller): |
||||
# -------------------------------------------------------------- |
||||
# Input driver version is 1.0.1 |
||||
# Input device ID: bus 0x3 vendor 0x79 product 0x11 version 0x110 |
||||
# Input device name: USB Gamepad |
||||
# Supported events: |
||||
# Event type 0 (EV_SYN) |
||||
# Event code 0 (SYN_REPORT) |
||||
# Event code 1 (SYN_CONFIG) |
||||
# Event code 2 (SYN_MT_REPORT) |
||||
# Event code 3 (SYN_DROPPED) |
||||
# Event code 4 (SYN_04) |
||||
# Event code 5 (SYN_05) |
||||
# Event code 6 (SYN_06) |
||||
# Event code 7 (SYN_07) |
||||
# Event code 8 (SYN_08) |
||||
# Event code 9 (SYN_09) |
||||
# Event code 10 (SYN_0A) |
||||
# Event code 11 (SYN_0B) |
||||
# Event code 12 (SYN_0C) |
||||
# Event code 13 (SYN_0D) |
||||
# Event code 14 (SYN_0E) |
||||
# Event code 15 (SYN_MAX) |
||||
# Event type 1 (EV_KEY) |
||||
# Event code 288 (BTN_TRIGGER) <- 1=[Blue/X] |
||||
# Event code 289 (BTN_THUMB) <- 1=[Red/A] |
||||
# Event code 290 (BTN_THUMB2) <- 1=[Yellow/B] |
||||
# Event code 291 (BTN_TOP) <- 1=[Green/Y] |
||||
# Event code 292 (BTN_TOP2) <- 1=[Frontal left] |
||||
# Event code 293 (BTN_PINKIE) <- 1=[Frontal right] |
||||
# Event code 294 (BTN_BASE) |
||||
# Event code 295 (BTN_BASE2) |
||||
# Event code 296 (BTN_BASE3) <- 1=[Centre left] |
||||
# Event code 297 (BTN_BASE4) <- 1=[Centre right] |
||||
# Event type 3 (EV_ABS) |
||||
# Event code 0 (ABS_X) <- Cross: 127=Neutral, 0=[Left], 255=[Right] |
||||
# Value 127 |
||||
# Minimum 0 |
||||
# Maximum 255 |
||||
# Fuzz 0 |
||||
# Flat 15 |
||||
# Resolution 0 |
||||
# Event code 1 (ABS_Y) <- Cross: 127=Neutral, 0=[Top], 255=[Down] |
||||
# Value 127 |
||||
# Minimum 0 |
||||
# Maximum 255 |
||||
# Fuzz 0 |
||||
# Flat 15 |
||||
# Resolution 0 |
||||
# Event type 4 (EV_MSC) |
||||
# Event code 4 (MSC_SCAN) |
||||
# Properties: |
||||
#----------------------------------------------------------------------- |
||||
|
||||
import sys |
||||
import libevdev |
||||
|
||||
def print_capabilities(l): |
||||
v = l.driver_version |
||||
print("Input driver version is {}.{}.{}".format(v >> 16, (v >> 8) & 0xff, v & 0xff)) |
||||
id = l.id |
||||
print("Input device ID: bus {:#x} vendor {:#x} product {:#x} version {:#x}".format( |
||||
id["bustype"], |
||||
id["vendor"], |
||||
id["product"], |
||||
id["version"], |
||||
)) |
||||
print("Input device name: {}".format(l.name)) |
||||
print("Supported events:") |
||||
|
||||
for t, cs in l.evbits.items(): |
||||
print(" Event type {} ({})".format(t.value, t.name)) |
||||
|
||||
for c in cs: |
||||
if t in [libevdev.EV_LED, libevdev.EV_SND, libevdev.EV_SW]: |
||||
v = l.value[c] |
||||
print(" Event code {} ({}) state {}".format(c.value, c.name, v)) |
||||
else: |
||||
print(" Event code {} ({})".format(c.value, c.name)) |
||||
|
||||
if t == libevdev.EV_ABS: |
||||
a = l.absinfo[c] |
||||
print(" {:10s} {:6d}".format('Value', a.value)) |
||||
print(" {:10s} {:6d}".format('Minimum', a.minimum)) |
||||
print(" {:10s} {:6d}".format('Maximum', a.maximum)) |
||||
print(" {:10s} {:6d}".format('Fuzz', a.fuzz)) |
||||
print(" {:10s} {:6d}".format('Flat', a.flat)) |
||||
print(" {:10s} {:6d}".format('Resolution', a.resolution)) |
||||
|
||||
print("Properties:") |
||||
for p in l.properties: |
||||
print(" Property type {} ({})".format(p.value, p.name)) |
||||
|
||||
|
||||
def print_event(e): |
||||
print("Event: time {}.{:06d}, ".format(e.sec, e.usec), end='') |
||||
if e.matches(libevdev.EV_SYN): |
||||
if e.matches(libevdev.EV_SYN.SYN_MT_REPORT): |
||||
print("++++++++++++++ {} ++++++++++++".format(e.code.name)) |
||||
elif e.matches(libevdev.EV_SYN.SYN_DROPPED): |
||||
print(">>>>>>>>>>>>>> {} >>>>>>>>>>>>".format(e.code.name)) |
||||
else: |
||||
print("-------------- {} ------------".format(e.code.name)) |
||||
else: |
||||
print("type {:02x} {} code {:03x} {:20s} value {:4d}".format(e.type.value, e.type.name, e.code.value, e.code.name, e.value)) |
||||
|
||||
|
||||
def main(args): |
||||
path = args[1] |
||||
try: |
||||
with open(path, "rb") as fd: |
||||
dev = libevdev.Device(fd) |
||||
print_capabilities(dev) |
||||
print("################################\n" |
||||
"# Waiting for events #\n" |
||||
"# Press [Center right] to exit #\n" |
||||
"################################") |
||||
|
||||
while True: |
||||
try: |
||||
for e in dev.events(): |
||||
print_event(e) |
||||
if (e.code.name == "BTN_BASE4") and (e.value == 1): |
||||
return |
||||
except libevdev.EventsDroppedException: |
||||
print("Dropped!") |
||||
for e in dev.sync(): |
||||
print_event(e) |
||||
|
||||
except KeyboardInterrupt: |
||||
pass |
||||
except IOError as e: |
||||
import errno |
||||
if e.errno == errno.EACCES: |
||||
print("Insufficient permissions to access {}".format(path)) |
||||
elif e.errno == errno.ENOENT: |
||||
print("Device {} does not exist".format(path)) |
||||
else: |
||||
raise e |
||||
|
||||
|
||||
if __name__ == "__main__": |
||||
if len(sys.argv) < 2: |
||||
print("Usage: {} /dev/input/eventX".format(sys.argv[0])) |
||||
sys.exit(1) |
||||
main(sys.argv) |
Loading…
Reference in new issue