Xbox icon indicating copy to clipboard operation
Xbox copied to clipboard

No disconnect detection

Open fsofras opened this issue 5 years ago • 4 comments

I am using a wireless controller to control a rover. Despite the fact that the handheld is switched off, the joy.connected attribute is True. Any idea why?

fsofras avatar Apr 06 '19 09:04 fsofras

The streamed output of xboxdrv is expected to change whenever a controller loses connectivity. Normally, the output of xboxdrv is a full set of control states for the Xbox 360 controller. When a disconnect occurs, xboxdrv normally detects the change and sends an event string that is unique (it switches to an original Xbox controller layout, rather than the 360 layout). You should be able to see this for yourself by running xboxdrv interactively

sudo xboxdrv --detach-kernel-driver

While the controller is connected, you'll see state changes streamed to the console, showing a consistent format that includes all of the controls of a 360 controller. If you pop-out the battery from the controller, to force a disconnect, you should see a final event streamed that has a unique format to it. Here is how it appears for me (note how the 'black' and 'white' states appear, which are unique to the original Xbox controller):

Press Ctrl-C to quit, use '--silent' to suppress the event output X1: -3458 Y1: 159 X2: 408 Y2: 151 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0 X1: -3458 Y1: 159 X2: 714 Y2: 151 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0 X1: 0 Y1: 0 X2: 0 Y2: 0 du:0 dd:0 dl:0 dr:0 start:0 back:0 TL:0 TR:0 A: 0 B: 0 X: 0 Y: 0 black: 0 white: 0 LT: 0 RT: 0

If you confirm that xboxdrv is working in this manner on your system, then xbox.py should be able to detect the loss of connection. Running sample.py is a good way to confirm that all is well.

If xboxdrv isn't sending a unique event string on disconnect, then xbox.py will not be able to detect the disconnect. I'd be curious to learn what you are seeing.

For reference, I was using xboxdrv version 0.8.8 on Ubuntu, for the sample above. I'm also using an original Microsoft USB Xbox receiver.

FRC4564 avatar Apr 13 '19 15:04 FRC4564

Thank you very much for taking the time to reply. I am using the same version of xboxdrv on a raspberry 3B+ with the latest raspbian. The controller is a clone and is detected as

Microsoft Corp. Xbox360 Controller

(a wireless version) The command sudo xboxdrv --detach-kernel-driver produces the following string:

X1: 0 Y1: -256 X2: 0 Y2: -256 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0 and sample.py works as expected.
Swiching it off does not produce a different string, it just zeros everything ( as it should I think)

fsofras avatar Apr 15 '19 07:04 fsofras

That is definitely different than I've seen with Microsoft receivers. If xboxdrv doesn't provide some unique output, then xbox.py won't be able to identify a disconnect. There might be a simple workaround for you,

I see that your output is showing the Y1 and Y2 axis values registering as -256, while X1 and X2 come through as zeros, which is fairly unique. If the values are always X1: 0 Y1: -256 X2: 0 Y2: -256 whenever the controller is disconnected, you could test for this condition specifically within the 'refresh' method of xbox.py. Currently the block of code for determining connected status looks like this:

if len(response) == 140:
    self.connectStatus = True
    self.reading = response
else:  #Any other response means we have lost wireless or controller battery
    self.connectStatus = False

Try changing the 'if' statement to:

if len(response) == 140 and not response.startswith("X1: 0 Y1: -256 X2: 0 Y2: -256 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0"):

I can't really test it with my hardware, but you can give it a try.

FRC4564 avatar Apr 22 '19 20:04 FRC4564

Thank you, that is a good solution. I will try it

Στις Δευ, 22 Απρ 2019 στις 11:02 μ.μ., ο/η Steven Jacobs < [email protected]> έγραψε:

That is definitely different than I've seen with Microsoft receivers. If xboxdrv doesn't provide some unique output, then xbox.py won't be able to identify a disconnect. There might be a simple workaround for you,

I see that your output is showing the Y1 and Y2 axis values registering as -256, while X1 and X2 come through as zeros, which is fairly unique. If the values are always X1: 0 Y1: -256 X2: 0 Y2: -256 whenever the controller is disconnected, you could test for this condition specifically within the 'refresh' method of xbox.py. Currently the block of code for determining connected status looks like this:

Valid controller response will be 140 chars. if len(response) == 140:

self.connectStatus = True self.reading = response else: #Any other response means we have lost wireless or controller battery self.connectStatus = False

Try changing the 'if' statement to:

if len(response) == 140 and not response.startswith("X1: 0 Y1: -256 X2: 0 Y2: -256 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0"):

I can't really test it with my hardware, but you can give it a try.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FRC4564/Xbox/issues/9#issuecomment-485533205, or mute the thread https://github.com/notifications/unsubscribe-auth/AI3LP7FSFG6KNC2PZIK4MXTPRYKU5ANCNFSM4HEAO3SQ .

--

F Sofras

Change of email address: [email protected]

Frank E. Sofras MD, PhD, FRCS FEBU Professor of Urology

Address 137 Vas. Sofias Ave. Athens - 11521 GREECE

Mobile: +30 6944 472 417

Web Page: http://www.urology.edu.gr

fsofras avatar Apr 24 '19 13:04 fsofras