zeth / inputs

Cross-platform Python support for keyboards, mice and gamepads
BSD 3-Clause "New" or "Revised" License
269 stars 87 forks source link

set_vibration lock after 16 uses giving "no space left on device" #109

Open Krayfighter opened 2 years ago

Krayfighter commented 2 years ago

the following code works

import inputs
from time import sleep
controller = inputs.devices.gamepads[0]
for i in range(16):
    controller.set_vibration(0, 1, 100)
    sleep(.1)

so long as the range is less than 17

otherwise, is will give the following stack trace

Traceback (most recent call last): File "", line 1, in File "/home/aidenk/.local/lib/python3.10/site-packages/inputs.py", line 2983, in set_vibration self._set_vibration_nix(left_motor, right_motor, duration) File "/home/aidenk/.local/lib/python3.10/site-packages/inputs.py", line 2969, in _set_vibration_nix code = self.get_vibration_code(left_motor, right_motor, duration) File "/home/aidenk/.local/lib/python3.10/site-packages/inputs.py", line 2963, in get_vibration_code buf_conts = ioctl(self._write_device, 1076905344, inner_event) OSError: [Errno 28] No space left on device

this work inside and outside of a loop, and for the duration of the process' lifetime, limiting the number of calls to this function to 16 for the entire program runtime

I also noticed that if I had 2 python instances open, I could use all the the 16 function calls in the first, and the second would be unable to call the function, giving the same stack trace.

my system:

Operating System: Fedora Linux 35 KDE Plasma Version: 5.25.4 KDE Frameworks Version: 5.96.0 Qt Version: 5.15.2 Kernel Version: 5.19.6-100.fc35.x86_64 (64-bit) Graphics Platform: Wayland Processors: 8 × 11th Gen Intel® Core™ i5-1135G7 @ 2.40GHz Memory: 15.3 GiB of RAM Graphics Processor: Mesa Intel® Xe Graphics Manufacturer: Framework Product Name: Laptop System Version: A3

Python 3.10.6 inputs 0.5

justin-sliprobotics commented 1 month ago

The reason why this is happening is because the set_vibration method actually writes the effect to the gamepad when called. Your gamepad probably has 16 slots for effects. After calling it 16 times, there is no more space to store another effect. This library is unmaintained, but you can address it for yourself by splitting out the writing of the effect into its own method that is called only once.