本来是奎克质造生产的模拟飞行设备QMCP737C
x-plane.vip - QuickMade - QMCP737C
我在写软件,支持全平台win/lin/mac,和模拟飞行平台X-Plane 11保持一致。结果WIN/MAC对设备支持没问题,插上就可以用。
但是Linux,插上也可以用,但是只剩80个按键,明明我的设备是104个按键,结果只识别出80个按键。
然后用各种关键字max USB HID button number之类一顿GOOGLE搜索,无果。
我记得Linus说过,你不要以为所谓别人会解决问题,如果问题是你发现的,那么你就是解决问题的最佳人选。此话值得回味。
好吧先看看Linux内核代码,这个神奇的数字80到底来自何方?
一顿80内核搜索,无果。
80=0x50,再是一顿代码搜索,同样无果。
终于读了一下逻辑,发现80确实有来头,下载ubuntu内核代码,经过几个小时的下载,编译,再修改编译,然后奇迹发生了。104个按键全部出来。
提交代码给内核社区,未来受益全人类了
Input: break joystick limitation of maximum 80 buttons - Patchwork
我编译的测试内核linux-image-4.15.18_2.0.qmcp737c_amd64.deb,这个内核,我连Nvidia Vulkan都能跑起来,所以也可以用于运行X-Plane 11.50。可以免费下载
linux-image-4.15.18_2.0.qmcp737c_amd64.deb-Linux文档类资源-CSDN下载
自定义新内核
关于input驱动的官方信息在这里
对于飞行模拟平台X-Plane 11.50b14,从启动的log看,ring3 APP识别到了设备,但是依然是80个按键,应该和/dev/input/event3的代码相关
0:00:04.305 D/HID: Hardware ADDED(0483, 5680) - QuickMake QMCP737C at path /dev/input/event3 - Has 79 buttons, 0 hat switches, and 0 axes
0:00:04.305 I/JOY: REGISTER Joystick device: QuickMake QMCP737C - VID:1155PID:22144, this is a familiar device.
继续用jstest /dev/input/event3,读取event设备消息,我得到如下错误
Driver version is 0.8.0.
jstest is not fully compatible with your kernel. Unable to retrieve button map!
Joystick (Unknown) has 2 axes and 2 buttons.
Testing ... (interrupt to exit)
jstest: error reading: Invalid argument
根据jstest的源代码
linuxconsole/jstest.c at master · flosse/linuxconsole · GitHub
/* Determine whether the button map is usable. */
for (i = 0; btnmapok && i < buttons; i++) {
if (btnmap[i] < BTN_MISC || btnmap[i] > KEY_MAX) {
btnmapok = 0;
break;
}
}
if (!btnmapok) {
/* btnmap out of range for names. Don't print any. */
puts("jstest is not fully compatible with your kernel. Unable to retrieve button map!");
printf("Joystick (%s) has %d axes ", name, axes);
printf("and %d buttons.\n", buttons);
如预期,果然和KEY_MAX的定义有关,而这个定义,我的自定义内核已经修改,它引用的确是内核头文件。所以只要补丁被接受,这些ring3的APP重新编译就可以根上脚步
#include <linux/input.h>
#include <linux/joystick.h>
再试试evtest /dev/input/event3
Input device name: "QuickMake QMCP737C"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 288 (BTN_TRIGGER)
Event code 289 (BTN_THUMB)
Event code 290 (BTN_THUMB2)
Event code 291 (BTN_TOP)
Event code 292 (BTN_TOP2)
Event code 293 (BTN_PINKIE)
Event code 294 (BTN_BASE)
Event code 295 (BTN_BASE2)
Event code 296 (BTN_BASE3)
Event code 297 (BTN_BASE4)
Event code 298 (BTN_BASE5)
Event code 299 (BTN_BASE6)
Event code 300 (?)
Event code 301 (?)
Event code 302 (?)
Event code 303 (BTN_DEAD)
Event code 704 (BTN_TRIGGER_HAPPY1)
Event code 705 (BTN_TRIGGER_HAPPY2)
Event code 706 (BTN_TRIGGER_HAPPY3)
Event code 707 (BTN_TRIGGER_HAPPY4)
Event code 708 (BTN_TRIGGER_HAPPY5)
Event code 709 (BTN_TRIGGER_HAPPY6)
Event code 710 (BTN_TRIGGER_HAPPY7)
Event code 711 (BTN_TRIGGER_HAPPY8)
Event code 712 (BTN_TRIGGER_HAPPY9)
Event code 713 (BTN_TRIGGER_HAPPY10)
Event code 714 (BTN_TRIGGER_HAPPY11)
Event code 715 (BTN_TRIGGER_HAPPY12)
Event code 716 (BTN_TRIGGER_HAPPY13)
Event code 717 (BTN_TRIGGER_HAPPY14)
Event code 718 (BTN_TRIGGER_HAPPY15)
Event code 719 (BTN_TRIGGER_HAPPY16)
Event code 720 (BTN_TRIGGER_HAPPY17)
Event code 721 (BTN_TRIGGER_HAPPY18)
Event code 722 (BTN_TRIGGER_HAPPY19)
Event code 723 (BTN_TRIGGER_HAPPY20)
Event code 724 (BTN_TRIGGER_HAPPY21)
Event code 725 (BTN_TRIGGER_HAPPY22)
Event code 726 (BTN_TRIGGER_HAPPY23)
Event code 727 (BTN_TRIGGER_HAPPY24)
Event code 728 (BTN_TRIGGER_HAPPY25)
Event code 729 (BTN_TRIGGER_HAPPY26)
Event code 730 (BTN_TRIGGER_HAPPY27)
Event code 731 (BTN_TRIGGER_HAPPY28)
Event code 732 (BTN_TRIGGER_HAPPY29)
Event code 733 (BTN_TRIGGER_HAPPY30)
Event code 734 (BTN_TRIGGER_HAPPY31)
Event code 735 (BTN_TRIGGER_HAPPY32)
Event code 736 (BTN_TRIGGER_HAPPY33)
Event code 737 (BTN_TRIGGER_HAPPY34)
Event code 738 (BTN_TRIGGER_HAPPY35)
Event code 739 (BTN_TRIGGER_HAPPY36)
Event code 740 (BTN_TRIGGER_HAPPY37)
Event code 741 (BTN_TRIGGER_HAPPY38)
Event code 742 (BTN_TRIGGER_HAPPY39)
Event code 743 (BTN_TRIGGER_HAPPY40)
Event code 744 (?)
Event code 745 (?)
Event code 746 (?)
Event code 747 (?)
Event code 748 (?)
Event code 749 (?)
Event code 750 (?)
Event code 751 (?)
Event code 752 (?)
Event code 753 (?)
Event code 754 (?)
Event code 755 (?)
Event code 756 (?)
Event code 757 (?)
Event code 758 (?)
Event code 759 (?)
Event code 760 (?)
Event code 761 (?)
Event code 762 (?)
Event code 763 (?)
Event code 764 (?)
Event code 765 (?)
Event code 766 (?)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing ... (interrupt to exit)
Event: time 1594415568.341154, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90053
Event: time 1594415568.341154, type 1 (EV_KEY), code 770 (?), value 1
Event: time 1594415568.341154, -------------- SYN_REPORT ------------
Event: time 1594415568.927153, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90053
Event: time 1594415568.927153, type 1 (EV_KEY), code 770 (?), value 0
Event: time 1594415568.927153, -------------- SYN_REPORT ------------
Event: time 1594415594.110023, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90065
Event: time 1594415594.110023, type 1 (EV_KEY), code 788 (?), value 0
Event: time 1594415594.110023, -------------- SYN_REPORT ------------
Event: time 1594415594.129027, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90066
Event: time 1594415594.129027, type 1 (EV_KEY), code 789 (?), value 1
Event: time 1594415594.129027, -------------- SYN_REPORT ------------
Event: time 1594415594.200024, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90066
Event: time 1594415594.200024, type 1 (EV_KEY), code 789 (?), value 0
Event: time 1594415594.200024, -------------- SYN_REPORT ------------
Event: time 1594415594.263022, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90067
Event: time 1594415594.263022, type 1 (EV_KEY), code 790 (?), value 1
Event: time 1594415594.263022, -------------- SYN_REPORT ------------
Event: time 1594415594.366024, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90067
Event: time 1594415594.366024, type 1 (EV_KEY), code 790 (?), value 0
Event: time 1594415594.366024, -------------- SYN_REPORT ------------
Event: time 1594415594.413021, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90068
Event: time 1594415594.413021, type 1 (EV_KEY), code 791 (?), value 1
Event: time 1594415594.413021, -------------- SYN_REPORT ------------
Event: time 1594415596.471012, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90068
Event: time 1594415596.471012, type 1 (EV_KEY), code 791 (?), value 0
Event: time 1594415596.471012, -------------- SYN_REPORT ------------
Event: time 1594415596.532012, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90067
Event: time 1594415596.532012, type 1 (EV_KEY), code 790 (?), value 1
Event: time 1594415596.532012, -------------- SYN_REPORT ------------
Event: time 1594415596.660008, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90067
Event: time 1594415596.660008, type 1 (EV_KEY), code 790 (?), value 0
Event: time 1594415596.660008, -------------- SYN_REPORT ------------
Event: time 1594415596.785010, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90066
Event: time 1594415596.785010, type 1 (EV_KEY), code 789 (?), value 1
Event: time 1594415596.785010, -------------- SYN_REPORT ------------
Event: time 1594415596.819010, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90066
Event: time 1594415596.819010, type 1 (EV_KEY), code 789 (?), value 0
Event: time 1594415596.819010, -------------- SYN_REPORT ------------
Event: time 1594415596.884009, type 4 (EV_MSC), code 4 (MSC_SCAN), value 90065
Event: time 1594415596.884009, type 1 (EV_KEY), code 788 (?), value 1
Event: time 1594415596.884009, -------------- SYN_REPORT ------------
至少可以探测所有按键,而且evtest也不会崩溃