Added profile setting for controller type

This commit is contained in:
Travis Nickles 2019-04-18 01:12:10 -05:00
parent dc5e34f1be
commit 1b58265c28
5 changed files with 1193 additions and 3768 deletions

View File

@ -422,20 +422,12 @@ namespace DS4Windows
if (!getDInputOnly(i) && device.isSynced())
{
LogDebug("Plugging in X360 Controller #" + (i + 1));
useDInputOnly[i] = false;
DS4OutDevice tempDS4 = new DS4OutDevice(vigemTestClient);
outputDevices[i] = tempDS4;
int devIndex = i;
tempDS4.cont.FeedbackReceived += (sender, args) =>
OutContType contType = Global.OutContType[i];
if (contType == OutContType.X360)
{
SetDevRumble(device, args.LargeMotor, args.SmallMotor, devIndex);
};
tempDS4.Connect();
//x360controls[i] = new Xbox360Controller(vigemTestClient);
/*Xbox360Controller bacon = new Xbox360Controller(vigemTestClient);
LogDebug("Plugging in X360 Controller #" + (i + 1));
Xbox360OutDevice tempXbox = new Xbox360OutDevice(vigemTestClient);
outputDevices[i] = tempXbox;
int devIndex = i;
@ -445,9 +437,23 @@ namespace DS4Windows
};
tempXbox.Connect();
*/
LogDebug("X360 Controller #" + (i + 1) + " connected");
}
else if (contType == OutContType.DS4)
{
LogDebug("Plugging in DS4 Controller #" + (i + 1));
DS4OutDevice tempDS4 = new DS4OutDevice(vigemTestClient);
outputDevices[i] = tempDS4;
int devIndex = i;
tempDS4.cont.FeedbackReceived += (sender, args) =>
{
SetDevRumble(device, args.LargeMotor, args.SmallMotor, devIndex);
};
tempDS4.Connect();
LogDebug("DS4 Controller #" + (i + 1) + " connected");
}
}
else
{
useDInputOnly[i] = true;
@ -582,10 +588,8 @@ namespace DS4Windows
}
CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
//x360controls[i]?.Disconnect();
outputDevices[i]?.Disconnect();
outputDevices[i] = null;
//x360controls[i] = null;
useDInputOnly[i] = true;
DS4Controllers[i] = null;
touchPad[i] = null;
@ -695,22 +699,38 @@ namespace DS4Windows
if (!getDInputOnly(Index) && device.isSynced())
{
LogDebug("Plugging in X360 Controller #" + (Index + 1));
useDInputOnly[Index] = false;
//x360controls[Index] = new Xbox360Controller(vigemTestClient);
OutContType contType = Global.OutContType[Index];
if (contType == OutContType.X360)
{
LogDebug("Plugging in X360 Controller #" + (Index + 1));
Xbox360OutDevice tempXbox = new Xbox360OutDevice(vigemTestClient);
outputDevices[Index] = tempXbox;
int devIndex = Index;
//x360controls[Index].FeedbackReceived += (sender, args) =>
tempXbox.cont.FeedbackReceived += (sender, args) =>
{
SetDevRumble(device, args.LargeMotor, args.SmallMotor, devIndex);
};
//x360controls[Index].Connect();
tempXbox.Connect();
LogDebug("X360 Controller #" + (Index + 1) + " connected");
}
else if (contType == OutContType.DS4)
{
LogDebug("Plugging in DS4 Controller #" + (Index + 1));
DS4OutDevice tempDS4 = new DS4OutDevice(vigemTestClient);
outputDevices[Index] = tempDS4;
int devIndex = Index;
tempDS4.cont.FeedbackReceived += (sender, args) =>
{
SetDevRumble(device, args.LargeMotor, args.SmallMotor, devIndex);
};
tempDS4.Connect();
LogDebug("DS4 Controller #" + (Index + 1) + " connected");
}
}
else
{
useDInputOnly[Index] = true;
@ -1073,12 +1093,15 @@ namespace DS4Windows
outputDevices[ind].Disconnect();
outputDevices[ind] = null;
useDInputOnly[ind] = true;
LogDebug("X360 Controller #" + (ind + 1) + " unplugged");
LogDebug("Controller #" + (ind + 1) + " unplugged");
}
}
else
{
if (!getDInputOnly(ind))
{
OutContType conType = Global.OutContType[ind];
if (conType == OutContType.X360)
{
LogDebug("Plugging in X360 Controller #" + (ind + 1));
Xbox360OutDevice tempXbox = new Xbox360OutDevice(vigemTestClient);
@ -1089,17 +1112,24 @@ namespace DS4Windows
};
tempXbox.Connect();
/*x360controls[ind] = new Xbox360Controller(vigemTestClient);
x360controls[ind].FeedbackReceived += (eventsender, args) =>
LogDebug("X360 Controller #" + (ind + 1) + " connected");
}
else if (conType == OutContType.DS4)
{
SetDevRumble(device, args.LargeMotor, args.SmallMotor, ind);
LogDebug("Plugging in DS4 Controller #" + (ind + 1));
DS4OutDevice tempDS4 = new DS4OutDevice(vigemTestClient);
outputDevices[ind] = tempDS4;
int devIndex = ind;
tempDS4.cont.FeedbackReceived += (eventsender, args) =>
{
SetDevRumble(device, args.LargeMotor, args.SmallMotor, devIndex);
};
x360controls[ind].Connect();
*/
tempDS4.Connect();
LogDebug("DS4 Controller #" + (ind + 1) + " connected");
}
useDInputOnly[ind] = false;
LogDebug("X360 Controller #" + (ind + 1) + " connected");
}
}
}

View File

@ -21,6 +21,7 @@ namespace DS4Windows
public enum X360Controls : byte { None, LXNeg, LXPos, LYNeg, LYPos, RXNeg, RXPos, RYNeg, RYPos, LB, LT, LS, RB, RT, RS, X, Y, B, A, DpadUp, DpadRight, DpadDown, DpadLeft, Guide, Back, Start, LeftMouse, RightMouse, MiddleMouse, FourthMouse, FifthMouse, WUP, WDOWN, MouseUp, MouseDown, MouseLeft, MouseRight, Unbound };
public enum SASteeringWheelEmulationAxisType: byte { None = 0, LX, LY, RX, RY, L2R2, VJoy1X, VJoy1Y, VJoy1Z, VJoy2X, VJoy2Y, VJoy2Z };
public enum OutContType : uint { None = 0, X360, DS4 }
public class DS4ControlSettings
{
@ -1148,6 +1149,7 @@ namespace DS4Windows
return m_Config.trackballFriction[index];
}
public static OutContType[] OutContType => m_Config.outputDevType;
public static string[] LaunchProgram => m_Config.launchProgram;
public static string[] ProfilePath => m_Config.profilePath;
public static string[] OlderProfilePath => m_Config.olderProfilePath;
@ -1660,6 +1662,9 @@ namespace DS4Windows
public int[] gyroMouseHorizontalAxis = new int[5] { 0, 0, 0, 0, 0 };
public bool[] trackballMode = new bool[5] { false, false, false, false, false };
public double[] trackballFriction = new double[5] { 10.0, 10.0, 10.0, 10.0, 10.0 };
public OutContType[] outputDevType = new OutContType[5] { OutContType.None,
OutContType.None, OutContType.None,
OutContType.None, OutContType.None };
bool tempBool = false;
@ -1779,6 +1784,34 @@ namespace DS4Windows
control.touchPad[index].ToggleGyroMouse = value;
}
private string OutContDeviceString(OutContType id)
{
string result = "None";
switch (id)
{
case OutContType.None: break;
case OutContType.X360: result = "X360"; break;
case OutContType.DS4: result = "DS4"; break;
default: break;
}
return result;
}
private OutContType OutContDeviceId(string name)
{
OutContType id = OutContType.None;
switch (name)
{
case "None": break;
case "X360": id = OutContType.X360; break;
case "DS4": id = OutContType.DS4; break;
default: break;
}
return id;
}
public bool SaveProfile(int device, string propath)
{
bool Saved = true;
@ -1903,6 +1936,8 @@ namespace DS4Windows
XmlNode xmlTrackBallMode = m_Xdoc.CreateNode(XmlNodeType.Element, "TrackballMode", null); xmlTrackBallMode.InnerText = trackballMode[device].ToString(); Node.AppendChild(xmlTrackBallMode);
XmlNode xmlTrackBallFriction = m_Xdoc.CreateNode(XmlNodeType.Element, "TrackballFriction", null); xmlTrackBallFriction.InnerText = trackballFriction[device].ToString(); Node.AppendChild(xmlTrackBallFriction);
XmlNode xmlOutContDevice = m_Xdoc.CreateNode(XmlNodeType.Element, "OutputContDevice", null); xmlOutContDevice.InnerText = OutContDeviceString(outputDevType[device]); Node.AppendChild(xmlOutContDevice);
XmlNode NodeControl = m_Xdoc.CreateNode(XmlNodeType.Element, "Control", null);
XmlNode Key = m_Xdoc.CreateNode(XmlNodeType.Element, "Key", null);
XmlNode Macro = m_Xdoc.CreateNode(XmlNodeType.Element, "Macro", null);
@ -2376,6 +2411,8 @@ namespace DS4Windows
DS4LightBar.forcedFlash[device] = 0;
}
OutContType oldContType = outputDevType[device];
// Make sure to reset currently set profile values before parsing
ResetProfile(device);
@ -2697,32 +2734,6 @@ namespace DS4Windows
bool oldUseDInputOnly = Global.useDInputOnly[device];
// Only change xinput devices under certain conditions. Avoid
// performing this upon program startup before loading devices.
if (xinputChange)
{
if (device < 4)
{
DS4Device tempDevice = control.DS4Controllers[device];
bool exists = tempBool = (tempDevice != null);
bool synced = tempBool = exists ? tempDevice.isSynced() : false;
bool isAlive = tempBool = exists ? tempDevice.IsAlive() : false;
if (dinputOnly[device] != oldUseDInputOnly)
{
if (dinputOnly[device] == true)
{
xinputPlug = false;
xinputStatus = true;
}
else if (synced && isAlive)
{
xinputPlug = true;
xinputStatus = true;
}
}
}
}
try
{
Item = m_Xdoc.SelectSingleNode("/" + rootname + "/StartTouchpadOff");
@ -2841,6 +2852,40 @@ namespace DS4Windows
try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/TrackballFriction"); double.TryParse(Item.InnerText, out trackballFriction[device]); }
catch { trackballFriction[device] = 10.0; missingSetting = true; }
try { Item = m_Xdoc.SelectSingleNode("/" + rootname + "/OutputContDevice"); outputDevType[device] = OutContDeviceId(Item.InnerText); }
catch { outputDevType[device] = OutContType.X360; missingSetting = true; }
// Only change xinput devices under certain conditions. Avoid
// performing this upon program startup before loading devices.
if (xinputChange)
{
if (device < 4)
{
DS4Device tempDevice = control.DS4Controllers[device];
bool exists = tempBool = (tempDevice != null);
bool synced = tempBool = exists ? tempDevice.isSynced() : false;
bool isAlive = tempBool = exists ? tempDevice.IsAlive() : false;
if (dinputOnly[device] != oldUseDInputOnly)
{
if (dinputOnly[device] == true)
{
xinputPlug = false;
xinputStatus = true;
}
else if (synced && isAlive)
{
xinputPlug = true;
xinputStatus = true;
}
}
else if (oldContType != outputDevType[device])
{
xinputPlug = true;
xinputStatus = true;
}
}
}
try
{
Item = m_Xdoc.SelectSingleNode("/" + rootname + "/ProfileActions");
@ -3090,6 +3135,18 @@ namespace DS4Windows
tempDev.setIdleTimeout(idleDisconnectTimeout[device]);
tempDev.setBTPollRate(btPollRate[device]);
if (xinputStatus && xinputPlug)
{
OutputDevice tempOutDev = control.outputDevices[device];
if (tempOutDev != null)
{
AppLogger.LogToGui("Unplug Controller #" + (device + 1), false);
tempOutDev.Disconnect();
tempOutDev = null;
control.outputDevices[device] = null;
}
OutContType tempContType = outputDevType[device];
if (tempContType == OutContType.X360)
{
Xbox360OutDevice tempXbox = new Xbox360OutDevice(control.vigemTestClient);
control.outputDevices[device] = tempXbox;
@ -3099,23 +3156,30 @@ namespace DS4Windows
};
tempXbox.Connect();
/*control.x360controls[device] = new Nefarius.ViGEm.Client.Targets.Xbox360Controller(control.vigemTestClient);
control.x360controls[device].FeedbackReceived += (eventsender, args) =>
AppLogger.LogToGui("X360 Controller #" + (device + 1) + " connected", false);
}
else if (tempContType == OutContType.DS4)
{
DS4OutDevice tempDS4 = new DS4OutDevice(control.vigemTestClient);
control.outputDevices[device] = tempDS4;
tempDS4.cont.FeedbackReceived += (eventsender, args) =>
{
control.SetDevRumble(tempDev, args.LargeMotor, args.SmallMotor, device);
};
control.x360controls[device].Connect();
*/
tempDS4.Connect();
AppLogger.LogToGui("DS4 Controller #" + (device + 1) + " connected", false);
}
Global.useDInputOnly[device] = false;
AppLogger.LogToGui("X360 Controller #" + (device + 1) + " connected", false);
}
else if (xinputStatus && !xinputPlug)
{
control.outputDevices[device].Disconnect();
control.outputDevices[device] = null;
Global.useDInputOnly[device] = true;
AppLogger.LogToGui("X360 Controller #" + (device + 1) + " unplugged", false);
AppLogger.LogToGui("Controller #" + (device + 1) + " unplugged", false);
}
tempDev.setRumble(0, 0);
@ -4062,6 +4126,7 @@ namespace DS4Windows
sxOutCurveMode[device] = szOutCurveMode[device] = 0;
trackballMode[device] = false;
trackballFriction[device] = 10.0;
outputDevType[device] = OutContType.X360;
}
}

View File

@ -121,6 +121,8 @@
this.bnSwipeRight = new System.Windows.Forms.Button();
this.lbSwipeRight = new System.Windows.Forms.Label();
this.gBOther = new System.Windows.Forms.GroupBox();
this.OutContTypeCb = new System.Windows.Forms.ComboBox();
this.label28 = new System.Windows.Forms.Label();
this.btPollRateLabel = new System.Windows.Forms.Label();
this.btPollRateComboBox = new System.Windows.Forms.ComboBox();
this.enableTouchToggleCheckbox = new System.Windows.Forms.CheckBox();
@ -290,6 +292,9 @@
this.label6 = new System.Windows.Forms.Label();
this.nUDLSMaxZone = new System.Windows.Forms.NumericUpDown();
this.label5 = new System.Windows.Forms.Label();
this.squStickTabPage = new System.Windows.Forms.TabPage();
this.rsSquStickCk = new System.Windows.Forms.CheckBox();
this.lsSquStickCk = new System.Windows.Forms.CheckBox();
this.tPOutCurve = new System.Windows.Forms.TabPage();
this.cBSixaxisZOutputCurve = new System.Windows.Forms.ComboBox();
this.cBSixaxisXOutputCurve = new System.Windows.Forms.ComboBox();
@ -397,9 +402,6 @@
this.shareTouchInvStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.psTouchInvStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.advColorDialog = new DS4Windows.AdvancedColorDialog();
this.squStickTabPage = new System.Windows.Forms.TabPage();
this.lsSquStickCk = new System.Windows.Forms.CheckBox();
this.rsSquStickCk = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.nUDRainbow)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tBBlueBar)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.tBGreenBar)).BeginInit();
@ -471,6 +473,7 @@
((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).BeginInit();
this.squStickTabPage.SuspendLayout();
this.tPOutCurve.SuspendLayout();
this.tPCurve.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nUDLSCurve)).BeginInit();
@ -494,7 +497,6 @@
((System.ComponentModel.ISupportInitialize)(this.nUDSZS)).BeginInit();
this.cMGyroTriggers.SuspendLayout();
this.cMTouchDisableInvert.SuspendLayout();
this.squStickTabPage.SuspendLayout();
this.SuspendLayout();
//
// lowColorChooserButton
@ -1316,6 +1318,8 @@
// gBOther
//
this.gBOther.BackColor = System.Drawing.SystemColors.Control;
this.gBOther.Controls.Add(this.OutContTypeCb);
this.gBOther.Controls.Add(this.label28);
this.gBOther.Controls.Add(this.btPollRateLabel);
this.gBOther.Controls.Add(this.btPollRateComboBox);
this.gBOther.Controls.Add(this.enableTouchToggleCheckbox);
@ -1337,6 +1341,21 @@
this.gBOther.Name = "gBOther";
this.gBOther.TabStop = false;
//
// OutContTypeCb
//
this.OutContTypeCb.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.OutContTypeCb.FormattingEnabled = true;
this.OutContTypeCb.Items.AddRange(new object[] {
resources.GetString("OutContTypeCb.Items"),
resources.GetString("OutContTypeCb.Items1")});
resources.ApplyResources(this.OutContTypeCb, "OutContTypeCb");
this.OutContTypeCb.Name = "OutContTypeCb";
//
// label28
//
resources.ApplyResources(this.label28, "label28");
this.label28.Name = "label28";
//
// btPollRateLabel
//
resources.ApplyResources(this.btPollRateLabel, "btPollRateLabel");
@ -3186,6 +3205,28 @@
resources.ApplyResources(this.label5, "label5");
this.label5.Name = "label5";
//
// squStickTabPage
//
this.squStickTabPage.Controls.Add(this.rsSquStickCk);
this.squStickTabPage.Controls.Add(this.lsSquStickCk);
resources.ApplyResources(this.squStickTabPage, "squStickTabPage");
this.squStickTabPage.Name = "squStickTabPage";
this.squStickTabPage.UseVisualStyleBackColor = true;
//
// rsSquStickCk
//
resources.ApplyResources(this.rsSquStickCk, "rsSquStickCk");
this.rsSquStickCk.Name = "rsSquStickCk";
this.rsSquStickCk.UseVisualStyleBackColor = true;
this.rsSquStickCk.Click += new System.EventHandler(this.rsSquStickCk_Click);
//
// lsSquStickCk
//
resources.ApplyResources(this.lsSquStickCk, "lsSquStickCk");
this.lsSquStickCk.Name = "lsSquStickCk";
this.lsSquStickCk.UseVisualStyleBackColor = true;
this.lsSquStickCk.Click += new System.EventHandler(this.lsSquStickCk_Click);
//
// tPOutCurve
//
this.tPOutCurve.BackColor = System.Drawing.SystemColors.Control;
@ -4232,28 +4273,6 @@
resources.ApplyResources(this.psTouchInvStripMenuItem, "psTouchInvStripMenuItem");
this.psTouchInvStripMenuItem.CheckedChanged += new System.EventHandler(this.TouchDisableInvert_CheckedChanged);
//
// squStickTabPage
//
this.squStickTabPage.Controls.Add(this.rsSquStickCk);
this.squStickTabPage.Controls.Add(this.lsSquStickCk);
resources.ApplyResources(this.squStickTabPage, "squStickTabPage");
this.squStickTabPage.Name = "squStickTabPage";
this.squStickTabPage.UseVisualStyleBackColor = true;
//
// lsSquStickCk
//
resources.ApplyResources(this.lsSquStickCk, "lsSquStickCk");
this.lsSquStickCk.Name = "lsSquStickCk";
this.lsSquStickCk.UseVisualStyleBackColor = true;
this.lsSquStickCk.Click += new System.EventHandler(this.lsSquStickCk_Click);
//
// rsSquStickCk
//
resources.ApplyResources(this.rsSquStickCk, "rsSquStickCk");
this.rsSquStickCk.Name = "rsSquStickCk";
this.rsSquStickCk.UseVisualStyleBackColor = true;
this.rsSquStickCk.Click += new System.EventHandler(this.rsSquStickCk_Click);
//
// Options
//
resources.ApplyResources(this, "$this");
@ -4349,6 +4368,7 @@
((System.ComponentModel.ISupportInitialize)(this.nUDL2Maxzone)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDRSMaxZone)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nUDLSMaxZone)).EndInit();
this.squStickTabPage.ResumeLayout(false);
this.tPOutCurve.ResumeLayout(false);
this.tPOutCurve.PerformLayout();
this.tPCurve.ResumeLayout(false);
@ -4378,7 +4398,6 @@
((System.ComponentModel.ISupportInitialize)(this.nUDSZS)).EndInit();
this.cMGyroTriggers.ResumeLayout(false);
this.cMTouchDisableInvert.ResumeLayout(false);
this.squStickTabPage.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -4757,5 +4776,7 @@
private System.Windows.Forms.TabPage squStickTabPage;
private System.Windows.Forms.CheckBox rsSquStickCk;
private System.Windows.Forms.CheckBox lsSquStickCk;
private System.Windows.Forms.ComboBox OutContTypeCb;
private System.Windows.Forms.Label label28;
}
}

View File

@ -34,6 +34,7 @@ namespace DS4Windows
private Bitmap pnlControllerBgImg;
private Bitmap btnLightBgImg;
private Bitmap btnLightBg;
private OutContType devOutContType = OutContType.X360;
int tempInt = 0;
@ -307,6 +308,8 @@ namespace DS4Windows
LoadProfile(device, false, Program.rootHub);
devOutContType = Global.OutContType[device];
if (Rainbow[device] == 0)
{
btnRainbow.Image = greyscale;
@ -728,6 +731,15 @@ namespace DS4Windows
int idxSASteeringWheelEmulationRange = cBSteeringWheelEmulationRange.Items.IndexOf(GetSASteeringWheelEmulationRange(device).ToString());
if (idxSASteeringWheelEmulationRange >= 0) cBSteeringWheelEmulationRange.SelectedIndex = idxSASteeringWheelEmulationRange;
OutContType tempOutType = Global.OutContType[device];
switch(tempOutType)
{
case OutContType.X360: OutContTypeCb.SelectedIndex = 0; break;
case OutContType.DS4: OutContTypeCb.SelectedIndex = 1; break;
default: break;
}
}
else
{
@ -853,6 +865,7 @@ namespace DS4Windows
triggerCondAndCombo.SelectedIndex = 0;
cBSteeringWheelEmulationAxis.SelectedIndex = 0;
cBSteeringWheelEmulationRange.SelectedIndex = cBSteeringWheelEmulationRange.Items.IndexOf("360");
OutContTypeCb.SelectedIndex = 0;
Set();
}
@ -1334,6 +1347,20 @@ namespace DS4Windows
if (nUDRainbow.Value == 0) btnRainbow.Image = greyscale;
else btnRainbow.Image = colored;
int tempOutCont = OutContTypeCb.SelectedIndex;
OutContType tempType = OutContType.X360;
switch(tempOutCont)
{
case 0: tempType = OutContType.X360; break;
case 1: tempType = OutContType.DS4; break;
default: break;
}
if (devOutContType != tempType)
{
Global.OutContType[device] = tempType;
}
}
private void Show_ControlsBtn(object sender, EventArgs e)

File diff suppressed because it is too large Load Diff