Skip to content

Commit

Permalink
removed trigger ff for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
atar-axis committed Jul 29, 2019
1 parent f0035c0 commit c05572d
Showing 1 changed file with 10 additions and 66 deletions.
76 changes: 10 additions & 66 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ struct xpadneo_devdata {
/* axis states */
s32 last_abs_z;
s32 last_abs_rz;

/* buffer and worker for ff report */
struct work_struct ff_worker;
void *output_report_dmabuf;
};


Expand Down Expand Up @@ -233,27 +237,14 @@ static int xpadneo_ff_play(struct input_dev *dev, void *data,
*/

struct ff_report ff_pck;
u16 weak, strong, direction, max, max_damped;
u8 mag_main_right, mag_main_left, mag_trigger_right, mag_trigger_left;
u16 weak, strong;
u8 mag_main_right, mag_main_left;
u8 ff_active;

const int fractions_milli[]
= {1000, 962, 854, 691, 500, 309, 146, 38, 0};
const int proportions_idx_max = 8;
u8 index_left, index_right;
int fraction_TL, fraction_TR;
u8 trigger_rumble_damping_nonzero;

int ret = 0;

enum {
DIRECTION_DOWN = 0x0000,
DIRECTION_LEFT = 0x4000,
DIRECTION_UP = 0x8000,
DIRECTION_RIGHT = 0xC000,
};


struct hid_device *hdev = input_get_drvdata(dev);

if (param_disable_ff == PARAM_DISABLE_FF_ALL)
Expand All @@ -265,72 +256,25 @@ static int xpadneo_ff_play(struct input_dev *dev, void *data,
/* copy data from effect structure at the very beginning */
weak = effect->u.rumble.weak_magnitude;
strong = effect->u.rumble.strong_magnitude;
direction = effect->direction;

hid_dbg_lvl(DBG_LVL_FEW, hdev, "playing effect: strong: %#04x, weak: %#04x, direction: %#04x\n",
strong, weak, direction);
hid_dbg_lvl(DBG_LVL_FEW, hdev, "playing effect: strong: %#04x, weak: %#04x\n",
strong, weak);

/* calculate the physical magnitudes */
mag_main_right = (u8)((weak & 0xFF00) >> 8); /* u16 to u8 */
mag_main_left = (u8)((strong & 0xFF00) >> 8); /* u16 to u8 */


/* get the proportions from a precalculated cosine table
* calculation goes like:
* cosine(a) * 1000 = {1000, 924, 707, 383, 0, -383, -707, -924, -1000}
* fractions_milli(a) = (1000 + (cosine * 1000)) / 2
*/

fraction_TL = 0;
fraction_TR = 0;

if (direction >= DIRECTION_LEFT && direction <= DIRECTION_RIGHT) {
index_left = (direction - DIRECTION_LEFT) >> 12;
index_right = proportions_idx_max - index_left;

fraction_TL = fractions_milli[index_left];
fraction_TR = fractions_milli[index_right];
}

/* we want to keep the rumbling at the triggers below the maximum
* of the weak and strong main rumble
*/
max = mag_main_right > mag_main_left ? mag_main_right : mag_main_left;

/* the user can change the damping at runtime, hence check the range */
trigger_rumble_damping_nonzero
= param_trigger_rumble_damping == 0 ? 1 : param_trigger_rumble_damping;

max_damped = max / trigger_rumble_damping_nonzero;

mag_trigger_left = (u8)((max_damped * fraction_TL) / 1000);
mag_trigger_right = (u8)((max_damped * fraction_TR) / 1000);


ff_active = FF_ENABLE_ALL;

if (param_disable_ff & PARAM_DISABLE_FF_TRIGGER)
ff_active &= ~(FF_ENABLE_LEFT_TRIGGER | FF_ENABLE_RIGHT_TRIGGER);

if (param_disable_ff & PARAM_DISABLE_FF_MAIN)
ff_active &= ~(FF_ENABLE_LEFT | FF_ENABLE_RIGHT);

ff_active &= ~(FF_ENABLE_LEFT_TRIGGER | FF_ENABLE_RIGHT_TRIGGER);

create_ff_pck(
&ff_pck, 0x03,
ff_active,
mag_trigger_left, mag_trigger_right,
0x00, 0x00,
mag_main_left, mag_main_right,
0);


hid_dbg_lvl(DBG_LVL_FEW, hdev,
"active: %#04x, max: %#04x, prop_left: %#04x, prop_right: %#04x, left trigger: %#04x, right: %#04x\n",
ff_active,
max, fraction_TL, fraction_TR,
ff_pck.ff.magnitude_left_trigger,
ff_pck.ff.magnitude_right_trigger);

ret = hid_hw_output_report(hdev, (u8 *)&ff_pck, sizeof(ff_pck));
hid_dbg_lvl(DBG_LVL_FEW, hdev, "hid_hw_output_report returned with %d\n", ret);

Expand Down

1 comment on commit c05572d

@kakra
Copy link
Collaborator

@kakra kakra commented on c05572d May 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this change anything? I was also thinking about disabling it to see if it changes anything. Maybe related to #189

Please sign in to comment.