inputs icon indicating copy to clipboard operation
inputs copied to clipboard

Allow re-scan of devices to support hot-plugging

Open j3kestrel opened this issue 3 years ago • 5 comments

The use of a bare generator in EVENT_MAP['type_codes'] makes EVENT_MAP a single use object. Converting the generator to a tuple allows reuse of EVENT_MAP and constructing a new DeviceManager that re-scans for devices.

Addresses issue #66

j3kestrel avatar May 05 '21 18:05 j3kestrel

I now see that pull request #81 fixes the same problem, but doesn't add a function to re-scan devices.

j3kestrel avatar May 05 '21 18:05 j3kestrel

Thanks. I just need to find a day to test with the 100 devices.

zeth avatar Jun 21 '21 01:06 zeth

This should also fix #106. Attempting to create a new DeviceManager instance manually does not work as rescan because of the bare generator in EVENT_MAP.

BirdLogics avatar Apr 17 '22 18:04 BirdLogics

This fix works only when inputs is imported as a whole. It would not change the instance of devices when it is imported individually (from inputs import devices), as it is shown instead in the examples.

>>> import inputs
>>> from inputs import devices
>>> 
>>> inputs.devices == devices
True
>>> inputs.rescan_devices()
>>> 
>>> inputs.devices == devices
False
>>>

cathartyc avatar Feb 17 '24 11:02 cathartyc

I suspect that is because input.devices not mutated, it is replaced. As a result, inputs.devices and local devices no longer reference the same object. Any local references to input.devices would need to be refreshed after using rescan_devices().

import inputs`
devices = inputs.devices
[...]
inputs.rescan_devices()
devices = inputs.devices

Or, perhaps rescan_devices() could return devices so that it becomes devices = inputs.rescan_devices(). The problem with all of this is that it doesn't solve the problem of a developer expecting devices to be mutated instead of replaced and not expecting to need to re-cache the local reference.

Is there a better solution other than updating examples and documentation?

j3kestrel avatar Feb 18 '24 01:02 j3kestrel