diff --git a/docs/.sphinxdict b/docs/.sphinxdict index 1bb400d..0590d1a 100644 --- a/docs/.sphinxdict +++ b/docs/.sphinxdict @@ -79,3 +79,4 @@ debayered rescanned unescaping underdefined +gamepads diff --git a/docs/devices/Windows.rst b/docs/devices/Windows.rst new file mode 100644 index 0000000..d6c7bb3 --- /dev/null +++ b/docs/devices/Windows.rst @@ -0,0 +1,25 @@ +.. _generic_windows_devices: + +Generic Windows devices +============================== + +There is some support for generic Windows drivers for some devices. + +Joysticks +------------------------------ + +Basic support for Windows-compatible joysticks / gamepads using WinMM. Since the driver only supports polling, the events (button/axis presses) are emulated using a separate polling loop. The main device class is :class:`pylablib.devices.Windows.Joystick<.joystick.Joystick>`. Since this library is a standard part of Windows, no additional software is required, apart from potential joystick drivers. + +The code supports polling the joystick state (button and axes) as well as querying events:: + + >> from pylablib.devices import Windows + >> Windows.list_joysticks() + {0: TDeviceInfo(name='Microsoft PC-joystick driver', id=(121, 17), nbuttons=10, naxes=2)} + >> j=Windows.Joystick() + >> j.get_buttons() + [False, False, False, False, False, False, False, False, False, False] + >> j.start() # start polling loop in a separate thread + >> j.get_events() # get the recent events (since the last get_events call) + TJoystickEvent(kind='axis', index=0, old=0, new=-1, timestamp=1000000000.000), + TJoystickEvent(kind='axis', index=0, old=-1, new=0, timestamp=1000000001.000)] + >> j.stop() # stop the polling loop when done \ No newline at end of file diff --git a/docs/devices/all_devices_list.txt b/docs/devices/all_devices_list.txt index 5a2a5ed..9ac923f 100644 --- a/docs/devices/all_devices_list.txt +++ b/docs/devices/all_devices_list.txt @@ -37,6 +37,7 @@ - :ref:`ElektroAutomatik power supplies ` - :ref:`Rigol power supplies ` +- :ref:`Generic Windows devices ` - :ref:`Mid-level protocols ` - :ref:`Modbus ` \ No newline at end of file diff --git a/docs/devices/devices_root.rst b/docs/devices/devices_root.rst index 9a59f72..fb45523 100644 --- a/docs/devices/devices_root.rst +++ b/docs/devices/devices_root.rst @@ -35,4 +35,5 @@ Currently supported devices: Lumel Omron misc_devices + Windows protocols \ No newline at end of file diff --git a/pylablib/devices/Windows/joystick.py b/pylablib/devices/Windows/joystick.py index dab07f8..1c1f63f 100644 --- a/pylablib/devices/Windows/joystick.py +++ b/pylablib/devices/Windows/joystick.py @@ -25,8 +25,15 @@ def list_joysticks(): return js TJoystickEvent=collections.namedtuple("TJoystickEvent",["kind","index","old","new","timestamp"]) -TJoystickEventEx=collections.namedtuple("TJoystickEvent",["kind","index","old","new","state","timestamp"]) +TJoystickEventEx=collections.namedtuple("TJoystickEventEx",["kind","index","old","new","state","timestamp"]) class Joystick(interface.IDevice): + """ + Generic Windows joystick device. + + Args: + idx: joystick index (0-based) in the list returned by :func:`list_joysticks`; if ``None``, use the first valid index. + expanded_events (bool): if ``True``, the events include the full joystick state; otherwise, they only record the change of the state at the particular event + """ Error=winmm_lib.WinMMError def __init__(self, idx=None, expanded_events=False): super().__init__()