From abadfb137bc4e73a011d8312239b70544c5fe0cb Mon Sep 17 00:00:00 2001 From: mika-n Date: Sun, 13 Jan 2019 21:25:42 +0200 Subject: [PATCH] Fine tuning vJoy output feeder --- DS4Windows/DS4Control/Mapping.cs | 11 ++++--- DS4Windows/VJoyFeeder/vJoyFeeder.cs | 48 +++++++++++++++++------------ 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs index 18779dd..3673ab1 100644 --- a/DS4Windows/DS4Control/Mapping.cs +++ b/DS4Windows/DS4Control/Mapping.cs @@ -4128,28 +4128,29 @@ namespace DS4Windows result = Mapping.ClampInt(maxRangeLeft, result, maxRangeRight); + // Debug log output of SA sensor values //LogToGuiSACalibrationDebugMsg($"DEBUG gyro=({gyroAccelX}, {gyroAccelZ}) gyroPitchRollYaw=({currentDeviceState.Motion.gyroPitch}, {currentDeviceState.Motion.gyroRoll}, {currentDeviceState.Motion.gyroYaw}) gyroPitchRollYaw=({currentDeviceState.Motion.angVelPitch}, {currentDeviceState.Motion.angVelRoll}, {currentDeviceState.Motion.angVelYaw}) angle={result / (1.0 * C_WHEEL_ANGLE_PRECISION)} fullTurns={controller.wheelFullTurnCount}", false); // Scale input to a raw x360 16bit output scale, except if output axis of steering wheel emulation is L2+R2 trigger axis. - // L2+R2 triggers use independent 8bit values, so use -255..0..+255 scaled values (therefore L2+R2 Trigger axis supports only 360 turn range) switch(Global.getSASteeringWheelEmulationAxis(device)) { case SASteeringWheelEmulationAxisType.LX: case SASteeringWheelEmulationAxisType.LY: case SASteeringWheelEmulationAxisType.RX: case SASteeringWheelEmulationAxisType.RY: - // DS4 Stick axis values with configurable range + // DS4 thumbstick axis output (-32768..32767 raw value range) return (((result - maxRangeLeft) * (32767 - (-32768))) / (maxRangeRight - maxRangeLeft)) + (-32768); case SASteeringWheelEmulationAxisType.L2R2: - // DS4 Trigger axis values with fixed 360 range + // DS4 Trigger axis output. L2+R2 triggers share the same axis in x360 xInput/DInput controller, + // so L2+R2 steering output supports only 360 turn range (-255..255 raw value range in the shared trigger axis) result = Convert.ToInt32(Math.Round(result / (1.0 * C_WHEEL_ANGLE_PRECISION))); if (result < 0) result = -181 - result; return (((result - (-180)) * (255 - (-255))) / (180 - (-180))) + (-255); default: - // VJoy axis values with configurable range - return (((result - maxRangeLeft) * (32767 - (-0))) / (maxRangeRight - maxRangeLeft)) + (-0); + // SASteeringWheelEmulationAxisType.VJoy1X/VJoy1Y/VJoy1Z/VJoy2X/VJoy2Y/VJoy2Z VJoy axis output (0..32767 raw value range by default) + return (((result - maxRangeLeft) * (32767 - (-0))) / (maxRangeRight - maxRangeLeft)) + (-0); } } } diff --git a/DS4Windows/VJoyFeeder/vJoyFeeder.cs b/DS4Windows/VJoyFeeder/vJoyFeeder.cs index f44a37c..8304cbb 100644 --- a/DS4Windows/VJoyFeeder/vJoyFeeder.cs +++ b/DS4Windows/VJoyFeeder/vJoyFeeder.cs @@ -653,36 +653,44 @@ namespace DS4Windows.VJoyFeeder vJoyInitialized = true; AppLogger.LogToGui("Initializing VJoy virtual joystick driver via vJoyInterface.dll interface", false); - if (vJoyObj == null) vJoyObj = new vJoy(); - - if (vJoyObj.vJoyEnabled() && vJoyObj.GetVJDAxisExist(vJoyID, axis)) + try { - AppLogger.LogToGui("Connection to VJoy virtual joystick established", false); - AppLogger.LogToGui($"VJoy driver. Vendor={vJoyObj.GetvJoyManufacturerString()} Product={vJoyObj.GetvJoyProductString()} Version={vJoyObj.GetvJoySerialNumberString()} Device#={vJoyID} Axis={axis}", false); + if (vJoyObj == null) vJoyObj = new vJoy(); - // Test if DLL matches the driver - UInt32 DllVer = 0, DrvVer = 0; - if (!vJoyObj.DriverMatch(ref DllVer, ref DrvVer)) - AppLogger.LogToGui("WARNING. VJoy version of Driver {DrvVer}) does not match interface DLL Version {DllVer}. This may lead to unexpected problems or crashes. Update VJoy driver and vJoyInterface.dll", false); - - VjdStat status = vJoyObj.GetVJDStatus(vJoyID); - if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!vJoyObj.AcquireVJD(vJoyID)))) + if (vJoyObj.vJoyEnabled() && vJoyObj.GetVJDAxisExist(vJoyID, axis)) { - vJoyAvailable = false; - AppLogger.LogToGui("ERROR. Failed to acquire vJoy device# {vJoyID}. Use another VJoy device or make sure there are no other VJoy feeder apps using the same device", false); + AppLogger.LogToGui("Connection to VJoy virtual joystick established", false); + AppLogger.LogToGui($"VJoy driver. Vendor={vJoyObj.GetvJoyManufacturerString()} Product={vJoyObj.GetvJoyProductString()} Version={vJoyObj.GetvJoySerialNumberString()} Device#={vJoyID} Axis={axis}", false); + + // Test if DLL matches the driver + UInt32 DllVer = 0, DrvVer = 0; + if (!vJoyObj.DriverMatch(ref DllVer, ref DrvVer)) + AppLogger.LogToGui("WARNING. VJoy version of Driver {DrvVer}) does not match interface DLL Version {DllVer}. This may lead to unexpected problems or crashes. Update VJoy driver and vJoyInterface.dll", false); + + VjdStat status = vJoyObj.GetVJDStatus(vJoyID); + if ((status == VjdStat.VJD_STAT_OWN) || ((status == VjdStat.VJD_STAT_FREE) && (!vJoyObj.AcquireVJD(vJoyID)))) + { + vJoyAvailable = false; + AppLogger.LogToGui("ERROR. Failed to acquire vJoy device# {vJoyID}. Use another VJoy device or make sure there are no other VJoy feeder apps using the same device", false); + } + else + { + //vJoyObj.GetVJDAxisMax(vJoyID, axis, ref vJoyAxisMaxValue); + //AppLogger.LogToGui($"VJoy axis {axis} max value={vJoyAxisMaxValue}", false); + vJoyObj.ResetVJD(vJoyID); + vJoyAvailable = true; + } } else { - //vJoyObj.GetVJDAxisMax(vJoyID, axis, ref vJoyAxisMaxValue); - //AppLogger.LogToGui($"VJoy axis {axis} max value={vJoyAxisMaxValue}", false); - vJoyObj.ResetVJD(vJoyID); - vJoyAvailable = true; + vJoyAvailable = false; + AppLogger.LogToGui($"ERROR. VJoy device# {vJoyID} or {axis} axis not available. Check vJoy driver installation and configuration", false); } } - else + catch { vJoyAvailable = false; - AppLogger.LogToGui($"ERROR. VJoy device# {vJoyID} or {axis} axis not available. Check vJoy driver installation and configuration", false); + AppLogger.LogToGui("ERROR. vJoy initialization failed. Make sure that DS4Windows application can find vJoyInterface.dll library file", false); } } }