Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALLEGRO_JOYSTICK* design does not allow for reconnecting #1424

Open
MarkOates opened this issue Mar 16, 2023 · 1 comment
Open

ALLEGRO_JOYSTICK* design does not allow for reconnecting #1424

MarkOates opened this issue Mar 16, 2023 · 1 comment

Comments

@MarkOates
Copy link
Contributor

MarkOates commented Mar 16, 2023

Issue

Currently, the Joystick implementation does not "re-recognize" any devices that have disconnected and then reconnect. Instead, a new ALLEGRO_JOYSTICK* is created for that device, and the old pointer remains active but dead. In addition to that, there is no data that is exposed by Allegro that can be used to correlate known, reconnecting devices.

This presents some limitations for Joystick usability, mostly in multiplayer contexts. Specifically, if one player's device disconnects, a new joystick setup may need to be walked through again when the "new" device reconnects. This presents challenges for custom mapping of buttons, correlating players to devices, usability of device lists. etc.

On macOS, the recommendation seems to be to obtain the serial number, e.g. ask for the kIOHIDSerialNumberKey on the IOHIDDeviceRef device, which can be used to map unique devices. If privacy is a concern, we could consider creating a hash consisting of serial number, manufacturer id, and device id. Device info and configurations with this info could even be stored in config files, allowing a smooth experience when restarting a program.

Discussion/Proposal

I see there has been some discussion about adding an ALLEGRO_JOYSTICK_GUID as well as a database of known joystick types (which would be great to have), but this issue is slightly different and may collide with the one I describe.

Originally I though to suggest a al_get_joystick_uid() to obtain a unique id specific to the device itself (hash composed of manufacturer id, device id, serial number), but the concept of a "GUID" already appears to be taken in the previous discussions to represent a joystick's make/model. Maybe a more formal ALLEGRO_JOYSTICK_KIND_GUID could be used there instead? And ALLEGRO_JOYSTICK_GUID could be used to represent a specific device?

For making the unique id, this would also open the door for other properties to be exposed such as al_get_joystick_manufacturer_id, al_get_joystick_device_id, al_get_joystick_serial_number, but these may be redundant if really all we're after is just information about a joystick's make and persistence status.

Relates Issues

@MarkOates
Copy link
Contributor Author

MarkOates commented Mar 16, 2023

In addition to kIOHIDSerialNumberKey, I also stumbled across a kIOHIDUniqueIDKey which appears to be exactly as it describes, a unique id representing the device.

I can't seem to find robust documentation on the thing, but there was a discussion here about using it to resolve re-connections. It was was also mentioned however that "kIOHIDUniqueIDKey is unsupported on older systems and wasn't a great solution because of this."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant