Kodi Community Forum

Full Version: PR8807
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
@garbear
First let me thank you for your hard and excellent work.

I saw your PR:8807 and decided to give it a try, manually merged and built it with peripheral.joystick just fine.
The addon seem to work but I am not able to make my "Xbox 360 Wireless" work at all.
The gui for mapping the buttons seems to ignore any keypresses.
I've tried both kernel xpad driver and xboxdrv with the same result.

The relevant part of the log file http://pastebin.com/Bjj5qCdK

Any suggestions?
Or PR is simply missing code/commits ?
(2016-01-08, 21:13)asavah Wrote: [ -> ]I saw your PR:8807 and decided to give it a try, manually merged and built it with peripheral.joystick just fine.
The addon seem to work but I am not able to make my "Xbox 360 Wireless" work at all.
The gui for mapping the buttons seems to ignore any keypresses.
I've tried both kernel xpad driver and xboxdrv with the same result.

The relevant part of the log file http://pastebin.com/Bjj5qCdK

it looks like you have a joystick driver that is translating joystick events into keypresses? maybe xboxdrv? Keypresses should still work though, so I'l not sure what's going on.

The Xbox 360 wireless receiver driver doesn't detect whether controllers are detected. So it thinks they're always connected, and this consumes ports, even when there's no controller. To fix this, on linux, we wait until the first button press or axis motion before considering the controller connected. Does the controller show up in the Peripherals List under System -> Input devices -> Peripherals?

Image
(2016-01-08, 23:14)garbear Wrote: [ -> ]Does the controller show up in the Peripherals List under System -> Input devices -> Peripherals?

No.
Only keyboard is shown.
Code:
21:04:03 13583.364258 T:1837106064    INFO: AddOnLog: Joystick Support: CJoystickInterfaceLinux::Initialize: opening joystick /dev/input/js3
21:04:03 13583.366211 T:1837106064    INFO: AddOnLog: Joystick Support: CJoystickInterfaceLinux::Initialize: opening joystick /dev/input/js2
21:04:03 13583.367188 T:1837106064    INFO: AddOnLog: Joystick Support: CJoystickInterfaceLinux::Initialize: opening joystick /dev/input/js1
21:04:03 13583.367188 T:1837106064    INFO: AddOnLog: Joystick Support: CJoystickInterfaceLinux::Initialize: opening joystick /dev/input/js0
21:04:03 13583.368164 T:1837106064    INFO: AddOnLog: Joystick Support: Initialized joystick 0: "Xbox 360 Wireless Receiver (XBOX)", axes: 8, hats: 0, buttons: 15
21:04:03 13583.368164 T:1837106064    INFO: AddOnLog: Joystick Support: Initialized joystick 1: "Xbox 360 Wireless Receiver (XBOX)", axes: 8, hats: 0, buttons: 15
21:04:03 13583.368164 T:1837106064    INFO: AddOnLog: Joystick Support: Initialized joystick 2: "Xbox 360 Wireless Receiver (XBOX)", axes: 8, hats: 0, buttons: 15
21:04:03 13583.369141 T:1837106064    INFO: AddOnLog: Joystick Support: Initialized joystick 3: "Xbox 360 Wireless Receiver (XBOX)", axes: 8, hats: 0, buttons: 15
21:04:04 13584.224609 T:1942786048    INFO: Found input device /dev/input/event0
21:04:04 13584.224609 T:1942786048    INFO: opened device 'Xbox 360 Wireless Receiver (XBOX)' (file name /dev/input/event0), m_bSkipNonKeyEvents 0
21:04:04 13584.224609 T:1942786048  NOTICE: Xbox 360 Wireless Receiver (XBOX): keys:0 ext:4 but:0 rel:0 abs:8 m_deviceType:8 bits:101000
21:04:04 13584.328125 T:1942786048    INFO: Found input device /dev/input/event1
21:04:04 13584.328125 T:1942786048    INFO: opened device 'Xbox 360 Wireless Receiver (XBOX)' (file name /dev/input/event1), m_bSkipNonKeyEvents 0
21:04:04 13584.328125 T:1942786048  NOTICE: Xbox 360 Wireless Receiver (XBOX): keys:0 ext:4 but:0 rel:0 abs:8 m_deviceType:8 bits:101000
21:04:04 13584.408203 T:1942786048    INFO: Found input device /dev/input/event2
21:04:04 13584.408203 T:1942786048    INFO: opened device 'Xbox 360 Wireless Receiver (XBOX)' (file name /dev/input/event2), m_bSkipNonKeyEvents 0
21:04:04 13584.408203 T:1942786048  NOTICE: Xbox 360 Wireless Receiver (XBOX): keys:0 ext:4 but:0 rel:0 abs:8 m_deviceType:8 bits:101000
21:04:04 13584.511719 T:1942786048    INFO: Found input device /dev/input/event3
21:04:04 13584.512695 T:1942786048    INFO: opened device 'Xbox 360 Wireless Receiver (XBOX)' (file name /dev/input/event3), m_bSkipNonKeyEvents 0
21:04:04 13584.512695 T:1942786048  NOTICE: Xbox 360 Wireless Receiver (XBOX): keys:0 ext:4 but:0 rel:0 abs:8 m_deviceType:8 bits:101000

It looks like there's two input systems battling over the same device. First, the joystick add-on discovers your receiver, and it thinks all four joystick are attached. Then, some other input system takes over and starts receiving events.

The variable m_bSkipNonKeyEvents doesn't appear in our source tree. searching the internet for this variable might help track down the problem.

Notably, they get the button count wrong, but we get it right :p

EDIT: nvm, wrong grep flag. Source is xbmc/input/linux/LinuxInputDevices.cpp - that's where the problem is
Just for the record I think https://github.com/paroj/xpad/commit/f23...eb630b9ae8 is getting merged in linux 4.4, which means the Xbox360 wireless-adapter will no longer set up all 4 controllers at start.

Edit: Maybe not in 4.4 but at least it's upcoming.
Cool, keep me updated on if it gets merged. Then we could compare kernel versions, and avoid the hack so you don't need to press a button to see your controller in the peripherals list.
I've looked into the problem and found a possible solution.

Historically, Linux provided a Joystick API. This is the API we use in peripheral.joystick.

Nowadays, this API is now built on top of the evdev input driver. This is the input driver that Kodi uses. It offers additional joystick functionality, like rumble. The problem is that Kodi mistakes the controller as a remote and grabs exclusive access. Because the input is absorbed here, it doesn't make it to the Joystick API.

The solution is to correct Kodi so that it doesn't think a joystick is a remote. If it releases the exclusive access, the device will "fall through" to the Linux Joystick API handled by peripheral.joystick. Fortunately, it looks like this bug is handled by PR 8385. I'll add this patch and see if it fixes the problem.
Thanks!
Building a fresh Kodi with updated PR as I write this lines.
Will report back as soon as I can test it (in a few hours).
PR has been updated, thanks for reporting
Wouldn't it be better to just have a peripheral.joystick addon that used evdev directly rather than using the deprecated joystick api?
Yes, this is the correct way forward. evdev has support for many extra features like rumble and (I think) LEDs
@garbear
Thanks again for what you are doing,
I finally managed to get some time to make a new build with updated PR.

It works now!
What I did:
borrowed this patch from OpenElec https://github.com/OpenELEC/OpenELEC.tv/...port.patch
completely removed SDL/SDL2

I think I forgot to mention that it's an X-less rpi2 with custom OS (somewhat similar to OpenElec)

From a quick test:
with kernel xpad button mapping is not correct from the gui - it maps d-pad down and left buttons as axis, fixed it by putting the right values from debug log into .xml config that peripheral.joystick generated, GUI navigation works like a charm.
userspace xboxdrv seems to have issues with axis, don't have enough time until the weekend to investigate thoroughly Sad

If needed I can provide debug logs, build master for ubuntu(x86_64) || rpi2 with any patches or make whatever tests you consider necessary, just ask, will be glad to help.