Skip to content

Instantly share code, notes, and snippets.

@Ryochan7
Created August 3, 2018 02:54
Show Gist options
  • Save Ryochan7/cefcd5b658f03d7e214fda5b9f6739af to your computer and use it in GitHub Desktop.
Save Ryochan7/cefcd5b658f03d7e214fda5b9f6739af to your computer and use it in GitHub Desktop.
Current misadventures with the UDP server code
diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs
index f2b19d5..80e7408 100644
--- a/DS4Windows/DS4Control/ControlService.cs
+++ b/DS4Windows/DS4Control/ControlService.cs
@@ -141,8 +141,43 @@ namespace DS4Windows
PreviousState[i] = new DS4State();
ExposedState[i] = new DS4StateExposed(CurrentState[i]);
}
+
+ boob = new ManualResetEvent(false);
+ damnit = new Thread(() =>
+ {
+
+ boob = new ManualResetEvent(false);
+ Action[] actArr = null;
+ while (!exitUdpThread)
+ {
+ boob.WaitOne();
+ boob.Reset();
+
+ lock (fucklock)
+ {
+ actArr = testfuck.ToArray();
+ }
+
+ for (int ind = 0, arlen = actArr.Length; ind < arlen; ind++)
+ //foreach (Action temp in testfuck)
+ {
+ Action temp = actArr[ind];
+ temp.Invoke();
+ }
+ }
+ });
+
+ damnit.Priority = ThreadPriority.Normal;
+ damnit.IsBackground = true;
}
+ private Queue<Action> testfuck = new Queue<Action>();
+ private object fucklock = new object();
+ private bool exitUdpThread = false;
+
+ private Thread damnit = null;
+ private ManualResetEvent boob;
+
private void WarnExclusiveModeFailure(DS4Device device)
{
if (DS4Devices.isExclusiveMode && !device.isExclusive())
@@ -323,7 +358,14 @@ namespace DS4Windows
{
DualShockPadMeta padDetail = new DualShockPadMeta();
GetPadDetailForIdx(tempIdx, ref padDetail);
- _udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
+ UdpDS4Report fuck = new UdpDS4Report(CurrentState[tempIdx]);
+ lock (fucklock)
+ testfuck.Enqueue(() =>
+ {
+ _udpServer.NewReportIncoming(ref padDetail, ref fuck);
+ });
+ boob.Set();
+ //_udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
};
device.Report += tempEvnt;
@@ -398,6 +440,7 @@ namespace DS4Windows
{
running = false;
runHotPlug = false;
+ exitUdpThread = true;
if (showlog)
LogDebug(Properties.Resources.StoppingX360);
@@ -536,7 +579,7 @@ namespace DS4Windows
{
DualShockPadMeta padDetail = new DualShockPadMeta();
GetPadDetailForIdx(tempIdx, ref padDetail);
- _udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
+ // _udpServer.NewReportIncoming(ref padDetail, CurrentState[tempIdx]);
};
device.Report += tempEvnt;
diff --git a/DS4Windows/DS4Control/UdpServer.cs b/DS4Windows/DS4Control/UdpServer.cs
index dfd4cfc..1b73b8e 100644
--- a/DS4Windows/DS4Control/UdpServer.cs
+++ b/DS4Windows/DS4Control/UdpServer.cs
@@ -412,7 +412,7 @@ namespace DS4Windows
}
}
- private bool ReportToBuffer(DS4State hidReport, byte[] outputData, ref int outIdx)
+ private bool ReportToBuffer(ref UdpDS4Report hidReport, byte[] outputData, ref int outIdx)
{
outputData[outIdx] = 0;
@@ -484,49 +484,34 @@ namespace DS4Windows
}
//motion timestamp
- if (hidReport.Motion != null)
- Array.Copy(BitConverter.GetBytes((ulong)hidReport.totalMicroSec), 0, outputData, outIdx, 8);
- else
- Array.Clear(outputData, outIdx, 8);
+ Array.Copy(BitConverter.GetBytes((ulong)hidReport.totalMicroSec), 0, outputData, outIdx, 8);
outIdx += 8;
//accelerometer
- if (hidReport.Motion != null)
{
- Array.Copy(BitConverter.GetBytes((float)hidReport.Motion.accelXG), 0, outputData, outIdx, 4);
+ Array.Copy(BitConverter.GetBytes((float)hidReport.accelXG), 0, outputData, outIdx, 4);
outIdx += 4;
- Array.Copy(BitConverter.GetBytes((float)hidReport.Motion.accelYG), 0, outputData, outIdx, 4);
+ Array.Copy(BitConverter.GetBytes((float)hidReport.accelYG), 0, outputData, outIdx, 4);
outIdx += 4;
- Array.Copy(BitConverter.GetBytes((float)-hidReport.Motion.accelZG), 0, outputData, outIdx, 4);
+ Array.Copy(BitConverter.GetBytes((float)-hidReport.accelZG), 0, outputData, outIdx, 4);
outIdx += 4;
}
- else
- {
- Array.Clear(outputData, outIdx, 12);
- outIdx += 12;
- }
//gyroscope
- if (hidReport.Motion != null)
{
- Array.Copy(BitConverter.GetBytes((float)hidReport.Motion.angVelPitch), 0, outputData, outIdx, 4);
+ Array.Copy(BitConverter.GetBytes((float)hidReport.angVelPitch), 0, outputData, outIdx, 4);
outIdx += 4;
- Array.Copy(BitConverter.GetBytes((float)hidReport.Motion.angVelYaw), 0, outputData, outIdx, 4);
+ Array.Copy(BitConverter.GetBytes((float)hidReport.angVelYaw), 0, outputData, outIdx, 4);
outIdx += 4;
- Array.Copy(BitConverter.GetBytes((float)hidReport.Motion.angVelRoll), 0, outputData, outIdx, 4);
+ Array.Copy(BitConverter.GetBytes((float)hidReport.angVelRoll), 0, outputData, outIdx, 4);
outIdx += 4;
}
- else
- {
- Array.Clear(outputData, outIdx, 12);
- outIdx += 12;
- }
return true;
}
- public void NewReportIncoming(ref DualShockPadMeta padMeta, DS4State hidReport)
+ public void NewReportIncoming(ref DualShockPadMeta padMeta, ref UdpDS4Report hidReport)
{
if (!running)
return;
@@ -614,7 +599,7 @@ namespace DS4Windows
Array.Copy(BitConverter.GetBytes((uint)hidReport.PacketCounter), 0, outputData, outIdx, 4);
outIdx += 4;
- if (!ReportToBuffer(hidReport, outputData, ref outIdx))
+ if (!ReportToBuffer(ref hidReport, outputData, ref outIdx))
return;
else
FinishPacket(outputData);
diff --git a/DS4Windows/DS4Windows.csproj b/DS4Windows/DS4Windows.csproj
index ad184a8..96f9139 100644
--- a/DS4Windows/DS4Windows.csproj
+++ b/DS4Windows/DS4Windows.csproj
@@ -154,6 +154,7 @@
<DependentUpon>ScpDevice.cs</DependentUpon>
</Compile>
<Compile Include="DS4Control\ScpUtil.cs" />
+ <Compile Include="DS4Control\UdpDS4Report.cs" />
<Compile Include="DS4Control\UdpServer.cs" />
<Compile Include="DS4Control\X360Device.cs">
<SubType>Component</SubType>
diff --git a/DS4Windows/Properties/Settings.Designer.cs b/DS4Windows/Properties/Settings.Designer.cs
index 8249a9b..441c463 100644
--- a/DS4Windows/Properties/Settings.Designer.cs
+++ b/DS4Windows/Properties/Settings.Designer.cs
@@ -22,5 +22,17 @@ namespace DS4Windows.Properties {
return defaultInstance;
}
}
+
+ [global::System.Configuration.UserScopedSettingAttribute()]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Configuration.DefaultSettingValueAttribute("")]
+ public string Setting {
+ get {
+ return ((string)(this["Setting"]));
+ }
+ set {
+ this["Setting"] = value;
+ }
+ }
}
}
diff --git a/DS4Windows/app.config b/DS4Windows/app.config
index d23be82..0b3b3a8 100644
--- a/DS4Windows/app.config
+++ b/DS4Windows/app.config
@@ -7,5 +7,6 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Lang"/>
</assemblyBinding>
+ <gcConcurrent enabled="false" />
</runtime>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment