psmoveapi icon indicating copy to clipboard operation
psmoveapi copied to clipboard

Reliably detecting controller disconnection.

Open whitingjp opened this issue 11 years ago • 1 comments

So it would be good to have a simple cross platform method for determining if the current controller is still connected to the machine. To the best of my knowledge such a thing does not currently exist. Disconnected can mean a bunch of different things, so I'll enumerate the ones I know of:

  • Controller out of bluetooth 'sight' (out of range, or shielded)
  • Controller turned off manually or out of battery
  • Controller unresponsive (broken)

I didn't find a concrete way of implementing it that was reliable on both OSX and Linux. The Current implementation of controller disconnection in Sportsfriends looks something like this:

bool connected = true;
if(!data.moves[i].api)
    connected = false;
else if(!data.moves[i].canUpdateLEDs)
    connected = false;
data.moves[i].timeSincePoll += dT;
if(data.moves[i].timeSincePoll > 1)
    connected = false;

So, to explain what is going on, for a controller to be seen as connected we must check:

  • We have a valid move api handle for controller.
  • We are able to successfully call psmove_update_leds on controller.
  • We have successfully pulled input data from the controller within the last second.

Anything shy of those requirements doesn't seem to be robust enough.

This is of course a fair bit of a faff to go through, and as far as I can see these are all things that we might be able to handle on the api side. Thoughts?

whitingjp avatar Sep 17 '14 12:09 whitingjp

Being able to read data from the controller, especially as it comes in with a high frequency, should be good. Maybe it also needs some holddown timer, i.e. if within 1 second, mark as "questionable", after 4 seconds (when the LEDs would go off) mark as "disconnected".

thp avatar Sep 26 '14 19:09 thp