v18 Xiaomi bluetooth gamepad not working
#1
It's Kodi 18.0 (CoreELEC 8.99.1 running on an Amlogic S905D device). I have paired Xiaomi bluetooth gamepad successfully.
In Kodi settings->System->Input->Peripherals, I can already see this Xiaomi bluetooth gamepad.
I'm trying to remap buttons via Kodi settings->System->Input->Configure attached controllers. However, no matter which button I press, nothing happens (either Kodi doesn't detect it or it's ignored somehow).
I understand this is not a popular gamepad, and I don't expect it to be working out of the box. But is there any guide I can follow manually to make it work?
Reply
#2
I'm back to continue the investigation. The gamepad is the same as https://www.gearbest.com/video-game/pp_167775.html.

With "cat /proc/bus/input/devices", it shows:
I: Bus=0005 Vendor=2717 Product=3144 Version=0129
N: Name="小米蓝牙手柄"
P: Phys=43:45:c0:00:1f:ac
S: Sysfs=/devices/c11084c0.serial/tty/ttyS1/hci0/hci0:11/0005:2717:3144.0001/input/input6
U: Uniq=ac:fd:93:f0:b0:70
H: Handlers=kbd js1 event5
B: PROP=0
B: EV=10001b
B: KEY=7fff0000 0 0 0 1000 40000000 1680 0 0 0
B: ABS=100 3047f
B: MSC=10

If I run "cat /dev/input/js1", I can see output when I press buttons on the gamepad.

According to Keymap (wiki), I can custom Joystick Configuration by joystick name and button ids. 'id' is the button ID used by SDL. Joystick button ids of connected joysticks appear in kodi.log when they are pressed. Use your log to map custom buttons to actions.

I already have the joystick name, but when I look at kodi.log, I can only find those "libinput: event5  - debounce state" instead of button ids. Can someone shed some light? Is this something that can be fixed by config file? Or it lacks the support from the low-level driver and simply won't work?

00:32:31.065 T:4096783216   DEBUG: CLibInputHandler:Big GrineviceAdded - keyboard type device added: 小米蓝牙手柄 (event5)
00:32:31.065 T:4096783216   DEBUG: CLibInputKeyboard::GetRepeat - delay: 500ms repeat: 33ms for 小米蓝牙手柄 (event5)
00:32:31.069 T:3954156400    INFO: AddOnLog: Joystick Support: Initialized joystick 1: "小米蓝牙手柄", axes: 11, hats: 0, buttons: 15
00:32:31.113 T:3954156400   DEBUG: GetMappingForDevice - device (0000:0000) mapped to  (type = joystick)
00:32:31.168 T:3954156400   DEBUG: Failed to load button map for "小米蓝牙手柄"
00:32:31.201 T:3954156400   DEBUG: Previous line repeats 2 times.
00:32:31.201 T:3954156400   DEBUG: Initialise - initialised peripheral on 'peripheral.joystick/1' with 1 features and 0 sub devices
00:32:31.201 T:3954156400  NOTICE: Register - new joystick device registered on addon->peripheral.joystick/1: 小米蓝牙手柄
00:32:38.957 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_IS_UP → DEBOUNCE_EVENT_OTHERBUTTON → DEBOUNCE_STATE_IS_UP
00:32:38.957 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_IS_UP → DEBOUNCE_EVENT_PRESS → DEBOUNCE_STATE_DOWN_WAITING
00:32:38.982 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_DOWN_WAITING → DEBOUNCE_EVENT_TIMEOUT → DEBOUNCE_STATE_IS_DOWN
00:32:39.159 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_IS_DOWN → DEBOUNCE_EVENT_RELEASE → DEBOUNCE_STATE_RELEASE_WAITING
00:32:39.171 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_RELEASE_WAITING → DEBOUNCE_EVENT_TIMEOUT_SHORT → DEBOUNCE_STATE_RELEASED
00:32:39.184 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_RELEASED → DEBOUNCE_EVENT_TIMEOUT → DEBOUNCE_STATE_IS_UP
Reply
#3
Experience the same thing with my Xiaomi. Thanks so much for any suggestions.
Reply
#4
(2019-02-28, 03:02)sockscap Wrote:
Code:
...
00:32:31.201 T:3954156400  NOTICE: Register - new joystick device registered on addon->peripheral.joystick/1: 小米蓝牙手柄
00:32:38.957 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_IS_UP → DEBOUNCE_EVENT_OTHERBUTTON → DEBOUNCE_STATE_IS_UP
00:32:38.957 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_IS_UP → DEBOUNCE_EVENT_PRESS → DEBOUNCE_STATE_DOWN_WAITING
00:32:38.982 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_DOWN_WAITING → DEBOUNCE_EVENT_TIMEOUT → DEBOUNCE_STATE_IS_DOWN
00:32:39.159 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_IS_DOWN → DEBOUNCE_EVENT_RELEASE → DEBOUNCE_STATE_RELEASE_WAITING
00:32:39.171 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_RELEASE_WAITING → DEBOUNCE_EVENT_TIMEOUT_SHORT → DEBOUNCE_STATE_RELEASED
00:32:39.184 T:4096783216   DEBUG: libinput: event5  - debounce state: DEBOUNCE_STATE_RELEASED → DEBOUNCE_EVENT_TIMEOUT → DEBOUNCE_STATE_IS_UP
Hi,
I run into the same problem yesterday and I found a solution! The problem is, that the device registers as joystick and as keyboard. If you use evtest or jstest with the correct device (/dev/input/eventX or /dev/input/jsX) they both work correctly, but kodi registers both devices as inputs and cannot debounce, as two inputs are coming at the same time. Although this is just a rough guess, the consequence is, that you need to block one device with a udev-rule. I will briefly describe how I defined the rule to block the keyboard part for libinput.
First you need to have a look at what happens when the device is registered. When you plug in a device it gets first registered by the kernel and then udev applies its rules to do whatever is defined for this device. With udevadm you can watch this process (only the interesting parts):
Code:
LibreELEC:~/.config/udev.rules.d # udevadm monitor --env
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
...snip...
KERNEL[1920.144319] add      /devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0006/input/input5/js0 (input)
ACTION=add
DEVPATH=/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0006/input/input5/js0
SUBSYSTEM=input
DEVNAME=/dev/input/js0
SEQNUM=2098
MAJOR=13
MINOR=0

KERNEL[1920.144640] add      /devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0006/input/input5/event0 (input)
ACTION=add
DEVPATH=/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0006/input/input5/event0
SUBSYSTEM=input
DEVNAME=/dev/input/event0
SEQNUM=2099
MAJOR=13
MINOR=64

UDEV  [1920.157313] add      /devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0006/input/input5/js0 (input)
ACTION=add
DEVPATH=/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0006/input/input5/js0
SUBSYSTEM=input
DEVNAME=/dev/input/js0
SEQNUM=2098
USEC_INITIALIZED=1920156852
ID_INPUT=1
ID_INPUT_JOYSTICK=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
MAJOR=13
MINOR=0

UDEV  [1920.277276] add      /devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0006/input/input5/event0 (input)
ACTION=add
DEVPATH=/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0006/input/input5/event0
SUBSYSTEM=input
DEVNAME=/dev/input/event0
SEQNUM=2099
USEC_INITIALIZED=1920223030
ID_INPUT=1
ID_INPUT_JOYSTICK=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
ID_INPUT_JOYSTICK_INTEGRATION=external
LIBINPUT_DEVICE_GROUP=5/2717/3144:dc:a6:32:2d:02:38
MAJOR=13
MINOR=64
TAGS=:power-switch:
You can see the "KERNEL" part and a corresponding "UDEV" part, which is what is registered by udev in the system. If you have a look on the input ID attributes you can see that the device is a joystick as well as a keyboard. A udev rule contains always a "match" part that selects on which item the rule should be applied and and an "action" of what should be done. As we want instruct libinput to ignore the keyboard (event0) we need to define a rule that matches on the "KERNEL" part and defines the environment variable LIBINPUT_IGNORE_DEVICE to something else then "0". As we can see there is only the DEVPATH variable that is device dependent and specifically "2717:3144" (vendor:device) define the Xiaomi GamePad (e.g. 2717:32B1 defines the Bluetooth Remote). Thus our rule looks as follows:
Code:
ACTION=="add", SUBSYSTEM=="input", KERNEL=="event[0-9]*", ENV{DEVPATH}=="*2717:3144*",  ENV{LIBINPUT_IGNORE_DEVICE}="1"

As I use libreElec I put this line into /storage/.config/udev.rules.d/99_xiaomi_gamepad.rules and test it with "udevadm test /sys/class/input/eventX" (with X be correct number for your device). The output should contain the rule you just written and the environment variable you set:
Code:
LibreELEC:~/.config/udev.rules.d # udevadm test /sys/class/input/event0/
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

Load module index
Created link configuration context.
Reading rules file: /usr/lib/udev/rules.d/30-disable-wakeup.rules
...snip...
Reading rules file: /storage/.config/udev.rules.d/99_xiaomi_gamepad.rules
Rules contain 24576 bytes tokens (2048 * 12 bytes), 14741 bytes strings
2178 strings (29230 bytes), 1445 de-duplicated (15223 bytes), 734 trie nodes used
Invalid inotify descriptor.
Starting 'libinput-device-group /sys/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0008/input/input7/event0'
'libinput-device-group /sys/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0008/input/input7/event0'(out) '5/2717/3144:dc:a6:32:2d:02:38'
Process 'libinput-device-group /sys/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0008/input/input7/event0' succeeded.
DEVPATH=/devices/platform/soc/fe201000.serial/tty/ttyAMA0/hci0/hci0:11/0005:2717:3144.0008/input/input7/event0
DEVNAME=/dev/input/event0
MAJOR=13
MINOR=64
ACTION=add
SUBSYSTEM=input
ID_INPUT=1
ID_INPUT_JOYSTICK=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
ID_INPUT_JOYSTICK_INTEGRATION=external
TAGS=:power-switch:
LIBINPUT_DEVICE_GROUP=5/2717/3144:dc:a6:32:2d:02:38
LIBINPUT_IGNORE_DEVICE=1
USEC_INITIALIZED=3495036593
run: '/usr/bin/ir-keytable --delay=500 --device=/dev/input/event0'
Unload module index
Unloaded link configuration context.

Now just reload the rules and trigger udev to use them:
Code:
udevadm control --reload
udevadm trigger
When you now reconnect your device, it is recognized only as joystick within kodi and you can proceed with the usual keymapping described here: https://kodi.wiki/view/HOW-TO:Configure_controllers
Reply
#5
@Darkstar2000 

Awesome! Thank you so much for sharing the solution. It works like a charm.

As I have very little knowledge about udev stuff, if you don't mind, I'd like to seek for your advice on another issue which has troubled me for years. Xiaomi used to sell bluetooth remote which worked great in Kodi, but it's decommissioned years ago. Unfortunately, the upgrade model Xiaomi bluetooth voice remote 小米语音遥控器 can no longer work in Kodi. I raised the issue in another post 2 years ago but never found a solution.

When I try your method today to fix the gamepad issue, I also use "udevadm monitor --env" to trace the process when I connect Xiaomi bluetooth voice remote 小米语音遥控器. The root cause appears to be, no input device is created. To fix the issue, do I need certain udev-rule to create the input device? Any idea how this can be achieved?
 


Sx05RE-42W800A:~ # udevadm monitor --env
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[157.069994] add      /devices/c11084c0.serial/tty/ttyS1/hci0/hci0:64 (bluetooth)
ACTION=add
DEVPATH=/devices/c11084c0.serial/tty/ttyS1/hci0/hci0:64
DEVTYPE=link
SEQNUM=2292
SUBSYSTEM=bluetooth

UDEV  [157.072971] add      /devices/c11084c0.serial/tty/ttyS1/hci0/hci0:64 (bluetooth)
ACTION=add
DEVPATH=/devices/c11084c0.serial/tty/ttyS1/hci0/hci0:64
DEVTYPE=link
SEQNUM=2292
SUBSYSTEM=bluetooth
SYSTEMD_ALIAS=/sys/subsystem/bluetooth/devices/hci0:64
SYSTEMD_WANTS=bluetooth.target
TAGS=:systemd:
USEC_INITIALIZED=157072467

KERNEL[163.493221] add      /devices/virtual/misc/uhid/0005:2717:32B0.0001 (hid)
ACTION=add
DEVPATH=/devices/virtual/misc/uhid/0005:2717:32B0.0001
HID_ID=0005:00002717:000032B0
HID_NAME=小米语音遥控器
HID_PHYS=43:45:C0:00:1F:AC
HID_UNIQ=08:EB:29:3E:02:0F
MODALIAS=hid:b0005g0003v00002717p000032B0
SEQNUM=2293
SUBSYSTEM=hid

UDEV  [163.502946] add      /devices/virtual/misc/uhid/0005:2717:32B0.0001 (hid)
ACTION=add
DEVPATH=/devices/virtual/misc/uhid/0005:2717:32B0.0001
HID_ID=0005:00002717:000032B0
HID_NAME=小米语音遥控器
HID_PHYS=43:45:C0:00:1F:AC
HID_UNIQ=08:EB:29:3E:02:0F
MODALIAS=hid:b0005g0003v00002717p000032B0
SEQNUM=2293
SUBSYSTEM=hid
USEC_INITIALIZED=163496641
Reply

Logout Mark Read Team Forum Stats Members Help
Xiaomi bluetooth gamepad not working0