Skip to content

Commit

Permalink
combined_z_axis: combine triggers to form a single Z axis (atar-axis#67)
Browse files Browse the repository at this point in the history
* first implementation of combine_triggers

* v0.5.2

* changed version dummy back to @DO_NOT_CHANGE@

* fixed update script

* fixed fuzz and flat for ABS_Z

* renamed parameter to combine_z_axis

* renamed parameter to combined_z_axis and updated README

* disable combined_z_axis by default
  • Loading branch information
atar-axis authored Jan 4, 2019
1 parent 2e32493 commit 95398bf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION="0.5.1"
VERSION="0.5.2"
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ files in `/sys/module/hid_xpadneo/parameters`:
* `fake_dev_version` (default `0x1130`)
* Fake the input device version to the given value (to prevent SDL from applying another mapping, see below)
* Values from `1` to `0xFFFF` are handled as a version number, `0` will retain the original version
* `combined_z_axis` (default `0´)
* Combine the triggers (`ABS_Z` and `ABS_RZ`) to form a single axis `ABS_Z` which is used e.g. in flight simulators
* The left and right trigger will work against each other.

#### Example
To set the highest level of debug verbosity, run
Expand Down
31 changes: 31 additions & 0 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ static bool disable_ff;
module_param(disable_ff, bool, 0644);
MODULE_PARM_DESC(disable_ff, "(bool) Disable all force-feedback effects (rumble). 1: disable ff, 0: enable ff.");

static bool combined_z_axis;
module_param(combined_z_axis, bool, 0644);
MODULE_PARM_DESC(combined_z_axis, "(bool) Combine the triggers to form a single axis. 1: combine, 0: do not combine");

static u8 trigger_rumble_damping = 4;
module_param(trigger_rumble_damping, byte, 0644);
MODULE_PARM_DESC(trigger_rumble_damping, "(u8) Damp the trigger: 1 (none) to 2^8+ (max)");
Expand Down Expand Up @@ -1010,9 +1014,17 @@ static int xpadneo_input_configured(struct hid_device *hdev,
input_set_abs_params(xdata->idev, ABS_RX, -32768, 32767, 255, 4095);
input_set_abs_params(xdata->idev, ABS_RY, -32768, 32767, 255, 4095);

if (combined_z_axis)
input_set_abs_params(xdata->idev, ABS_Z, -1024, 1023, 3, 63);

// furthermore, we need to translate the incoming events to fit within
// the new range, we will do that in the xpadneo_event() hook.

// We remove the ABS_RZ event if combined_z_axis is enabled
if (combined_z_axis) {
__clear_bit(ABS_RZ, xdata->idev->absbit);
}

return 0;
}

Expand Down Expand Up @@ -1040,6 +1052,9 @@ int xpadneo_event(struct hid_device *hdev, struct hid_field *field,
struct xpadneo_devdata *xdata = hid_get_drvdata(hdev);
struct input_dev *idev = xdata->idev;

static int last_abs_z = 0;
static int last_abs_rz = 0;


hid_dbg_lvl(DBG_LVL_ALL, hdev,
"hid-up: %02x, hid-usg: %02x, input-code: %02x, value: %02x\n",
Expand All @@ -1049,6 +1064,8 @@ int xpadneo_event(struct hid_device *hdev, struct hid_field *field,

// we have to shift the range of the analogues sticks (ABS_X/Y/RX/RY)
// as already explained in xpadneo_input_configured() above
// furthermore we need to combine ABS_Z and ABS_RZ if combined_z_axis
// is set

u16 usg_type = usage->type;
u16 usg_code = usage->code;
Expand All @@ -1060,8 +1077,22 @@ int xpadneo_event(struct hid_device *hdev, struct hid_field *field,
input_report_abs(idev, usg_code, value - 32768);
goto sync_and_stop_processing;
}

if (combined_z_axis) {
if (usg_code == ABS_Z || usg_code == ABS_RZ) {
if (usg_code == ABS_Z)
last_abs_z = value;
if (usg_code == ABS_RZ)
last_abs_rz = value;

input_report_abs(idev, ABS_Z, -last_abs_z +last_abs_rz);
goto sync_and_stop_processing;
}
}
}




/* TODO:
* This is a workaround for the wrong report (Windows report but
Expand Down
2 changes: 1 addition & 1 deletion update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ if [[ $LATEST == $VERSION ]]; then
else

if [[ $IS_GIT == "true" ]]; then
echo "Please update this directory by running `git reset --hard` and `git pull`, afterwards run this script again"
echo "Please update this directory by running 'git reset --hard' and 'git pull', afterwards run this script again"
else
echo "Please update this directory by downloading the latest version from https://github.com/atar-axis/xpadneo/archive/master.zip"
fi
Expand Down

0 comments on commit 95398bf

Please sign in to comment.