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

Make pairing process occur on hot-reload #315

Closed
Kanuan opened this issue Aug 30, 2023 · 13 comments · Fixed by #360
Closed

Make pairing process occur on hot-reload #315

Kanuan opened this issue Aug 30, 2023 · 13 comments · Fixed by #360
Assignees
Labels
Core Core/Common Driver Topic enhancement New feature or request USB USB-related (wired)
Milestone

Comments

@Kanuan
Copy link
Collaborator

Kanuan commented Aug 30, 2023

This should allow users to spam the apply settings button to trigger the hot-reload, sending the pairing packet any time it's necessary. This might fix issues with controllers that fail to pair if the packet is received too early.

If possible, also make it so the "last pairing check" and "host address" packets are updated then.

@nefarius nefarius self-assigned this Aug 30, 2023
@nefarius nefarius added enhancement New feature or request USB USB-related (wired) Core Core/Common Driver Topic labels Aug 30, 2023
@nefarius nefarius added this to the Fixed in v3.0.x milestone Sep 6, 2023
@Kanuan
Copy link
Collaborator Author

Kanuan commented Apr 26, 2024

Should pairing occur on every hot-reload? Or should we introduce a different way of triggering pairing on demand by pressing some button in the ControlApp?

Making it occur on every hot-reload seems wasteful, specially if the user is testing settings

@nefarius
Copy link
Owner

There aren't a ton of mechanisms in how to communicate with a HID driver since IO control requests are governed by what features the HID report descriptor exposes. However, being a user-mode driver we have some options to "cheat", for example a named event could be registered, similar to the hot reload file system watcher, that can be signaled by the control app and trigger the pairing. Remaining question would be where to get the desired MAC address from; if a radio exists that's easy but what about a custom MAC to mimic functionality of the old sixaxis pair tool. Maybe also pulling it from the JSON would be the least amount of change required.

@Kanuan
Copy link
Collaborator Author

Kanuan commented Apr 26, 2024

Yeah, was planning on taking the custom address from the config file, was wondering more how to trigger it "manually" and not on every hot-reload.

I think I'll do the following:

  1. Introduce a counter variable in the user config disk file
  2. Load this counter value to memory when (re-)loading user settings in the driver
  3. Send pairing request on device boot, but also if the counter changed on a hot-reload
  4. Make it so the counter in the disk file only increases on command in the ControlApp instead of everytime settings are adjusted

@nefarius
Copy link
Owner

There is no such need for that much complexity. The last host address sent to the controller is already known and cached in the device context during runtime. If the address pulled from the config file matches this value, don't send the pairing packet, case closed.

@nefarius
Copy link
Owner

As for triggering this mechanism, introduce a named event that is shared between driver and app, if the app signals it, see if the host address in the JSON is different from the current one, if so, send the USB packet, done.

@nefarius
Copy link
Owner

An extra even isn't even needed, since unnecessary requests can easily be avoided by address comparison if the JSON is modified and saved, pairing can be triggered from hot reload, further reducing complexity.

@nefarius
Copy link
Owner

nefarius commented Apr 26, 2024

Two new settings are needed. A pairing type preference like default (auto select host radio address) and custom (use MAC from 2nd config field) that writes whatever the user desires.

@Kanuan
Copy link
Collaborator Author

Kanuan commented Apr 26, 2024

My proposal was more on how to force the repairing process to occur repeatedly to the same address for devices we believe are time sensitive and may not accept the pairing request on boot.

But you are right, if the user wants to re-trigger the process it's possible to simplify things in the driver side by just making the Control app first automatically set some random address before setting the address again to the desired one

@nefarius
Copy link
Owner

Setting it to 00:00:00:00:00:00, waiting a bit, then using the desired value could achieve that without screwing anything.

@Kanuan
Copy link
Collaborator Author

Kanuan commented Apr 26, 2024

yeah, was just writing that. Set the values to all zeroes before setting the desired one.

Is it safe to directly set the pairing address to "0" or should I make the driver check for it and not send the pairing request if so?

@nefarius
Copy link
Owner

Well, the address copy in the driver context memory should only be updated with a new value, if the USB request was successful. Technically leaving it at 0 if the subsequent "pairing" process failed is valid; after all if a controller is reset via the back pin, the host value would be read as zeroed out as well anyway. So 00:00:00:00:00:00 is a valid MAC at any time.

@nefarius
Copy link
Owner

nefarius commented Apr 26, 2024

And yes, as I wrote before, if the controller is already set to e.g. 0C:13:37:DE:AD:BE and that exact value is read again on reload, the whole address updating should simply be skipped altogether. If a force refresh is desired:

  • Set custom value in JSON to all zeroes
  • Save file
  • Wait a bit
  • Set custom value in JSON to actual value
  • Save file
  • Hopefully it now has worked for the controller in question

Last pairing status can be queried from the already existing device property and reacted on in the UI accordingly.

@nefarius
Copy link
Owner

#321 is also related. As a follow-up change, a failure to fetch device or host MAC should log an error in the future as it does already, however should not fail device power up. This would open the door to support devices that have no concept of a MAC or where fetching it is timing-sensitive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Core/Common Driver Topic enhancement New feature or request USB USB-related (wired)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants