hid#

class platypush.plugins.hid.HidPlugin(monitored_devices: Iterable[dict] | None = None, poll_seconds: int = 1, **kwargs)[source]#

Bases: RunnablePlugin

This plugin can be used to interact directly with HID devices (including Bluetooth, USB and several serial and wireless devices) over the raw interface.

This is the preferred way of communicating with joypads.

Note that on Linux reading from the devices requires the user running the Platypush service to have (at least) read access to the /dev/hidraw* devices. However, it is still possible to get connected/disconnected events even without having to open a connection to the device. A way to make HID raw devices accessible to e.g. a particular user group is via udev rules. For example, create a file named /etc/udev/rules.d/99-hid.rules with the following content:

# Make all /dev/hidraw* devices accessible in read/write to users in
# the group input
KERNEL=="hidraw*", GROUP="input", MODE="0660"

A more granular solution is to provide read and/or write access only to a specific device that you want to access, and only to the specific user running the Platypush service:

KERNEL=="hidraw*", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", USER="user", MODE="0660"

If you don’t want to reboot the device after adding the rules, then you can reload the rules for udev service and re-trigger them:

# udevadm control --reload && udevadm trigger

Triggers:

__init__(monitored_devices: Iterable[dict] | None = None, poll_seconds: int = 1, **kwargs)[source]#
Parameters:
  • monitored_devices

    Map of devices that should be monitored for new data. Format (note that all the device filtering attributes are optional):

    [
      {
        "data_size": "How many bytes should be read from the device on each iteration (default: 64)",
        "manufacturer_string": "foo",
        "notify_only_if_changed": "If set to true (default), only changes in the values of the device will trigger events. So if you are e.g. monitoring the state of a joystick, only changes in the pressed buttons will trigger events.",
        "path": "/dev/hidraw0",
        "poll_seconds": "How often we should wait before data reads (default: no wait)",
        "product_id": 4321,
        "product_string": "My Device",
        "serial_number": "00:11:22:33:44:55",
        "vendor_id": 1234
      }
    ]
    

  • poll_seconds – How often the plugin should check for changes in the list of devices (default: 1 second).

get_devices() List[dict][source]#

Get the HID devices available on the host.

Returns:

[
  {
    "manufacturer_string": "foo",
    "path": "/dev/hidraw0",
    "product_id": 4321,
    "product_string": "My Device",
    "serial_number": "00:11:22:33:44:55",
    "vendor_id": 1234
  }
]

main()[source]#

Implementation of the main loop of the plugin.

stop()[source]#

Stop the plugin.