mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-23 23:21:49 +01:00
Merge branch 'jay' into vigem-udpserver
# Conflicts: # DS4Windows/DS4Control/ControlService.cs
This commit is contained in:
commit
8750d6ea08
@ -131,18 +131,42 @@ namespace DS4Windows
|
||||
//return meta;
|
||||
}
|
||||
|
||||
private object busThrLck = new object();
|
||||
private bool busThrRunning = false;
|
||||
private Queue<Action> busEvtQueue = new Queue<Action>();
|
||||
private object busEvtQueueLock = new object();
|
||||
public ControlService()
|
||||
{
|
||||
//sp.Stream = Properties.Resources.EE;
|
||||
// Cause thread affinity to not be tied to main GUI thread
|
||||
tempThread = new Thread(() => { x360Bus = new X360Device(); _udpServer = new UdpServer(GetPadDetailForIdx); });
|
||||
tempThread = new Thread(() => {
|
||||
x360Bus = new X360Device();
|
||||
//_udpServer = new UdpServer(GetPadDetailForIdx);
|
||||
busThrRunning = true;
|
||||
|
||||
while (busThrRunning)
|
||||
{
|
||||
lock (busEvtQueueLock)
|
||||
{
|
||||
Action tempAct = null;
|
||||
for (int actInd = 0, actLen = busEvtQueue.Count; actInd < actLen; actInd++)
|
||||
{
|
||||
tempAct = busEvtQueue.Dequeue();
|
||||
tempAct.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
lock (busThrLck)
|
||||
Monitor.Wait(busThrLck);
|
||||
}
|
||||
});
|
||||
tempThread.Priority = ThreadPriority.AboveNormal;
|
||||
tempThread.IsBackground = true;
|
||||
tempThread.Start();
|
||||
while (tempThread.IsAlive)
|
||||
{
|
||||
Thread.SpinWait(500);
|
||||
}
|
||||
//while (_udpServer == null)
|
||||
//{
|
||||
// Thread.SpinWait(500);
|
||||
//}
|
||||
|
||||
for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
|
||||
{
|
||||
@ -155,6 +179,109 @@ namespace DS4Windows
|
||||
}
|
||||
}
|
||||
|
||||
private void TestQueueBus(Action temp)
|
||||
{
|
||||
lock (busEvtQueueLock)
|
||||
{
|
||||
busEvtQueue.Enqueue(temp);
|
||||
}
|
||||
|
||||
lock (busThrLck)
|
||||
Monitor.Pulse(busThrLck);
|
||||
}
|
||||
|
||||
public void ChangeUDPStatus(bool state)
|
||||
{
|
||||
if (state && _udpServer == null)
|
||||
{
|
||||
TestQueueBus(() =>
|
||||
{
|
||||
udpChangeStatus = true;
|
||||
_udpServer = new UdpServer(GetPadDetailForIdx);
|
||||
var UDP_SERVER_PORT = Global.getUDPServerPortNum();
|
||||
|
||||
try
|
||||
{
|
||||
_udpServer.Start(UDP_SERVER_PORT);
|
||||
LogDebug("UDP server listening on port " + UDP_SERVER_PORT);
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException ex)
|
||||
{
|
||||
var errMsg = String.Format("Couldn't start UDP server on port {0}, outside applications won't be able to access pad data ({1})", UDP_SERVER_PORT, ex.SocketErrorCode);
|
||||
|
||||
LogDebug(errMsg, true);
|
||||
Log.LogToTray(errMsg, true, true);
|
||||
}
|
||||
|
||||
udpChangeStatus = false;
|
||||
});
|
||||
}
|
||||
else if (!state && _udpServer != null)
|
||||
{
|
||||
TestQueueBus(() =>
|
||||
{
|
||||
udpChangeStatus = true;
|
||||
_udpServer.Stop();
|
||||
_udpServer = null;
|
||||
Log.LogToGui("Closed UDP server", false);
|
||||
udpChangeStatus = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeMotionEventStatus(bool state)
|
||||
{
|
||||
IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers();
|
||||
if (state)
|
||||
{
|
||||
foreach (DS4Device dev in devices)
|
||||
{
|
||||
dev.queueEvent(() =>
|
||||
{
|
||||
dev.Report += dev.MotionEvent;
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (DS4Device dev in devices)
|
||||
{
|
||||
dev.queueEvent(() =>
|
||||
{
|
||||
dev.Report -= dev.MotionEvent;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool udpChangeStatus = false;
|
||||
public bool changingUDPPort = false;
|
||||
public async void UseUDPPort()
|
||||
{
|
||||
changingUDPPort = true;
|
||||
IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers();
|
||||
foreach (DS4Device dev in devices)
|
||||
{
|
||||
dev.queueEvent(() =>
|
||||
{
|
||||
dev.Report -= dev.MotionEvent;
|
||||
});
|
||||
}
|
||||
|
||||
await Task.Delay(100);
|
||||
_udpServer.Start(getUDPServerPortNum());
|
||||
|
||||
foreach (DS4Device dev in devices)
|
||||
{
|
||||
dev.queueEvent(() =>
|
||||
{
|
||||
dev.Report += dev.MotionEvent;
|
||||
});
|
||||
}
|
||||
|
||||
changingUDPPort = false;
|
||||
}
|
||||
|
||||
private void WarnExclusiveModeFailure(DS4Device device)
|
||||
{
|
||||
if (DS4Devices.isExclusiveMode && !device.isExclusive())
|
||||
@ -300,6 +427,15 @@ namespace DS4Windows
|
||||
LogDebug(DS4Devices.isExclusiveMode ? Properties.Resources.UsingExclusive : Properties.Resources.UsingShared);
|
||||
}
|
||||
|
||||
if (isUsingUDPServer() && _udpServer == null)
|
||||
{
|
||||
ChangeUDPStatus(true);
|
||||
while (udpChangeStatus == true)
|
||||
{
|
||||
Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DS4Devices.findControllers();
|
||||
@ -357,17 +493,17 @@ namespace DS4Windows
|
||||
this.On_Report(sender, e, tempIdx);
|
||||
};
|
||||
|
||||
EventHandler<EventArgs> tempEvnt = (sender, args) =>
|
||||
{
|
||||
DualShockPadMeta padDetail = new DualShockPadMeta();
|
||||
GetPadDetailForIdx(tempIdx, ref padDetail);
|
||||
_udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
|
||||
};
|
||||
device.MotionEvent = tempEvnt;
|
||||
|
||||
if (_udpServer != null)
|
||||
{
|
||||
EventHandler<EventArgs> tempEvnt = (sender, args) =>
|
||||
{
|
||||
DualShockPadMeta padDetail = new DualShockPadMeta();
|
||||
GetPadDetailForIdx(tempIdx, ref padDetail);
|
||||
_udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
|
||||
};
|
||||
|
||||
device.Report += tempEvnt;
|
||||
device.MotionEvent = tempEvnt;
|
||||
}
|
||||
|
||||
TouchPadOn(i, device);
|
||||
@ -405,7 +541,8 @@ namespace DS4Windows
|
||||
|
||||
if (_udpServer != null)
|
||||
{
|
||||
var UDP_SERVER_PORT = 26760;
|
||||
//var UDP_SERVER_PORT = 26760;
|
||||
var UDP_SERVER_PORT = Global.getUDPServerPortNum();
|
||||
|
||||
try
|
||||
{
|
||||
@ -491,7 +628,8 @@ namespace DS4Windows
|
||||
DS4Devices.stopControllers();
|
||||
|
||||
if (_udpServer != null)
|
||||
_udpServer.Stop();
|
||||
ChangeUDPStatus(false);
|
||||
//_udpServer.Stop();
|
||||
|
||||
if (showlog)
|
||||
LogDebug(Properties.Resources.StoppedDS4Windows);
|
||||
@ -565,7 +703,20 @@ namespace DS4Windows
|
||||
this.On_Report(sender, e, tempIdx);
|
||||
};
|
||||
|
||||
EventHandler<EventArgs> tempEvnt = (sender, args) =>
|
||||
{
|
||||
DualShockPadMeta padDetail = new DualShockPadMeta();
|
||||
GetPadDetailForIdx(tempIdx, ref padDetail);
|
||||
_udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
|
||||
};
|
||||
device.MotionEvent = tempEvnt;
|
||||
|
||||
if (_udpServer != null)
|
||||
{
|
||||
device.Report += tempEvnt;
|
||||
}
|
||||
|
||||
if (!getDInputOnly(Index) && device.isSynced())
|
||||
{
|
||||
EventHandler<EventArgs> tempEvnt = (sender, args) =>
|
||||
{
|
||||
@ -1083,6 +1234,14 @@ namespace DS4Windows
|
||||
*/
|
||||
}
|
||||
|
||||
/*if (_udpServer != null)
|
||||
{
|
||||
DualShockPadMeta padDetail = new DualShockPadMeta();
|
||||
GetPadDetailForIdx(ind, ref padDetail);
|
||||
_udpServer.NewReportIncoming(ref padDetail, CurrentState[ind]);
|
||||
}
|
||||
*/
|
||||
|
||||
// Output any synthetic events.
|
||||
Mapping.Commit(ind);
|
||||
|
||||
|
@ -569,6 +569,24 @@ namespace DS4Windows
|
||||
return m_Config.flashWhenLateAt;
|
||||
}
|
||||
|
||||
public static bool isUsingUDPServer()
|
||||
{
|
||||
return m_Config.useUDPServ;
|
||||
}
|
||||
public static void setUsingUDPServer(bool state)
|
||||
{
|
||||
m_Config.useUDPServ = state;
|
||||
}
|
||||
|
||||
public static int getUDPServerPortNum()
|
||||
{
|
||||
return m_Config.udpServPort;
|
||||
}
|
||||
public static void setUDPServerPort(int value)
|
||||
{
|
||||
m_Config.udpServPort = value;
|
||||
}
|
||||
|
||||
public static bool UseWhiteIcon
|
||||
{
|
||||
set { m_Config.useWhiteIcon = value; }
|
||||
@ -1472,6 +1490,8 @@ namespace DS4Windows
|
||||
public bool useWhiteIcon;
|
||||
public bool flashWhenLate = true;
|
||||
public int flashWhenLateAt = 20;
|
||||
public bool useUDPServ = false;
|
||||
public int udpServPort = 26760;
|
||||
// Cache whether profile has custom action
|
||||
public bool[] containsCustomAction = new bool[5] { false, false, false, false, false };
|
||||
|
||||
@ -2989,6 +3009,10 @@ namespace DS4Windows
|
||||
catch { missingSetting = true; }
|
||||
try { Item = m_Xdoc.SelectSingleNode("/Profile/WhiteIcon"); Boolean.TryParse(Item.InnerText, out useWhiteIcon); }
|
||||
catch { missingSetting = true; }
|
||||
try { Item = m_Xdoc.SelectSingleNode("/Profile/UseUDPServer"); Boolean.TryParse(Item.InnerText, out useUDPServ); }
|
||||
catch { missingSetting = true; }
|
||||
try { Item = m_Xdoc.SelectSingleNode("/Profile/UDPServerPort"); int temp; int.TryParse(Item.InnerText, out temp); udpServPort = Math.Min(Math.Max(temp, 1024), 65535); }
|
||||
catch { missingSetting = true; }
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
@ -3057,6 +3081,8 @@ namespace DS4Windows
|
||||
XmlNode xmlFlashWhenLate = m_Xdoc.CreateNode(XmlNodeType.Element, "FlashWhenLate", null); xmlFlashWhenLate.InnerText = flashWhenLate.ToString(); Node.AppendChild(xmlFlashWhenLate);
|
||||
XmlNode xmlFlashWhenLateAt = m_Xdoc.CreateNode(XmlNodeType.Element, "FlashWhenLateAt", null); xmlFlashWhenLateAt.InnerText = flashWhenLateAt.ToString(); Node.AppendChild(xmlFlashWhenLateAt);
|
||||
XmlNode xmlWhiteIcon = m_Xdoc.CreateNode(XmlNodeType.Element, "WhiteIcon", null); xmlWhiteIcon.InnerText = useWhiteIcon.ToString(); Node.AppendChild(xmlWhiteIcon);
|
||||
XmlNode xmlUseUDPServ = m_Xdoc.CreateNode(XmlNodeType.Element, "UseUDPServer", null); xmlUseUDPServ.InnerText = useUDPServ.ToString(); Node.AppendChild(xmlUseUDPServ);
|
||||
XmlNode xmlUDPServPort = m_Xdoc.CreateNode(XmlNodeType.Element, "UDPServerPort", null); xmlUDPServPort.InnerText = udpServPort.ToString(); Node.AppendChild(xmlUDPServPort);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
|
55
DS4Windows/DS4Forms/DS4Form.Designer.cs
generated
55
DS4Windows/DS4Forms/DS4Form.Designer.cs
generated
@ -154,6 +154,10 @@
|
||||
this.lbUseXIPorts = new System.Windows.Forms.Label();
|
||||
this.nUDXIPorts = new System.Windows.Forms.NumericUpDown();
|
||||
this.lbLastXIPort = new System.Windows.Forms.Label();
|
||||
this.panel4 = new System.Windows.Forms.Panel();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.ckUdpServ = new System.Windows.Forms.CheckBox();
|
||||
this.nUDUdpPortNum = new System.Windows.Forms.NumericUpDown();
|
||||
this.languagePackComboBox1 = new DS4Windows.DS4Forms.LanguagePackComboBox();
|
||||
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
|
||||
this.linkProfiles = new System.Windows.Forms.LinkLabel();
|
||||
@ -199,6 +203,8 @@
|
||||
((System.ComponentModel.ISupportInitialize)(this.nUDUpdateTime)).BeginInit();
|
||||
this.pnlXIPorts.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nUDXIPorts)).BeginInit();
|
||||
this.panel4.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nUDUdpPortNum)).BeginInit();
|
||||
this.flowLayoutPanel1.SuspendLayout();
|
||||
this.tabLog.SuspendLayout();
|
||||
this.panel3.SuspendLayout();
|
||||
@ -958,6 +964,7 @@
|
||||
this.fLPSettings.Controls.Add(this.cBUpdate);
|
||||
this.fLPSettings.Controls.Add(this.pNUpdate);
|
||||
this.fLPSettings.Controls.Add(this.pnlXIPorts);
|
||||
this.fLPSettings.Controls.Add(this.panel4);
|
||||
this.fLPSettings.Controls.Add(this.languagePackComboBox1);
|
||||
this.fLPSettings.Controls.Add(this.flowLayoutPanel1);
|
||||
this.fLPSettings.Name = "fLPSettings";
|
||||
@ -1209,6 +1216,47 @@
|
||||
resources.ApplyResources(this.lbLastXIPort, "lbLastXIPort");
|
||||
this.lbLastXIPort.Name = "lbLastXIPort";
|
||||
//
|
||||
// panel4
|
||||
//
|
||||
this.panel4.Controls.Add(this.label2);
|
||||
this.panel4.Controls.Add(this.ckUdpServ);
|
||||
this.panel4.Controls.Add(this.nUDUdpPortNum);
|
||||
resources.ApplyResources(this.panel4, "panel4");
|
||||
this.panel4.Name = "panel4";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
resources.ApplyResources(this.label2, "label2");
|
||||
this.label2.Name = "label2";
|
||||
//
|
||||
// ckUdpServ
|
||||
//
|
||||
resources.ApplyResources(this.ckUdpServ, "ckUdpServ");
|
||||
this.ckUdpServ.Name = "ckUdpServ";
|
||||
this.ckUdpServ.UseVisualStyleBackColor = true;
|
||||
this.ckUdpServ.CheckedChanged += new System.EventHandler(this.CkUdpServ_CheckedChanged);
|
||||
//
|
||||
// nUDUdpPortNum
|
||||
//
|
||||
resources.ApplyResources(this.nUDUdpPortNum, "nUDUdpPortNum");
|
||||
this.nUDUdpPortNum.Maximum = new decimal(new int[] {
|
||||
65535,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.nUDUdpPortNum.Minimum = new decimal(new int[] {
|
||||
1024,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.nUDUdpPortNum.Name = "nUDUdpPortNum";
|
||||
this.nUDUdpPortNum.Value = new decimal(new int[] {
|
||||
26760,
|
||||
0,
|
||||
0,
|
||||
0});
|
||||
this.nUDUdpPortNum.Leave += new System.EventHandler(this.NUDUdpPortNum_Leave);
|
||||
//
|
||||
// languagePackComboBox1
|
||||
//
|
||||
resources.ApplyResources(this.languagePackComboBox1, "languagePackComboBox1");
|
||||
@ -1399,6 +1447,9 @@
|
||||
this.pnlXIPorts.ResumeLayout(false);
|
||||
this.pnlXIPorts.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nUDXIPorts)).EndInit();
|
||||
this.panel4.ResumeLayout(false);
|
||||
this.panel4.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.nUDUdpPortNum)).EndInit();
|
||||
this.flowLayoutPanel1.ResumeLayout(false);
|
||||
this.flowLayoutPanel1.PerformLayout();
|
||||
this.tabLog.ResumeLayout(false);
|
||||
@ -1555,6 +1606,10 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem discon3ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem discon4ToolStripMenuItem;
|
||||
private System.Windows.Forms.CheckBox mintoTaskCheckBox;
|
||||
private System.Windows.Forms.Panel panel4;
|
||||
private System.Windows.Forms.Label label2;
|
||||
private System.Windows.Forms.CheckBox ckUdpServ;
|
||||
private System.Windows.Forms.NumericUpDown nUDUdpPortNum;
|
||||
//private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2;
|
||||
}
|
||||
}
|
||||
|
@ -400,6 +400,9 @@ namespace DS4Windows
|
||||
StartWindowsCheckBox.CheckedChanged += new EventHandler(StartWindowsCheckBox_CheckedChanged);
|
||||
new ToolTip().SetToolTip(StartWindowsCheckBox, Properties.Resources.RunAtStartup);
|
||||
|
||||
ckUdpServ.Checked = isUsingUDPServer();
|
||||
nUDUdpPortNum.Value = getUDPServerPortNum();
|
||||
|
||||
populateHoverTextDict();
|
||||
|
||||
cBController1.KeyPress += CBController_KeyPress;
|
||||
@ -2544,6 +2547,38 @@ Properties.Resources.DS4Update, MessageBoxButtons.YesNo, MessageBoxIcon.Question
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private async void CkUdpServ_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
bool state = ckUdpServ.Checked;
|
||||
setUsingUDPServer(state);
|
||||
if (!state)
|
||||
{
|
||||
Program.rootHub.ChangeMotionEventStatus(state);
|
||||
await TaskRunner.Delay(100);
|
||||
Program.rootHub.ChangeUDPStatus(state);
|
||||
}
|
||||
else
|
||||
{
|
||||
Program.rootHub.ChangeUDPStatus(state);
|
||||
Program.rootHub.ChangeMotionEventStatus(state);
|
||||
}
|
||||
|
||||
nUDUdpPortNum.Enabled = state;
|
||||
}
|
||||
|
||||
private void NUDUdpPortNum_Leave(object sender, EventArgs e)
|
||||
{
|
||||
nUDUdpPortNum.Enabled = false;
|
||||
setUDPServerPort((int)nUDUdpPortNum.Value);
|
||||
WaitUDPPortChange();
|
||||
}
|
||||
|
||||
private async void WaitUDPPortChange()
|
||||
{
|
||||
await TaskRunner.Run(() => Program.rootHub.UseUDPPort());
|
||||
nUDUdpPortNum.Enabled = true;
|
||||
}
|
||||
|
||||
private void cBFlashWhenLate_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
FlashWhenLate = cBFlashWhenLate.Checked;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,12 +8,12 @@ You can find the latest and older versions [here](https://github.com/Ryochan7/DS
|
||||
|
||||
UdpServer builds for using Gyro motion controls in Cemu.
|
||||
|
||||
http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.1_UdpServer_x64.zip
|
||||
http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.1_ViGEm_UdpServer_x64.zip
|
||||
http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.2_UdpServer_x64.zip
|
||||
http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.2_ViGEm_UdpServer_x64.zip
|
||||
|
||||
ViGEm build.
|
||||
|
||||
http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.1_ViGEm_x64.zip
|
||||
http://ryochan7.xyz/ds4windows/test/DS4Windows_1.5.2_ViGEm_x64.zip
|
||||
|
||||
This project is a fork of the work of Jays2Kings. You can find the old project
|
||||
website at [ds4windows.com](http://ds4windows.com).
|
||||
|
Loading…
Reference in New Issue
Block a user