From f55e5a643139f85a4a8ae8cd74456e7706f4fe01 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Sat, 2 May 2020 03:09:10 +0200 Subject: [PATCH] hid-xpadneo: Re-arrange the order evaluations This puts the evaluation for rumble effects into a more natural order for keeping the follow-up patch simpler and easier to understand. --- hid-xpadneo/src/hid-xpadneo.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/hid-xpadneo/src/hid-xpadneo.c b/hid-xpadneo/src/hid-xpadneo.c index 1ec7e7e0..df855631 100644 --- a/hid-xpadneo/src/hid-xpadneo.c +++ b/hid-xpadneo/src/hid-xpadneo.c @@ -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} @@ -286,12 +299,6 @@ 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; @@ -299,12 +306,6 @@ static int xpadneo_ff_play(struct input_dev *dev, void *data, 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,