Skip to content

Commit

Permalink
hid-xpadneo: Re-arrange the order evaluations
Browse files Browse the repository at this point in the history
This puts the evaluation for rumble effects into a more natural order
for keeping the follow-up patch simpler and easier to understand.
  • Loading branch information
kakra committed May 3, 2020
1 parent febfe30 commit f55e5a6
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions hid-xpadneo/src/hid-xpadneo.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ static int xpadneo_ff_play(struct input_dev *dev, void *data,
mag_main_right = (u8)((weak * 100) / 0xFFFF); /* scale from 16 bit to 0..100 */
mag_main_left = (u8)((strong * 100) / 0xFFFF); /* scale from 16 bit to 0..100 */

/* 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;
max_unscaled = weak > strong ? weak : strong;

/* the user can disable some rumble motors */
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);

/* get the proportions from a precalculated cosine table
* calculation goes like:
* cosine(a) * 1000 = {100, 96, 85, 69, 50, 31, 15, 4, 0, 4, 15, 31, 50, 69, 85, 96, 100}
Expand All @@ -286,25 +299,13 @@ static int xpadneo_ff_play(struct input_dev *dev, void *data,
fraction_TR = fractions_percent[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;
max_unscaled = weak > strong ? weak : strong;

/* 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_unscaled / trigger_rumble_damping_nonzero;
mag_trigger_left = (u8)((max_damped * fraction_TL) / 0xFFFF);
mag_trigger_right = (u8)((max_damped * fraction_TR) / 0xFFFF);

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);

create_ff_pck(
&ff_pck, 0x03,
ff_active,
Expand Down

0 comments on commit f55e5a6

Please sign in to comment.