From 8386f27a0389478af0db488d2fdf8c661e31a448 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Wed, 14 Jun 2023 01:32:15 +0200 Subject: [PATCH] xpadneo, profiles: Report current profile as depressed button This way, user-space can figure out which profile currently is configured. Take note that this may also involve a different button mapping, and only profile 0 has paddles forcibly reported as their distinct events (otherwise mapped to A, B, X, and Y by default). Link: https://github.com/atar-axis/xpadneo/issues/428 Signed-off-by: Kai Krakow --- hid-xpadneo/src/hid-xpadneo.c | 15 +++++++++++++++ hid-xpadneo/src/xpadneo.h | 9 +++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/hid-xpadneo/src/hid-xpadneo.c b/hid-xpadneo/src/hid-xpadneo.c index 8b119c9b..b6200901 100644 --- a/hid-xpadneo/src/hid-xpadneo.c +++ b/hid-xpadneo/src/hid-xpadneo.c @@ -894,6 +894,13 @@ static int xpadneo_input_configured(struct hid_device *hdev, struct hid_input *h __set_bit(BTN_PADDLES(3), xdata->gamepad->keybit); } + /* expose current profile as buttons */ + __set_bit(BTN_PROFILES(0), xdata->gamepad->keybit); + __set_bit(BTN_PROFILES(1), xdata->gamepad->keybit); + __set_bit(BTN_PROFILES(2), xdata->gamepad->keybit); + __set_bit(BTN_PROFILES(3), xdata->gamepad->keybit); + input_report_key(xdata->gamepad, BTN_PROFILES(0), 1); + return 0; } @@ -1008,6 +1015,14 @@ static int xpadneo_event(struct hid_device *hdev, struct hid_field *field, } stop_processing: + /* report the profile change */ + if (xdata->last_profile != xdata->profile) { + if (xdata->last_profile < 4) + input_report_key(gamepad, BTN_PROFILES(xdata->last_profile), 0); + input_report_key(gamepad, BTN_PROFILES(xdata->profile), 1); + xdata->last_profile = xdata->profile; + } + return 1; } diff --git a/hid-xpadneo/src/xpadneo.h b/hid-xpadneo/src/xpadneo.h index c01e98da..18687bf9 100644 --- a/hid-xpadneo/src/xpadneo.h +++ b/hid-xpadneo/src/xpadneo.h @@ -48,9 +48,10 @@ do { \ } while (0) /* button aliases */ -#define BTN_PADDLES(b) (BTN_TRIGGER_HAPPY5+(b)) -#define BTN_SHARE KEY_F12 -#define BTN_XBOX BTN_MODE +#define BTN_PROFILES(b) (BTN_TRIGGER_HAPPY33+(b)) +#define BTN_PADDLES(b) (BTN_TRIGGER_HAPPY5+(b)) +#define BTN_SHARE KEY_F12 +#define BTN_XBOX BTN_MODE /* module parameter "trigger_rumble_mode" */ #define PARAM_TRIGGER_RUMBLE_PRESSURE 0 @@ -149,7 +150,7 @@ struct xpadneo_devdata { /* profile switching */ bool xbox_button_down, profile_switched; - u8 profile; + u8 last_profile, profile; /* mouse mode */ bool mouse_mode;