Fine tuning vJoy output feeder

This commit is contained in:
mika-n 2019-01-13 21:25:42 +02:00
parent 853b1ac650
commit abadfb137b
2 changed files with 34 additions and 25 deletions

View File

@ -4128,28 +4128,29 @@ namespace DS4Windows
result = Mapping.ClampInt(maxRangeLeft, result, maxRangeRight); 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); //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. // 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)) switch(Global.getSASteeringWheelEmulationAxis(device))
{ {
case SASteeringWheelEmulationAxisType.LX: case SASteeringWheelEmulationAxisType.LX:
case SASteeringWheelEmulationAxisType.LY: case SASteeringWheelEmulationAxisType.LY:
case SASteeringWheelEmulationAxisType.RX: case SASteeringWheelEmulationAxisType.RX:
case SASteeringWheelEmulationAxisType.RY: 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); return (((result - maxRangeLeft) * (32767 - (-32768))) / (maxRangeRight - maxRangeLeft)) + (-32768);
case SASteeringWheelEmulationAxisType.L2R2: 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))); result = Convert.ToInt32(Math.Round(result / (1.0 * C_WHEEL_ANGLE_PRECISION)));
if (result < 0) result = -181 - result; if (result < 0) result = -181 - result;
return (((result - (-180)) * (255 - (-255))) / (180 - (-180))) + (-255); return (((result - (-180)) * (255 - (-255))) / (180 - (-180))) + (-255);
default: default:
// VJoy axis values with configurable range // 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); return (((result - maxRangeLeft) * (32767 - (-0))) / (maxRangeRight - maxRangeLeft)) + (-0);
} }
} }
} }

View File

@ -653,36 +653,44 @@ namespace DS4Windows.VJoyFeeder
vJoyInitialized = true; vJoyInitialized = true;
AppLogger.LogToGui("Initializing VJoy virtual joystick driver via vJoyInterface.dll interface", false); AppLogger.LogToGui("Initializing VJoy virtual joystick driver via vJoyInterface.dll interface", false);
if (vJoyObj == null) vJoyObj = new vJoy(); try
if (vJoyObj.vJoyEnabled() && vJoyObj.GetVJDAxisExist(vJoyID, axis))
{ {
AppLogger.LogToGui("Connection to VJoy virtual joystick established", false); if (vJoyObj == null) vJoyObj = new vJoy();
AppLogger.LogToGui($"VJoy driver. Vendor={vJoyObj.GetvJoyManufacturerString()} Product={vJoyObj.GetvJoyProductString()} Version={vJoyObj.GetvJoySerialNumberString()} Device#={vJoyID} Axis={axis}", false);
// Test if DLL matches the driver if (vJoyObj.vJoyEnabled() && vJoyObj.GetVJDAxisExist(vJoyID, axis))
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("Connection to VJoy virtual joystick established", 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($"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 else
{ {
//vJoyObj.GetVJDAxisMax(vJoyID, axis, ref vJoyAxisMaxValue); vJoyAvailable = false;
//AppLogger.LogToGui($"VJoy axis {axis} max value={vJoyAxisMaxValue}", false); AppLogger.LogToGui($"ERROR. VJoy device# {vJoyID} or {axis} axis not available. Check vJoy driver installation and configuration", false);
vJoyObj.ResetVJD(vJoyID);
vJoyAvailable = true;
} }
} }
else catch
{ {
vJoyAvailable = false; 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);
} }
} }
} }