Skip to content

Commit

Permalink
xpadneo, profiles: Report current profile as depressed button
Browse files Browse the repository at this point in the history
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: atar-axis#428
Signed-off-by: Kai Krakow <kai@kaishome.de>
  • Loading branch information
kakra committed Apr 22, 2024
1 parent 2f77207 commit e641e48
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 15 additions & 0 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,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;
}

Expand Down Expand Up @@ -1026,6 +1033,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;
}

Expand Down
9 changes: 5 additions & 4 deletions hid-xpadneo/src/xpadneo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -152,7 +153,7 @@ struct xpadneo_devdata {

/* profile switching */
bool xbox_button_down, profile_switched;
u8 profile;
u8 last_profile, profile;

/* mouse mode */
bool mouse_mode;
Expand Down

0 comments on commit e641e48

Please sign in to comment.