mirror of https://github.com/nirenjan/libx52.git
Report X52 buttons in order
While the original idea was to have a consistent reporting order between the X52 and X52 Pro, it causes issues in applications like Wine. This commit updates the reporting such that it sends the exact same report as the kernel with the quirks enabled. Addresses: #51report-buttons-in-order
parent
fe023ffc65
commit
19b76cd8f6
|
@ -53,163 +53,35 @@ static void _parse_axis_report(struct input_dev *input_dev,
|
|||
input_report_abs(input_dev, ABS_Z, data[4]);
|
||||
input_report_abs(input_dev, ABS_RX, data[5]);
|
||||
input_report_abs(input_dev, ABS_RY, data[6]);
|
||||
input_report_abs(input_dev, ABS_MISC, data[7]);
|
||||
input_report_abs(input_dev, ABS_THROTTLE, data[7]);
|
||||
|
||||
/* Mouse stick is always the last byte of the report */
|
||||
input_report_abs(input_dev, ABS_TILT_X, data[len-1] & 0xf);
|
||||
input_report_abs(input_dev, ABS_TILT_Y, data[len-1] >> 4);
|
||||
input_report_abs(input_dev, ABS_MISC, data[len-1] & 0xf);
|
||||
input_report_abs(input_dev, ABS_MISC+1, data[len-1] >> 4);
|
||||
|
||||
/* Hat is always the upper nibble of the penultimate byte of the report */
|
||||
input_report_abs(input_dev, ABS_HAT0X, hat_to_axis[hat][0]);
|
||||
input_report_abs(input_dev, ABS_HAT0Y, hat_to_axis[hat][1]);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* Mapping buttons
|
||||
* ===============
|
||||
*
|
||||
* The X52 and X52 Pro report the buttons in different orders. In order
|
||||
* to let a userspace application handle them in a generic fashion, we
|
||||
* define a map for buttons to BTN_* defines, so that one button (eg. clutch)
|
||||
* will send the same ID on both X52 and X52 Pro
|
||||
*
|
||||
* The map is defined below.
|
||||
**********************************************************************
|
||||
*/
|
||||
#define X52_TRIGGER_1 BTN_TRIGGER_HAPPY1
|
||||
#define X52_TRIGGER_2 BTN_TRIGGER_HAPPY2
|
||||
#define X52_BTN_FIRE BTN_TRIGGER_HAPPY3
|
||||
#define X52_BTN_A BTN_TRIGGER_HAPPY4
|
||||
#define X52_BTN_B BTN_TRIGGER_HAPPY5
|
||||
#define X52_BTN_C BTN_TRIGGER_HAPPY6
|
||||
#define X52_BTN_D BTN_TRIGGER_HAPPY7
|
||||
#define X52_BTN_E BTN_TRIGGER_HAPPY8
|
||||
#define X52_BTN_PINKIE BTN_TRIGGER_HAPPY9
|
||||
#define X52_BTN_T1_UP BTN_TRIGGER_HAPPY10
|
||||
#define X52_BTN_T1_DN BTN_TRIGGER_HAPPY11
|
||||
#define X52_BTN_T2_UP BTN_TRIGGER_HAPPY12
|
||||
#define X52_BTN_T2_DN BTN_TRIGGER_HAPPY13
|
||||
#define X52_BTN_T3_UP BTN_TRIGGER_HAPPY14
|
||||
#define X52_BTN_T3_DN BTN_TRIGGER_HAPPY15
|
||||
#define X52_BTN_CLUTCH BTN_TRIGGER_HAPPY16
|
||||
#define X52_MOUSE_LEFT BTN_TRIGGER_HAPPY17
|
||||
#define X52_MOUSE_RIGHT BTN_TRIGGER_HAPPY18
|
||||
#define X52_MOUSE_FORWARD BTN_TRIGGER_HAPPY19
|
||||
#define X52_MOUSE_BACKWARD BTN_TRIGGER_HAPPY20
|
||||
#define X52_STICK_POV_N BTN_TRIGGER_HAPPY21
|
||||
#define X52_STICK_POV_E BTN_TRIGGER_HAPPY22
|
||||
#define X52_STICK_POV_S BTN_TRIGGER_HAPPY23
|
||||
#define X52_STICK_POV_W BTN_TRIGGER_HAPPY24
|
||||
#define X52_THROT_POV_N BTN_TRIGGER_HAPPY25
|
||||
#define X52_THROT_POV_E BTN_TRIGGER_HAPPY26
|
||||
#define X52_THROT_POV_S BTN_TRIGGER_HAPPY27
|
||||
#define X52_THROT_POV_W BTN_TRIGGER_HAPPY28
|
||||
#define X52_MODE_1 BTN_TRIGGER_HAPPY29
|
||||
#define X52_MODE_2 BTN_TRIGGER_HAPPY30
|
||||
#define X52_MODE_3 BTN_TRIGGER_HAPPY31
|
||||
#define X52_BTN_FUNCTION BTN_TRIGGER_HAPPY32
|
||||
#define X52_BTN_START_STOP BTN_TRIGGER_HAPPY33
|
||||
#define X52_BTN_RESET BTN_TRIGGER_HAPPY34
|
||||
#define X52_BTN_PG_UP BTN_TRIGGER_HAPPY35
|
||||
#define X52_BTN_PG_DN BTN_TRIGGER_HAPPY36
|
||||
#define X52_BTN_UP BTN_TRIGGER_HAPPY37
|
||||
#define X52_BTN_DN BTN_TRIGGER_HAPPY38
|
||||
#define X52_BTN_MFD_SELECT BTN_TRIGGER_HAPPY39
|
||||
|
||||
static void _parse_button_report(struct input_dev *input_dev,
|
||||
int is_pro, u8 *data, int num_buttons)
|
||||
{
|
||||
int i;
|
||||
int idx;
|
||||
int btn;
|
||||
|
||||
// Map X52 buttons from report to fixed button ID
|
||||
// This should be defined in the order provided in the report.
|
||||
static const int x52_buttons[] = {
|
||||
X52_TRIGGER_1,
|
||||
X52_BTN_FIRE,
|
||||
X52_BTN_A,
|
||||
X52_BTN_B,
|
||||
X52_BTN_C,
|
||||
X52_BTN_PINKIE,
|
||||
X52_BTN_D,
|
||||
X52_BTN_E,
|
||||
X52_BTN_T1_UP,
|
||||
X52_BTN_T1_DN,
|
||||
X52_BTN_T2_UP,
|
||||
X52_BTN_T2_DN,
|
||||
X52_BTN_T3_UP,
|
||||
X52_BTN_T3_DN,
|
||||
X52_TRIGGER_2,
|
||||
X52_STICK_POV_N,
|
||||
X52_STICK_POV_E,
|
||||
X52_STICK_POV_S,
|
||||
X52_STICK_POV_W,
|
||||
X52_THROT_POV_N,
|
||||
X52_THROT_POV_E,
|
||||
X52_THROT_POV_S,
|
||||
X52_THROT_POV_W,
|
||||
X52_MODE_1,
|
||||
X52_MODE_2,
|
||||
X52_MODE_3,
|
||||
X52_BTN_FUNCTION,
|
||||
X52_BTN_START_STOP,
|
||||
X52_BTN_RESET,
|
||||
X52_BTN_CLUTCH,
|
||||
X52_MOUSE_LEFT,
|
||||
X52_MOUSE_RIGHT,
|
||||
X52_MOUSE_FORWARD,
|
||||
X52_MOUSE_BACKWARD,
|
||||
};
|
||||
|
||||
static const int pro_buttons[] = {
|
||||
X52_TRIGGER_1,
|
||||
X52_BTN_FIRE,
|
||||
X52_BTN_A,
|
||||
X52_BTN_B,
|
||||
X52_BTN_C,
|
||||
X52_BTN_PINKIE,
|
||||
X52_BTN_D,
|
||||
X52_BTN_E,
|
||||
X52_BTN_T1_UP,
|
||||
X52_BTN_T1_DN,
|
||||
X52_BTN_T2_UP,
|
||||
X52_BTN_T2_DN,
|
||||
X52_BTN_T3_UP,
|
||||
X52_BTN_T3_DN,
|
||||
X52_TRIGGER_2,
|
||||
X52_MOUSE_LEFT,
|
||||
X52_MOUSE_FORWARD,
|
||||
X52_MOUSE_BACKWARD,
|
||||
X52_MOUSE_RIGHT,
|
||||
X52_STICK_POV_N,
|
||||
X52_STICK_POV_E,
|
||||
X52_STICK_POV_S,
|
||||
X52_STICK_POV_W,
|
||||
X52_THROT_POV_N,
|
||||
X52_THROT_POV_E,
|
||||
X52_THROT_POV_S,
|
||||
X52_THROT_POV_W,
|
||||
X52_MODE_1,
|
||||
X52_MODE_2,
|
||||
X52_MODE_3,
|
||||
X52_BTN_CLUTCH,
|
||||
X52_BTN_FUNCTION,
|
||||
X52_BTN_START_STOP,
|
||||
X52_BTN_RESET,
|
||||
X52_BTN_PG_UP,
|
||||
X52_BTN_PG_DN,
|
||||
X52_BTN_UP,
|
||||
X52_BTN_DN,
|
||||
X52_BTN_MFD_SELECT,
|
||||
};
|
||||
|
||||
const int *btn_map = is_pro ? pro_buttons : x52_buttons ;
|
||||
int report_button;
|
||||
|
||||
for (i = 0; i < num_buttons; i++) {
|
||||
idx = 8 + (i / BITS_PER_BYTE);
|
||||
btn = !!(data[idx] & (1 << (i % BITS_PER_BYTE)));
|
||||
input_report_key(input_dev, btn_map[i], btn);
|
||||
if (i <= 0xf) {
|
||||
report_button = BTN_JOYSTICK + i;
|
||||
} else {
|
||||
report_button = BTN_TRIGGER_HAPPY + i - 0x10;
|
||||
}
|
||||
|
||||
input_report_key(input_dev, report_button, btn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -267,30 +139,27 @@ static int x52_input_configured(struct hid_device *dev,
|
|||
set_bit(EV_KEY, input_dev->evbit);
|
||||
set_bit(EV_ABS, input_dev->evbit);
|
||||
|
||||
/*
|
||||
* X52 has only 34 buttons, X52 Pro has 39. The first 34 buttons are common
|
||||
* although the button order differs between the two.
|
||||
*/
|
||||
// X52 has only 34 buttons, X52 Pro has 39.
|
||||
max_btn = is_pro ? 39 : 34 ;
|
||||
|
||||
for (i = 0; i < max_btn; i++) {
|
||||
set_bit(BTN_TRIGGER_HAPPY1 + i, input_dev->keybit);
|
||||
for (i = 0; i < 0x10; i++) {
|
||||
set_bit(BTN_JOYSTICK + i, input_dev->keybit);
|
||||
}
|
||||
for (i = 0x10; i < max_btn; i++) {
|
||||
set_bit(BTN_TRIGGER_HAPPY + i - 0x10, input_dev->keybit);
|
||||
}
|
||||
|
||||
/* Both X52 and X52 Pro have the same number of axes, only the ranges vary */
|
||||
|
||||
set_bit(ABS_X, input_dev->absbit);
|
||||
set_bit(ABS_Y, input_dev->absbit);
|
||||
set_bit(ABS_Z, input_dev->absbit);
|
||||
set_bit(ABS_RX, input_dev->absbit);
|
||||
set_bit(ABS_RY, input_dev->absbit);
|
||||
set_bit(ABS_RZ, input_dev->absbit);
|
||||
set_bit(ABS_RZ, input_dev->absbit);
|
||||
set_bit(ABS_THROTTLE, input_dev->absbit);
|
||||
set_bit(ABS_HAT0X, input_dev->absbit);
|
||||
set_bit(ABS_HAT0Y, input_dev->absbit);
|
||||
set_bit(ABS_TILT_X, input_dev->absbit);
|
||||
set_bit(ABS_TILT_Y, input_dev->absbit);
|
||||
set_bit(ABS_MISC, input_dev->absbit);
|
||||
set_bit(ABS_MISC+1, input_dev->absbit);
|
||||
|
||||
max_stick = is_pro ? 1023 : 2047;
|
||||
input_set_abs_params(input_dev, ABS_X, 0, max_stick, max_stick >> 8, max_stick >> 4);
|
||||
|
@ -299,11 +168,11 @@ static int x52_input_configured(struct hid_device *dev,
|
|||
input_set_abs_params(input_dev, ABS_RX, 0, 255, 0, 15);
|
||||
input_set_abs_params(input_dev, ABS_RY, 0, 255, 0, 15);
|
||||
input_set_abs_params(input_dev, ABS_Z, 0, 255, 0, 15);
|
||||
input_set_abs_params(input_dev, ABS_MISC, 0, 255, 0, 15);
|
||||
input_set_abs_params(input_dev, ABS_THROTTLE, 0, 255, 0, 15);
|
||||
input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
|
||||
input_set_abs_params(input_dev, ABS_HAT0Y, -1, 1, 0, 0);
|
||||
input_set_abs_params(input_dev, ABS_TILT_X, 0, 15, 0, 0);
|
||||
input_set_abs_params(input_dev, ABS_TILT_Y, 0, 15, 0, 0);
|
||||
input_set_abs_params(input_dev, ABS_MISC, 0, 15, 0, 0);
|
||||
input_set_abs_params(input_dev, ABS_MISC+1, 0, 15, 0, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue