New "360 degree gyro steering wheel emulation" functionality. This works best if the DS4 controller is mounted on a "DoItYourself steering wheel rig" (ie. controller attached at a tip of a plastic or wooden pipe which acts as a "steering shaft". This way the controller turns around like a steering wheel and gyro sensor values are more consistent).

At this point there is no GUI to enable this, so you should edit a profile XML file (fex default.xml profile) with Notepad and add <SASteeringWheelEmulationAxis>LXPos</SASteeringWheelEmulationAxis> entry.
Accepted values are None, LXPos, LYPos, RXPos, RYPos) which indicates which X360 axis is used for steering wheel values (ie. gyro tilt converted as steering wheel turning range values). The normal behaviour of this axis should be set as "unmapped" to avoid conflicting values. If steering wheel axis is LX then LY axis is still available for other purposes.
This commit is contained in:
mika-n 2018-11-17 01:41:21 +02:00
parent dedb1c9ad9
commit a933eae0a9
5 changed files with 455 additions and 5 deletions

View File

@ -6,6 +6,8 @@ using System.Threading.Tasks;
using System.Diagnostics; using System.Diagnostics;
using static DS4Windows.Global; using static DS4Windows.Global;
using System.Drawing; // Point struct
namespace DS4Windows namespace DS4Windows
{ {
public class Mapping public class Mapping
@ -1648,6 +1650,9 @@ namespace DS4Windows
} }
} }
if (getSASteeringWheelEmulationAxis(device) != DS4Controls.None)
MappedState.SASteeringWheelEmulationUnit = Mapping.Scale360degreeGyroAxis(device, eState, ctrl);
calculateFinalMouseMovement(ref tempMouseDeltaX, ref tempMouseDeltaY, calculateFinalMouseMovement(ref tempMouseDeltaX, ref tempMouseDeltaY,
out mouseDeltaX, out mouseDeltaY); out mouseDeltaX, out mouseDeltaY);
if (mouseDeltaX != 0 || mouseDeltaY != 0) if (mouseDeltaX != 0 || mouseDeltaY != 0)
@ -3773,5 +3778,261 @@ namespace DS4Windows
fieldMap.buttons[controlNum] = false; fieldMap.buttons[controlNum] = false;
} }
} }
// BEGIN: SixAxis steering wheel emulation logic
// "In-game" calibration process:
// TODO: Launching a calibration process should probably be a special action which allows multiple key bindings to launch a specific task.
// - Place controller at "steering wheel center" position and press DS4 Option button to start the calibration (Profile should have "SASteeringWheelEmulationAxis" option set to LXPos, LYPos, RXPos or RYPos value).
// - Hold the controller still for a while and wait until red lightbar turns to blinking yellow (center point calibrated)
// - Turn the controller at 90 degree left or right position and hold still for few seconds and wait until lightbar turns to blinking light blue (two points calibrated)
// - Turn the controller at 90 degree position on the opposite side (but do it by going through 0 degree center position. Don't go through 180deg mark). Wait until lighbar turns to green (three points calibrated)
// - Now you can check the calibratio by turning the wheel and see when the green lightbar starts to blink (it should blink at those three calibrated positions).
// - Press DS4 Options button to accept the calibration (result is saved to ControllerConfigs.xml xml file in AppData folder).
//
// 0 = None of the anchors calibrated yet. Hold controller still at "wheel center position" and wait until lightbar turns from constant red to flashing yellow color
// 1 = one anchor calibrated (The first calibration point should always be the center position)
// 2 = two anchors calibrated (center and 90Right or 90Left depending on which way user turn the wheel after the first center calibration point)
// 3 = all three anchor points calibrated (center, 90Right, 90Left). Good to go. User can check calibration by turning the wheel and checking when the green lightbar blinks. If happy then pressing Options btn accepts the calibration.
private static readonly DS4Color calibrationColor_0 = new DS4Color { red = 0xA0, green = 0x00, blue = 0x00 };
private static readonly DS4Color calibrationColor_1 = new DS4Color { red = 0xFF, green = 0xFF, blue = 0x00 };
private static readonly DS4Color calibrationColor_2 = new DS4Color { red = 0x00, green = 0x50, blue = 0x50 };
private static readonly DS4Color calibrationColor_3 = new DS4Color { red = 0x00, green = 0xC0, blue = 0x00 };
private static DateTime latestDebugMsgTime;
private static void LogToGuiSACalibrationDebugMsg(string data)
{
// Print debug calibration log messages only once per 2 secs to avoid flooding the log receiver
DateTime curTime = DateTime.Now;
if (((TimeSpan)(curTime - latestDebugMsgTime)).TotalSeconds > 2)
{
latestDebugMsgTime = curTime;
AppLogger.LogToGui(data, false);
}
}
// Return number of bits set in a value
protected static int CountNumOfSetBits(int bitValue)
{
int count = 0;
while (bitValue != 0)
{
count++;
bitValue &= (bitValue - 1);
}
return count;
}
// Calculate and return the angle of the controller as -180...0...+180 value.
// TODO: Support >360 degree turn range by adding "lap counter" when wheel is rotated full rounds left or right.At the moment this logic supports only 360 degree turn range.
protected static Int32 CalculateControllerAngle(int gyroAccelX, int gyroAccelZ, DS4Device controller)
{
Int32 result;
if (Math.Abs(gyroAccelX - controller.wheelCenterPoint.X) <= 1 && Math.Abs(gyroAccelZ - controller.wheelCenterPoint.Y) <= 1)
{
// When the current gyro position is "close enough" the wheel center point then no need to go through the hassle of calculating an angle
result = 0;
}
else
{
// Calculate two vectors based on "circle center" (ie. circle represents the 360 degree wheel turn and wheelCenterPoint and currentPosition vectors both start from circle center).
// To improve accuracy both left and right turns use a decicated calibration "circle" because DS4 gyro and DoItYourselfWheelRig may return slightly different SA sensor values depending on the tilt direction (well, only one or two degree difference so nothing major).
Point vectorAB;
Point vectorCD;
if (gyroAccelX >= controller.wheelCenterPoint.X)
{
// "DS4 gyro wheel" tilted to right
vectorAB = new Point(controller.wheelCenterPoint.X - controller.wheelCircleCenterPointRight.X, controller.wheelCenterPoint.Y - controller.wheelCircleCenterPointRight.Y);
vectorCD = new Point(gyroAccelX - controller.wheelCircleCenterPointRight.X, gyroAccelZ - controller.wheelCircleCenterPointRight.Y);
}
else
{
// "DS4 gyro wheel" tilted to left
vectorAB = new Point(controller.wheelCenterPoint.X - controller.wheelCircleCenterPointLeft.X, controller.wheelCenterPoint.Y - controller.wheelCircleCenterPointLeft.Y);
vectorCD = new Point(gyroAccelX - controller.wheelCircleCenterPointLeft.X, gyroAccelZ - controller.wheelCircleCenterPointLeft.Y);
}
// Calculate dot product and magnitude of vectors (center vector and the current tilt vector)
double dotProduct = vectorAB.X * vectorCD.X + vectorAB.Y * vectorCD.Y;
double magAB = Math.Sqrt(vectorAB.X * vectorAB.X + vectorAB.Y * vectorAB.Y);
double magCD = Math.Sqrt(vectorCD.X * vectorCD.X + vectorCD.Y * vectorCD.Y);
// Calculate angle between vectors and convert radian to degrees
double angle = Math.Acos(dotProduct / (magAB * magCD));
result = Convert.ToInt32(Math.Round(angle * (180.0 / Math.PI)));
// Left turn is -180..0 and right turn 0..180 degrees
if (gyroAccelX < controller.wheelCenterPoint.X) result = -result;
// Just to be sure.. Probably not needed. TODO: Add support for 360/720/900 turn ranges by counting "laps" how many times the steering wheel is turned around
result = ClampInt(-180, result, 180);
}
return result;
}
protected static Int32 Scale360degreeGyroAxis(int device, /*DS4State state,*/ DS4StateExposed exposedState, ControlService ctrl)
{
unchecked
{
DS4Device controller;
DS4State currentDeviceState;
int gyroAccelX, gyroAccelZ;
int result;
//controller = Program.rootHub.DS4Controllers[device];
controller = ctrl.DS4Controllers[device];
if (controller == null) return 0;
currentDeviceState = controller.getCurrentStateRef();
gyroAccelX = exposedState.getAccelX();
gyroAccelZ = exposedState.getAccelZ();
// If DS4 Options btn is pressed and the previous re-calibration was done more than 2 secs ago (avoids repeated "calibration" loops if user holds down the Option btn too long) then re-calibrate the gyro wheel emulation.
// TODO. Maybe here should be logic to enter calibration process only if Options btn is hold down minimum of 3 secs? This way Option btn can be re-mapped to do other things without kicking on re-calibration everytime it is pressed.
if (currentDeviceState.Options && ((TimeSpan)(DateTime.Now - controller.wheelPrevRecalibrateTime)).TotalSeconds > 2)
{
if (controller.WheelRecalibrateActive == false)
{
AppLogger.LogToGui($"Controller {ctrl.x360Bus.FirstController + device} activated re-calibration of motion steering wheel emulation", false);
controller.WheelRecalibrateActive = true;
// Clear existing calibration value and use current position as "center" point.
// This initial center value may be off-center because of shaking the controller while button was pressed. The value will be overriden with correct value once controller is stabilized and hold still few secs at the center point
controller.wheelCenterPoint.X = gyroAccelX;
controller.wheelCenterPoint.Y = gyroAccelZ;
controller.wheel90DegPointRight.X = gyroAccelX + 25;
controller.wheel90DegPointLeft.X = gyroAccelX - 25;
// Clear bitmask for calibration points. All three calibration points need to be set before re-calibration process is valid
controller.wheelCalibratedAxisBitmask = DS4Device.WheelCalibrationPoint.None;
}
else
{
AppLogger.LogToGui($"Controller {ctrl.x360Bus.FirstController + device} completed steering wheel calibration. center=({controller.wheelCenterPoint.X}, {controller.wheelCenterPoint.Y}) 90L=({controller.wheel90DegPointLeft.X}, {controller.wheel90DegPointLeft.Y}) 90R=({controller.wheel90DegPointRight.X}, {controller.wheel90DegPointRight.Y})", false);
controller.WheelRecalibrateActive = false;
// If any of the calibration points (center, left 90deg, right 90deg) are missing then reset back to default calibration values
if (((controller.wheelCalibratedAxisBitmask & DS4Device.WheelCalibrationPoint.All) == DS4Device.WheelCalibrationPoint.All))
Global.SaveControllerConfigs(controller);
else
controller.wheelCenterPoint.X = controller.wheelCenterPoint.Y = 0;
// Reset lightbar back to normal color
DS4LightBar.forcelight[device] = false;
DS4LightBar.forcedFlash[device] = 0;
controller.LightBarColor = Global.getMainColor(device);
DS4LightBar.updateLightBar(controller, device);
}
controller.wheelPrevRecalibrateTime = DateTime.Now;
}
if (controller.WheelRecalibrateActive)
{
// Auto calibrate 90deg left/right positions (these values may change over time because gyro/accel sensor values are not "precise mathematics", so user can trigger calibration even in mid-game sessions by pressing DS4 Options btn),
// but make sure controller is stable enough to avoid misaligments because of hard shaking (check velocity of gyro axis)
if (Math.Abs(/*state*/ currentDeviceState.Motion.angVelPitch) < 0.5 && Math.Abs(currentDeviceState.Motion.angVelYaw) < 0.5 && Math.Abs(currentDeviceState.Motion.angVelRoll) < 0.5)
{
if (controller.wheelCalibratedAxisBitmask == DS4Device.WheelCalibrationPoint.None)
{
// Wait few secs after re-calibration button was pressed. Hold controller still at center position and don't shake it too much until red lightbar turns to yellow.
if (((TimeSpan)(DateTime.Now - controller.wheelPrevRecalibrateTime)).TotalSeconds >= 3)
{
controller.wheelCenterPoint.X = gyroAccelX;
controller.wheelCenterPoint.Y = gyroAccelZ;
controller.wheelCalibratedAxisBitmask |= DS4Device.WheelCalibrationPoint.Center;
}
}
else if (controller.wheel90DegPointRight.X < gyroAccelX)
{
controller.wheel90DegPointRight.X = gyroAccelX;
controller.wheel90DegPointRight.Y = gyroAccelZ;
controller.wheelCircleCenterPointRight.X = controller.wheelCenterPoint.X;
controller.wheelCircleCenterPointRight.Y = controller.wheel90DegPointRight.Y;
controller.wheelCalibratedAxisBitmask |= DS4Device.WheelCalibrationPoint.Right90;
}
else if (controller.wheel90DegPointLeft.X > gyroAccelX)
{
controller.wheel90DegPointLeft.X = gyroAccelX;
controller.wheel90DegPointLeft.Y = gyroAccelZ;
controller.wheelCircleCenterPointLeft.X = controller.wheelCenterPoint.X;
controller.wheelCircleCenterPointLeft.Y = controller.wheel90DegPointLeft.Y;
controller.wheelCalibratedAxisBitmask |= DS4Device.WheelCalibrationPoint.Left90;
}
}
// Show lightbar color feedback how the calibration process is proceeding.
// red / yellow / blue / green = No calibration anchors/one anchor/two anchors/three anchors calibrated (center, 90DegLeft, 90DegRight)
// Blinking led = Controller is tilted at the current calibration point (or calibration routine just set a new anchor point)
// TODO: device num to flash led idx (use red for center calibrated, yellow for one 90deg and green for both 90deg calibration and then reset back to normal led)
int bitsSet = CountNumOfSetBits((int)controller.wheelCalibratedAxisBitmask);
if (bitsSet >= 3) DS4LightBar.forcedColor[device] = calibrationColor_3;
else if (bitsSet == 2) DS4LightBar.forcedColor[device] = calibrationColor_2;
else if (bitsSet == 1) DS4LightBar.forcedColor[device] = calibrationColor_1;
else DS4LightBar.forcedColor[device] = calibrationColor_0;
result = CalculateControllerAngle(gyroAccelX, gyroAccelZ, controller);
if (bitsSet >= 1 && (Math.Abs(result) <= 1 || (Math.Abs(result) >= 88 && Math.Abs(result) <= 92) || Math.Abs(result) >= 178)) DS4LightBar.forcedFlash[device] = 2;
else DS4LightBar.forcedFlash[device] = 0;
DS4LightBar.forcelight[device] = true;
//DS4LightBar.updateLightBar(controller, device);
LogToGuiSACalibrationDebugMsg($"Calibration values ({gyroAccelX}, {gyroAccelZ}) angle={result}\n");
// Return center wheel position while gyro is calibrated, not the calculated angle
return 0;
}
// If calibration values are missing then use "educated guesses" about good starting values.
// TODO. Use pre-calibrated default values from configuration file.
if (controller.wheelCenterPoint.IsEmpty)
{
if (!Global.LoadControllerConfigs(controller))
{
AppLogger.LogToGui($"Controller {ctrl.x360Bus.FirstController + device} motion steering wheel calibration data missing. It is recommended to run steering wheel calibration process by pressing DS4 Options button. Using estimated values until the controller is calibrated at least once.", false);
controller.wheelCenterPoint.X = gyroAccelX;
controller.wheelCenterPoint.Y = gyroAccelZ;
controller.wheel90DegPointRight.X = controller.wheelCenterPoint.X + 113; // 113;
controller.wheel90DegPointRight.Y = controller.wheelCenterPoint.Y + 110; // 110;
controller.wheel90DegPointLeft.X = controller.wheelCenterPoint.X - 127; // -127;
controller.wheel90DegPointLeft.Y = controller.wheel90DegPointRight.Y; // 2;
}
controller.wheelCircleCenterPointRight.X = controller.wheelCenterPoint.X;
controller.wheelCircleCenterPointRight.Y = controller.wheel90DegPointRight.Y;
controller.wheelCircleCenterPointLeft.X = controller.wheelCenterPoint.X;
controller.wheelCircleCenterPointLeft.Y = controller.wheel90DegPointLeft.Y;
AppLogger.LogToGui($"Controller {ctrl.x360Bus.FirstController + device} steering wheel emulation calibration values. center=({controller.wheelCenterPoint.X}, {controller.wheelCenterPoint.Y}) 90L=({controller.wheel90DegPointLeft.X}, {controller.wheel90DegPointLeft.Y}) 90R=({controller.wheel90DegPointRight.X}, {controller.wheel90DegPointRight.Y})", false);
controller.wheelPrevRecalibrateTime = DateTime.Now;
}
result = CalculateControllerAngle(gyroAccelX, gyroAccelZ, controller);
// Keep outputting debug data 30secs after the latest re-calibration event (user can check these values from the log screen of DS4Windows GUI)
//if (((TimeSpan)(DateTime.Now - prevRecalibrateTime)).TotalSeconds < 30)
// LogToGuiSACalibrationDebugMsg($"DEBUG gyro=({gyroAccelX}, {gyroAccelZ}) angle={result}");
// Scale input to a raw x360 thumbstick output scale
return (((result - (-180)) * (32767 - (-32768))) / (180 - (-180))) + (-32768);
}
}
// END: SixAxis steering wheel emulation logic
} }
} }

View File

@ -270,6 +270,7 @@ namespace DS4Windows
m_Config.m_Profile = appdatapath + "\\Profiles.xml"; m_Config.m_Profile = appdatapath + "\\Profiles.xml";
m_Config.m_Actions = appdatapath + "\\Actions.xml"; m_Config.m_Actions = appdatapath + "\\Actions.xml";
m_Config.m_linkedProfiles = Global.appdatapath + "\\LinkedProfiles.xml"; m_Config.m_linkedProfiles = Global.appdatapath + "\\LinkedProfiles.xml";
m_Config.m_controllerConfigs = Global.appdatapath + "\\ControllerConfigs.xml";
} }
/// <summary> /// <summary>
@ -717,6 +718,12 @@ namespace DS4Windows
m_Config.SetSaTriggerCond(index, text); m_Config.SetSaTriggerCond(index, text);
} }
public static DS4Controls[] SASteeringWheelEmulationAxis => m_Config.sASteeringWheelEmulationAxis;
public static DS4Controls getSASteeringWheelEmulationAxis(int index)
{
return m_Config.sASteeringWheelEmulationAxis[index];
}
public static int[][] TouchDisInvertTriggers => m_Config.touchDisInvertTriggers; public static int[][] TouchDisInvertTriggers => m_Config.touchDisInvertTriggers;
public static int[] getTouchDisInvertTriggers(int index) public static int[] getTouchDisInvertTriggers(int index)
{ {
@ -1284,6 +1291,30 @@ namespace DS4Windows
return m_Config.LoadLinkedProfiles(); return m_Config.LoadLinkedProfiles();
} }
public static bool SaveControllerConfigs(DS4Device device = null)
{
if (device != null)
return m_Config.SaveControllerConfigsForDevice(device);
for (int idx = 0; idx < ControlService.DS4_CONTROLLER_COUNT; idx++)
if (Program.rootHub.DS4Controllers[idx] != null)
m_Config.SaveControllerConfigsForDevice(Program.rootHub.DS4Controllers[idx]);
return true;
}
public static bool LoadControllerConfigs(DS4Device device = null)
{
if (device != null)
return m_Config.LoadControllerConfigsForDevice(device);
for (int idx = 0; idx < ControlService.DS4_CONTROLLER_COUNT; idx++)
if (Program.rootHub.DS4Controllers[idx] != null)
m_Config.LoadControllerConfigsForDevice(Program.rootHub.DS4Controllers[idx]);
return true;
}
private static byte applyRatio(byte b1, byte b2, double r) private static byte applyRatio(byte b1, byte b2, double r)
{ {
if (r > 100.0) if (r > 100.0)
@ -1382,6 +1413,7 @@ namespace DS4Windows
public String m_Profile = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + "\\Profiles.xml"; public String m_Profile = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + "\\Profiles.xml";
public String m_Actions = Global.appdatapath + "\\Actions.xml"; public String m_Actions = Global.appdatapath + "\\Actions.xml";
public string m_linkedProfiles = Global.appdatapath + "\\LinkedProfiles.xml"; public string m_linkedProfiles = Global.appdatapath + "\\LinkedProfiles.xml";
public string m_controllerConfigs = Global.appdatapath + "\\ControllerConfigs.xml";
protected XmlDocument m_Xdoc = new XmlDocument(); protected XmlDocument m_Xdoc = new XmlDocument();
// fifth value used for options, not fifth controller // fifth value used for options, not fifth controller
@ -1481,6 +1513,7 @@ namespace DS4Windows
public bool[] useSAforMouse = new bool[5] { false, false, false, false, false }; public bool[] useSAforMouse = new bool[5] { false, false, false, false, false };
public string[] sATriggers = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty }; public string[] sATriggers = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
public bool[] sATriggerCond = new bool[5] { true, true, true, true, true }; public bool[] sATriggerCond = new bool[5] { true, true, true, true, true };
public DS4Controls[] sASteeringWheelEmulationAxis = new DS4Controls[5] { DS4Controls.None, DS4Controls.None, DS4Controls.None, DS4Controls.None, DS4Controls.None };
public int[][] touchDisInvertTriggers = new int[5][] { new int[1] { -1 }, new int[1] { -1 }, new int[1] { -1 }, public int[][] touchDisInvertTriggers = new int[5][] { new int[1] { -1 }, new int[1] { -1 }, new int[1] { -1 },
new int[1] { -1 }, new int[1] { -1 } }; new int[1] { -1 }, new int[1] { -1 } };
public int[] lsCurve = new int[5] { 0, 0, 0, 0, 0 }; public int[] lsCurve = new int[5] { 0, 0, 0, 0, 0 };
@ -1727,6 +1760,7 @@ namespace DS4Windows
XmlNode xmlUseSAforMouse = m_Xdoc.CreateNode(XmlNodeType.Element, "UseSAforMouse", null); xmlUseSAforMouse.InnerText = useSAforMouse[device].ToString(); Node.AppendChild(xmlUseSAforMouse); XmlNode xmlUseSAforMouse = m_Xdoc.CreateNode(XmlNodeType.Element, "UseSAforMouse", null); xmlUseSAforMouse.InnerText = useSAforMouse[device].ToString(); Node.AppendChild(xmlUseSAforMouse);
XmlNode xmlSATriggers = m_Xdoc.CreateNode(XmlNodeType.Element, "SATriggers", null); xmlSATriggers.InnerText = sATriggers[device].ToString(); Node.AppendChild(xmlSATriggers); XmlNode xmlSATriggers = m_Xdoc.CreateNode(XmlNodeType.Element, "SATriggers", null); xmlSATriggers.InnerText = sATriggers[device].ToString(); Node.AppendChild(xmlSATriggers);
XmlNode xmlSATriggerCond = m_Xdoc.CreateNode(XmlNodeType.Element, "SATriggerCond", null); xmlSATriggerCond.InnerText = SaTriggerCondString(sATriggerCond[device]); Node.AppendChild(xmlSATriggerCond); XmlNode xmlSATriggerCond = m_Xdoc.CreateNode(XmlNodeType.Element, "SATriggerCond", null); xmlSATriggerCond.InnerText = SaTriggerCondString(sATriggerCond[device]); Node.AppendChild(xmlSATriggerCond);
XmlNode xmlSASteeringWheelEmulationAxis = m_Xdoc.CreateNode(XmlNodeType.Element, "SASteeringWheelEmulationAxis", null); xmlSASteeringWheelEmulationAxis.InnerText = sASteeringWheelEmulationAxis[device].ToString("G"); Node.AppendChild(xmlSASteeringWheelEmulationAxis);
XmlNode xmlTouchDisInvTriggers = m_Xdoc.CreateNode(XmlNodeType.Element, "TouchDisInvTriggers", null); XmlNode xmlTouchDisInvTriggers = m_Xdoc.CreateNode(XmlNodeType.Element, "TouchDisInvTriggers", null);
string tempTouchDisInv = string.Join(",", touchDisInvertTriggers[device]); string tempTouchDisInv = string.Join(",", touchDisInvertTriggers[device]);
@ -2603,7 +2637,11 @@ namespace DS4Windows
try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/SATriggerCond"); sATriggerCond[device] = SaTriggerCondValue(Item.InnerText); } try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/SATriggerCond"); sATriggerCond[device] = SaTriggerCondValue(Item.InnerText); }
catch { sATriggerCond[device] = true; missingSetting = true; } catch { sATriggerCond[device] = true; missingSetting = true; }
try { try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/SASteeringWheelEmulationAxis"); DS4Controls.TryParse(Item.InnerText, out sASteeringWheelEmulationAxis[device]); }
catch { sASteeringWheelEmulationAxis[device] = DS4Controls.None; missingSetting = true; }
try
{
Item = m_Xdoc.SelectSingleNode("/" + rootname + "/TouchDisInvTriggers"); Item = m_Xdoc.SelectSingleNode("/" + rootname + "/TouchDisInvTriggers");
string[] triggers = Item.InnerText.Split(','); string[] triggers = Item.InnerText.Split(',');
int temp = -1; int temp = -1;
@ -3467,6 +3505,107 @@ namespace DS4Windows
return saved; return saved;
} }
public bool createControllerConfigs()
{
bool saved = true;
XmlDocument configXdoc = new XmlDocument();
XmlNode Node;
Node = configXdoc.CreateXmlDeclaration("1.0", "utf-8", string.Empty);
configXdoc.AppendChild(Node);
Node = configXdoc.CreateComment(string.Format(" Controller config data. {0} ", DateTime.Now));
configXdoc.AppendChild(Node);
Node = configXdoc.CreateWhitespace("\r\n");
configXdoc.AppendChild(Node);
Node = configXdoc.CreateNode(XmlNodeType.Element, "Controllers", "");
configXdoc.AppendChild(Node);
try { configXdoc.Save(m_controllerConfigs); }
catch (UnauthorizedAccessException) { AppLogger.LogToGui("Unauthorized Access - Save failed to path: " + m_controllerConfigs, false); saved = false; }
return saved;
}
public bool LoadControllerConfigsForDevice(DS4Device device)
{
bool loaded = false;
if (device == null) return false;
if (!File.Exists(m_controllerConfigs)) createControllerConfigs();
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(m_controllerConfigs);
XmlNode node = xmlDoc.SelectSingleNode("/Controllers/Controller[@Mac=\"" + device.getMacAddress() + "\"]");
if (node != null)
{
Int32 intValue;
if (Int32.TryParse(node["wheelCenterPoint"].InnerText.Split(',')[0], out intValue)) device.wheelCenterPoint.X = intValue;
if (Int32.TryParse(node["wheelCenterPoint"].InnerText.Split(',')[1], out intValue)) device.wheelCenterPoint.Y = intValue;
if (Int32.TryParse(node["wheel90DegPointLeft"].InnerText.Split(',')[0], out intValue)) device.wheel90DegPointLeft.X = intValue;
if (Int32.TryParse(node["wheel90DegPointLeft"].InnerText.Split(',')[1], out intValue)) device.wheel90DegPointLeft.Y = intValue;
if (Int32.TryParse(node["wheel90DegPointRight"].InnerText.Split(',')[0], out intValue)) device.wheel90DegPointRight.X = intValue;
if (Int32.TryParse(node["wheel90DegPointRight"].InnerText.Split(',')[1], out intValue)) device.wheel90DegPointRight.Y = intValue;
loaded = true;
}
}
catch
{
AppLogger.LogToGui("ControllerConfigs.xml can't be found.", false);
loaded = false;
}
return loaded;
}
public bool SaveControllerConfigsForDevice(DS4Device device)
{
bool saved = true;
if (device == null) return false;
if (!File.Exists(m_controllerConfigs)) createControllerConfigs();
try
{
//XmlNode node = null;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(m_controllerConfigs);
XmlNode node = xmlDoc.SelectSingleNode("/Controllers/Controller[@Mac=\"" + device.getMacAddress() + "\"]");
if (node == null)
{
XmlNode xmlControllersNode = xmlDoc.SelectSingleNode("/Controllers");
XmlElement el = xmlDoc.CreateElement("Controller");
el.SetAttribute("Mac", device.getMacAddress());
el.AppendChild(xmlDoc.CreateElement("wheelCenterPoint"));
el.AppendChild(xmlDoc.CreateElement("wheel90DegPointLeft"));
el.AppendChild(xmlDoc.CreateElement("wheel90DegPointRight"));
node = xmlControllersNode.AppendChild(el);
}
node["wheelCenterPoint"].InnerText = $"{device.wheelCenterPoint.X},{device.wheelCenterPoint.Y}";
node["wheel90DegPointLeft"].InnerText = $"{device.wheel90DegPointLeft.X},{device.wheel90DegPointLeft.Y}";
node["wheel90DegPointRight"].InnerText = $"{device.wheel90DegPointRight.X},{device.wheel90DegPointRight.Y}";
xmlDoc.Save(m_controllerConfigs);
}
catch (UnauthorizedAccessException)
{
AppLogger.LogToGui("Unauthorized Access - Save failed to path: " + m_controllerConfigs, false);
saved = false;
}
return saved;
}
public void UpdateDS4CSetting(int deviceNum, string buttonName, bool shift, object action, string exts, DS4KeyType kt, int trigger = 0) public void UpdateDS4CSetting(int deviceNum, string buttonName, bool shift, object action, string exts, DS4KeyType kt, int trigger = 0)
{ {
DS4Controls dc; DS4Controls dc;
@ -3780,6 +3919,7 @@ namespace DS4Windows
useSAforMouse[device] = false; useSAforMouse[device] = false;
sATriggers[device] = string.Empty; sATriggers[device] = string.Empty;
sATriggerCond[device] = true; sATriggerCond[device] = true;
sASteeringWheelEmulationAxis[device] = DS4Controls.None;
touchDisInvertTriggers[device] = new int[1] { -1 }; touchDisInvertTriggers[device] = new int[1] { -1 };
lsCurve[device] = rsCurve[device] = 0; lsCurve[device] = rsCurve[device] = 0;
gyroSensitivity[device] = 100; gyroSensitivity[device] = 100;

View File

@ -5,6 +5,8 @@ using System.ComponentModel;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles; using Microsoft.Win32.SafeHandles;
using System.Drawing; // Point struct
namespace DS4Windows namespace DS4Windows
{ {
public partial class X360Device : ScpDevice public partial class X360Device : ScpDevice
@ -141,10 +143,25 @@ namespace DS4Windows
Output[12] = state.L2; // Left Trigger Output[12] = state.L2; // Left Trigger
Output[13] = state.R2; // Right Trigger Output[13] = state.R2; // Right Trigger
Int32 ThumbLX = Scale(state.LX, false); Int32 ThumbLX;
Int32 ThumbLY = Scale(state.LY, true); Int32 ThumbLY;
Int32 ThumbRX = Scale(state.RX, false); Int32 ThumbRX;
Int32 ThumbRY = Scale(state.RY, true); Int32 ThumbRY;
DS4Controls steeringWheelMappedAxis = Global.getSASteeringWheelEmulationAxis(device);
if (steeringWheelMappedAxis == DS4Controls.LXPos) ThumbLX = state.SASteeringWheelEmulationUnit;
else ThumbLX = Scale(state.LX, false);
if (steeringWheelMappedAxis == DS4Controls.LYPos) ThumbLY = state.SASteeringWheelEmulationUnit;
else ThumbLY = Scale(state.LY, true);
if (steeringWheelMappedAxis == DS4Controls.RXPos) ThumbRX = state.SASteeringWheelEmulationUnit;
else ThumbRX = Scale(state.RX, false);
if (steeringWheelMappedAxis == DS4Controls.RYPos) ThumbRY = state.SASteeringWheelEmulationUnit;
else ThumbRY = Scale(state.RY, true);
Output[14] = (Byte)((ThumbLX >> 0) & 0xFF); // LX Output[14] = (Byte)((ThumbLX >> 0) & 0xFF); // LX
Output[15] = (Byte)((ThumbLX >> 8) & 0xFF); Output[15] = (Byte)((ThumbLX >> 8) & 0xFF);
Output[16] = (Byte)((ThumbLY >> 0) & 0xFF); // LY Output[16] = (Byte)((ThumbLY >> 0) & 0xFF); // LY

View File

@ -157,6 +157,34 @@ namespace DS4Windows
return warnInterval; return warnInterval;
} }
public Point wheelCenterPoint;
public Point wheel90DegPointLeft;
public Point wheelCircleCenterPointLeft;
public Point wheel90DegPointRight;
public Point wheelCircleCenterPointRight;
public DateTime wheelPrevRecalibrateTime;
private bool wheelRecalibrateActive = false;
public bool WheelRecalibrateActive
{
get { return wheelRecalibrateActive; }
set
{
wheelRecalibrateActive = value;
}
}
public enum WheelCalibrationPoint
{
None = 0,
Center = 1,
Right90 = 2,
Left90 = 4,
All = Center | Right90 | Left90
}
public WheelCalibrationPoint wheelCalibratedAxisBitmask;
private bool exitOutputThread = false; private bool exitOutputThread = false;
public bool ExitOutputThread => exitOutputThread; public bool ExitOutputThread => exitOutputThread;
private bool exitInputThread = false; private bool exitInputThread = false;

View File

@ -28,6 +28,7 @@ namespace DS4Windows
public ulong totalMicroSec = 0; public ulong totalMicroSec = 0;
public SixAxis Motion = null; public SixAxis Motion = null;
public static readonly int DEFAULT_AXISDIR_VALUE = 127; public static readonly int DEFAULT_AXISDIR_VALUE = 127;
public Int32 SASteeringWheelEmulationUnit;
public struct TrackPadTouch public struct TrackPadTouch
{ {
@ -66,6 +67,7 @@ namespace DS4Windows
Motion = new SixAxis(0, 0, 0, 0, 0, 0, 0.0); Motion = new SixAxis(0, 0, 0, 0, 0, 0, 0.0);
TrackPadTouch0.IsActive = false; TrackPadTouch0.IsActive = false;
TrackPadTouch1.IsActive = false; TrackPadTouch1.IsActive = false;
SASteeringWheelEmulationUnit = 0;
} }
public DS4State(DS4State state) public DS4State(DS4State state)
@ -120,6 +122,7 @@ namespace DS4Windows
Motion = state.Motion; Motion = state.Motion;
TrackPadTouch0 = state.TrackPadTouch0; TrackPadTouch0 = state.TrackPadTouch0;
TrackPadTouch1 = state.TrackPadTouch1; TrackPadTouch1 = state.TrackPadTouch1;
SASteeringWheelEmulationUnit = state.SASteeringWheelEmulationUnit;
} }
public DS4State Clone() public DS4State Clone()
@ -179,6 +182,7 @@ namespace DS4Windows
state.Motion = Motion; state.Motion = Motion;
state.TrackPadTouch0 = TrackPadTouch0; state.TrackPadTouch0 = TrackPadTouch0;
state.TrackPadTouch1 = TrackPadTouch1; state.TrackPadTouch1 = TrackPadTouch1;
state.SASteeringWheelEmulationUnit = SASteeringWheelEmulationUnit;
} }
public void calculateStickAngles() public void calculateStickAngles()