aboutsummaryrefslogtreecommitdiff
path: root/inputdev_describe
blob: 37fd3dde1d5c8d1743162935f2ace6b4e165ce73 (plain)
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
#!/usr/bin/python3

import argparse
import contextlib
import evdev
import json
import sys

parser = argparse.ArgumentParser()

parser.add_argument('device')

args = parser.parse_args(sys.argv[1:])

with contextlib.closing(evdev.InputDevice(args.device)) as device:
    out = {}

    out['linux-evdev-device-desc'] = 0

    out['name'] = device.name

    info = {}
    info['bustype'] = device.info.bustype
    info['vendor']  = device.info.vendor
    info['product'] = device.info.product
    info['version'] = device.info.version
    out['info'] = info

    caps = {}
    for t, l in device.capabilities().items():
        if t == evdev.ecodes.EV_SYN:
            continue
        caps[t] = l
    out['capabilities'] = caps

    # TODO: LEDs

    json.dump(out, sys.stdout, indent = 4)