Skip to content

Commit

Permalink
Added joysticks docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexShkarin committed May 5, 2024
1 parent 08ce38e commit a4f10ed
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/.sphinxdict
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ debayered
rescanned
unescaping
underdefined
gamepads
25 changes: 25 additions & 0 deletions docs/devices/Windows.rst
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions docs/devices/all_devices_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- :ref:`ElektroAutomatik power supplies <elektroautomatik_sources>`
- :ref:`Rigol power supplies <rigol_power_supply>`

- :ref:`Generic Windows devices <generic_windows_devices>`
- :ref:`Mid-level protocols <protocols>`

- :ref:`Modbus <protocols_modbus>`
1 change: 1 addition & 0 deletions docs/devices/devices_root.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Currently supported devices:
Lumel
Omron
misc_devices
Windows
protocols
9 changes: 8 additions & 1 deletion pylablib/devices/Windows/joystick.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down

0 comments on commit a4f10ed

Please sign in to comment.