Adjust emulated rumble strength (#1288)

This commit is contained in:
Alek Lefebvre
2024-01-19 19:12:21 -06:00
committed by GitHub
parent 3aab9eb13b
commit dbf1b88a3d
5 changed files with 35 additions and 7 deletions
@@ -2121,7 +2121,16 @@ public class ControllerHandler implements InputManager.InputDeviceListener, UsbD
else if (foundMatchingDevice && !vibrated && prefConfig.vibrateFallbackToDevice) {
// We found a device to vibrate but it didn't have rumble support. The user
// has requested us to vibrate the device in this case.
rumbleSingleVibrator(deviceVibrator, lowFreqMotor, highFreqMotor);
// We cast the unsigned short value to a signed int before multiplying by
// the preferred strength. The resulting value is capped at 65534 before
// we cast it back to a short so it doesn't go above 100%.
short lowFreqMotorAdjusted = (short)(Math.min((((lowFreqMotor & 0xffff)
* prefConfig.vibrateFallbackToDeviceStrength) / 100), Short.MAX_VALUE*2));
short highFreqMotorAdjusted = (short)(Math.min((((highFreqMotor & 0xffff)
* prefConfig.vibrateFallbackToDeviceStrength) / 100), Short.MAX_VALUE*2));
rumbleSingleVibrator(deviceVibrator, lowFreqMotorAdjusted, highFreqMotorAdjusted);
}
}
}