Skip to content

Commit

Permalink
[WIP] xpadneo, deadzones: Implement our own smooth dead zone
Browse files Browse the repository at this point in the history
This commit sets flatness to zero to let us calculate the dead zone by
scaling the axis value instead of jumping out of it. The dead zone is
implemented as a smooth axial dead zone.

We also need to set fuzz to 0, otherwise `joydev` doesn't always return
to the center.

See-also: atar-axis#231
Signed-off-by: Kai Krakow <[email protected]>
  • Loading branch information
kakra committed Jul 17, 2020
1 parent 79c5428 commit e6d1cbb
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -942,10 +942,10 @@ static int xpadneo_input_configured(struct hid_device *hdev, struct hid_input *h

if (param_gamepad_compliance) {
hid_info(hdev, "enabling compliance with Linux Gamepad Specification\n");
input_set_abs_params(xdata->idev, ABS_X, -32768, 32767, 7, 4095);
input_set_abs_params(xdata->idev, ABS_Y, -32768, 32767, 7, 4095);
input_set_abs_params(xdata->idev, ABS_RX, -32768, 32767, 7, 4095);
input_set_abs_params(xdata->idev, ABS_RY, -32768, 32767, 7, 4095);
input_set_abs_params(xdata->idev, ABS_X, -32768, 32767, 0, 0);
input_set_abs_params(xdata->idev, ABS_Y, -32768, 32767, 0, 0);
input_set_abs_params(xdata->idev, ABS_RX, -32768, 32767, 0, 0);
input_set_abs_params(xdata->idev, ABS_RY, -32768, 32767, 0, 0);
}

/* combine triggers to form a rudder, use ABS_MISC to order after dpad */
Expand All @@ -954,8 +954,20 @@ static int xpadneo_input_configured(struct hid_device *hdev, struct hid_input *h
return 0;
}

static void xpadneo_report_abs(struct xpadneo_devdata *xdata, unsigned int code, int value) {
unsigned int offset = 0;
static inline s32 scale_axis(s32 value, s32 zone) {
if (abs(value) < zone) {
value = 0;
} else {
s32 cleaned = (value < 0 ? value + zone : value - zone);
s32 scaled = 32767 * cleaned / (32767 - zone);
value = clamp(scaled, -32768, 32767);
}
return value;
}

static void xpadneo_report_abs(struct xpadneo_devdata *xdata, unsigned int code, s32 value) {
s32 offset = 0;
static u32 deadzone = 2560;

switch (code) {
case ABS_X:
Expand All @@ -972,18 +984,22 @@ static void xpadneo_report_abs(struct xpadneo_devdata *xdata, unsigned int code,
switch (code) {
case ABS_X:
xdata->abs.x = value;
value = scale_axis(value, deadzone);
break;
case ABS_Y:
xdata->abs.y = value;
value = scale_axis(value, deadzone);
break;
case ABS_Z:
xdata->abs.z = value;
break;
case ABS_RX:
xdata->abs.rx = value;
value = scale_axis(value, deadzone);
break;
case ABS_RY:
xdata->abs.ry = value;
value = scale_axis(value, deadzone);
break;
case ABS_RZ:
xdata->abs.rz = value;
Expand Down

0 comments on commit e6d1cbb

Please sign in to comment.