Skip to content

Commit

Permalink
Apply black
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagocoutinho committed Oct 24, 2023
1 parent 6f0eb5b commit 0863f98
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
43 changes: 32 additions & 11 deletions linuxpy/input/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ def u_set_absolutes(fd, *absolutes: Absolute):


def u_set_miscellaneous(fd, *misc: Miscelaneous):
_u_set_n(fd, UIOC.SET_MSCBIT, misc)
_u_set_n(fd, UIOC.SET_MSCBIT, misc)


def u_set_force_feedback(fd, *ff: ForceFeedback):
_u_set_n(fd, UIOC.SET_FFBIT, ff)
_u_set_n(fd, UIOC.SET_FFBIT, ff)


def u_emit(fd, event_type, event_code, value, syn=True):
Expand All @@ -638,7 +638,14 @@ class BaseUDevice(BaseDevice):
PATH = pathlib.Path("/dev/uinput")
CAPABILITIES = {}

def __init__(self, filename=PATH, bus=Bus.USB, vendor_id=0x01, product_id=0x01, name="linuxpy emulated device"):
def __init__(
self,
filename=PATH,
bus=Bus.USB,
vendor_id=0x01,
product_id=0x01,
name="linuxpy emulated device",
):
# Force write only
super().__init__(filename, read_write="w")
self.bustype = bus
Expand Down Expand Up @@ -673,7 +680,6 @@ def set_capabilities(self, caps: dict):
elif event_type == EventType.FF:
u_set_force_feedback(self.fileno(), *capabilities)


def create(self):
u_device_create(self.fileno())

Expand All @@ -687,23 +693,38 @@ def emit(self, event_type: EventType, event_code: int, value: int, syn=True):
class UMouse(BaseUDevice):
CAPABILITIES = {
EventType.KEY: {Key.BTN_LEFT, Key.BTN_MIDDLE, Key.BTN_RIGHT},
EventType.REL: {Relative.X, Relative.Y}
EventType.REL: {Relative.X, Relative.Y},
}


class UGamepad(BaseUDevice):
CAPABILITIES = {
# EventType.FF: {ForceFeedback.RUMBLE, ForceFeedback.PERIODIC, ForceFeedback.SQUARE, ForceFeedback.TRIANGLE, ForceFeedback.SINE, ForceFeedback.GAIN},
EventType.KEY: {Key.BTN_GAMEPAD, Key.BTN_EAST, Key.BTN_NORTH, Key.BTN_WEST, Key.BTN_EAST, Key.BTN_SELECT, Key.BTN_START,
Key.BTN_TL, Key.BTN_TR, Key.BTN_TL2, Key.BTN_TR2, Key.BTN_MODE, Key.BTN_THUMBL, Key.BTN_THUMBR,
Key.BTN_DPAD_UP, Key.BTN_DPAD_DOWN, Key.BTN_DPAD_LEFT, Key.BTN_DPAD_RIGHT},
# EventType.FF: {ForceFeedback.RUMBLE, ForceFeedback.PERIODIC, ForceFeedback.SQUARE, ForceFeedback.TRIANGLE, ForceFeedback.SINE, ForceFeedback.GAIN},
EventType.KEY: {
Key.BTN_GAMEPAD,
Key.BTN_EAST,
Key.BTN_NORTH,
Key.BTN_WEST,
Key.BTN_EAST,
Key.BTN_SELECT,
Key.BTN_START,
Key.BTN_TL,
Key.BTN_TR,
Key.BTN_TL2,
Key.BTN_TR2,
Key.BTN_MODE,
Key.BTN_THUMBL,
Key.BTN_THUMBR,
Key.BTN_DPAD_UP,
Key.BTN_DPAD_DOWN,
Key.BTN_DPAD_LEFT,
Key.BTN_DPAD_RIGHT,
},
EventType.ABS: {Absolute.X, Absolute.Y, Absolute.RX, Absolute.RY, Absolute.RZ},
EventType.MSC: {Miscelaneous.SCAN},
}




def main():
import sys

Expand Down
13 changes: 10 additions & 3 deletions tests/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
from ward import skip, test, each, fixture, Scope


from linuxpy.input.device import EventType, is_uinput_available, UGamepad, UMouse, find_gamepads, find_mice
from linuxpy.input.device import (
EventType,
is_uinput_available,
UGamepad,
UMouse,
find_gamepads,
find_mice,
)


@fixture
Expand Down Expand Up @@ -91,7 +98,7 @@ def _(pair_dev_simulator=gamepad):
assert type(device.rx) is int
assert type(device.ry) is int
assert type(device.rz) is int
assert not device.active_keys
assert not device.active_keys


@skip(when=not is_uinput_available(), reason="uinput is not available")
Expand Down Expand Up @@ -119,4 +126,4 @@ async def _(pair_dev_simulator=gamepad):
event = await stream.__anext__()
assert event.type == EventType.KEY
event = await stream.__anext__()
assert event.type == EventType.SYN
assert event.type == EventType.SYN

0 comments on commit 0863f98

Please sign in to comment.