mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2025-02-18 08:56:20 +01:00
Stop using Async methods for FileStream instance. Reduce CPU usage. Initial thread action queue.
No longer uses an application set timeout but it looks like a timeout will be handled by the system
This commit is contained in:
parent
7a1b382c5a
commit
bca7850a36
@ -516,7 +516,20 @@ namespace DS4Windows
|
|||||||
if (removingStatus)
|
if (removingStatus)
|
||||||
{
|
{
|
||||||
CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
|
CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
|
||||||
x360Bus.Unplug(ind);
|
if (!useDInputOnly[ind])
|
||||||
|
{
|
||||||
|
bool unplugResult = x360Bus.Unplug(ind);
|
||||||
|
int xinputIndex = x360Bus.FirstController + ind;
|
||||||
|
if (unplugResult)
|
||||||
|
{
|
||||||
|
LogDebug("X360 Controller # " + xinputIndex + " unplugged");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogDebug("X360 Controller # " + xinputIndex + " failed to unplug");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString());
|
string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString());
|
||||||
if (device.getBattery() <= 20 &&
|
if (device.getBattery() <= 20 &&
|
||||||
device.getConnectionType() == ConnectionType.BT && !device.isCharging())
|
device.getConnectionType() == ConnectionType.BT && !device.isCharging())
|
||||||
|
@ -352,6 +352,8 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SynchronizationContext uiContext = null;
|
private SynchronizationContext uiContext = null;
|
||||||
|
private Queue<Action> eventQueue = new Queue<Action>();
|
||||||
|
private object eventQueueLock = new object();
|
||||||
|
|
||||||
public DS4Device(HidDevice hidDevice)
|
public DS4Device(HidDevice hidDevice)
|
||||||
{
|
{
|
||||||
@ -479,7 +481,8 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return hDevice.WriteAsyncOutputReportViaInterrupt(outputReport);
|
return hDevice.WriteOutputReportViaInterrupt(outputReport, READ_STREAM_TIMEOUT);
|
||||||
|
//return hDevice.WriteAsyncOutputReportViaInterrupt(outputReport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,14 +570,15 @@ namespace DS4Windows
|
|||||||
if (conType == ConnectionType.BT)
|
if (conType == ConnectionType.BT)
|
||||||
{
|
{
|
||||||
//HidDevice.ReadStatus res = hDevice.ReadFile(btInputReport);
|
//HidDevice.ReadStatus res = hDevice.ReadFile(btInputReport);
|
||||||
HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT);
|
//HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(btInputReport, READ_STREAM_TIMEOUT);
|
||||||
|
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(btInputReport);
|
||||||
|
//HidDevice.ReadStatus res = hDevice.ReadFileOverlapped(btInputReport, READ_STREAM_TIMEOUT);
|
||||||
if (res == HidDevice.ReadStatus.Success)
|
if (res == HidDevice.ReadStatus.Success)
|
||||||
{
|
{
|
||||||
Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length);
|
Array.Copy(btInputReport, 2, inputReport, 0, inputReport.Length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
if (res == HidDevice.ReadStatus.WaitTimedOut)
|
if (res == HidDevice.ReadStatus.WaitTimedOut)
|
||||||
{
|
{
|
||||||
Log.LogToGui(Mac.ToString() + " disconnected due to timeout", true);
|
Log.LogToGui(Mac.ToString() + " disconnected due to timeout", true);
|
||||||
@ -595,14 +599,15 @@ namespace DS4Windows
|
|||||||
}), null);
|
}), null);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//HidDevice.ReadStatus res = hDevice.ReadFile(inputReport);
|
//HidDevice.ReadStatus res = hDevice.ReadFile(inputReport);
|
||||||
//Array.Clear(inputReport, 0, inputReport.Length);
|
//Array.Clear(inputReport, 0, inputReport.Length);
|
||||||
HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT);
|
//HidDevice.ReadStatus res = hDevice.ReadAsyncWithFileStream(inputReport, READ_STREAM_TIMEOUT);
|
||||||
|
HidDevice.ReadStatus res = hDevice.ReadWithFileStream(inputReport);
|
||||||
|
//HidDevice.ReadStatus res = hDevice.ReadFileOverlapped(inputReport, READ_STREAM_TIMEOUT);
|
||||||
if (res != HidDevice.ReadStatus.Success)
|
if (res != HidDevice.ReadStatus.Success)
|
||||||
{
|
{
|
||||||
if (res == HidDevice.ReadStatus.WaitTimedOut)
|
if (res == HidDevice.ReadStatus.WaitTimedOut)
|
||||||
@ -797,6 +802,18 @@ namespace DS4Windows
|
|||||||
error = currerror;
|
error = currerror;
|
||||||
|
|
||||||
cState.CopyTo(pState);
|
cState.CopyTo(pState);
|
||||||
|
|
||||||
|
/*lock (eventQueueLock)
|
||||||
|
{
|
||||||
|
Action tempAct = null;
|
||||||
|
//while (eventQueue.TryDequeue(out tempAct))
|
||||||
|
for (int actInd = 0, actLen = eventQueue.Count; actInd < actLen; actInd++)
|
||||||
|
{
|
||||||
|
tempAct = eventQueue.Dequeue();
|
||||||
|
tempAct.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1117,5 +1134,13 @@ namespace DS4Windows
|
|||||||
{
|
{
|
||||||
this.Report = null;
|
this.Report = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void queueEvent(Action act)
|
||||||
|
{
|
||||||
|
lock (eventQueueLock)
|
||||||
|
{
|
||||||
|
eventQueue.Enqueue(act);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,6 +242,25 @@ namespace DS4Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReadStatus ReadWithFileStream(byte[] inputBuffer)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (fileStream.Read(inputBuffer, 0, inputBuffer.Length) > 0)
|
||||||
|
{
|
||||||
|
return ReadStatus.Success;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return ReadStatus.NoDataRead;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return ReadStatus.ReadError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ReadStatus ReadWithFileStream(byte[] inputBuffer, int timeout)
|
public ReadStatus ReadWithFileStream(byte[] inputBuffer, int timeout)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
Loading…
x
Reference in New Issue
Block a user