Exemplo n.º 1
0
def create(device):
    evdev = fetch(device, "evdev")

    d = libevdev.Device()
    d.name = fetch(evdev, "name")

    ids = fetch(evdev, "id")
    if len(ids) != 4:
        raise YamlException("Invalid ID format: {}".format(ids))
    d.id = dict(zip(["bustype", "vendor", "product", "version"], ids))

    codes = fetch(evdev, "codes")
    for evtype, evcodes in codes.items():
        for code in evcodes:
            data = None
            if evtype == libevdev.EV_ABS.value:
                values = fetch(evdev, "absinfo")[code]
                absinfo = libevdev.InputAbsInfo(
                    minimum=values[0],
                    maximum=values[1],
                    fuzz=values[2],
                    flat=values[3],
                    resolution=values[4],
                )
                data = absinfo
            elif evtype == libevdev.EV_REP.value:
                if code == libevdev.EV_REP.REP_DELAY.value:
                    data = 500
                elif code == libevdev.EV_REP.REP_PERIOD.value:
                    data = 20
            d.enable(libevdev.evbit(evtype, code), data=data)

    properties = fetch(evdev, "properties")
    for prop in properties:
        d.enable(libevdev.propbit(prop))

    uinput = d.create_uinput_device()

    check_udev_properties(device, uinput)

    return uinput
Exemplo n.º 2
0
    def from_name(cls, name: str, type: str) -> "Device":
        """
        Create a Device from the given name with the given type (pen, pad,
        finger). This method iterates through the test/devices/*.yml files and
        finds the file for the device with the given name, then loads the
        matching event node for that type.
        """
        type = type.lower()
        assert type.lower() in ("pen", "pad", "finger")

        for ymlfile in Path("test/devices").glob("*.yml"):
            with open(ymlfile) as fd:
                yml = yaml.safe_load(fd)
                logger.debug(f"Found device: {yml['name']}")
                if yml["name"].upper() != name.upper():
                    continue

                for d in yml["devices"]:
                    if d["type"] != type:
                        continue

                    name = d["name"]
                    id = InputId.from_list([int(i, 16) for i in d["id"]])
                    bits = [libevdev.evbit(b) for b in d["bits"]]
                    abs = {
                        libevdev.evbit(n): libevdev.InputAbsInfo(*v)
                        for n, v in d["abs"].items()
                    }
                    props = [libevdev.propbit(p) for p in d["props"]]

                    return Device(name=name,
                                  id=id,
                                  bits=bits,
                                  absinfo=abs,
                                  props=props)
                raise ValueError(
                    f"Device '{name}' does not have type '{type}'")

        raise ValueError(f"Device '{name}' does not exist")
Exemplo n.º 3
0
    def test_propbit_string(self):
        self.assertEqual(propbit('INPUT_PROP_POINTER'), libevdev.INPUT_PROP_POINTER)
        self.assertEqual(propbit('INPUT_PROP_DIRECT'), libevdev.INPUT_PROP_DIRECT)

        for p in libevdev.props:
            self.assertEqual(propbit(p.value), p)