Test hotplug changes. Change mouse remainder cutoff

This commit is contained in:
Travis Nickles 2017-06-11 08:15:45 -07:00
parent 7bf43f93f5
commit 2cf33e1bba
4 changed files with 63 additions and 29 deletions

View File

@ -131,6 +131,7 @@ namespace DS4Windows
WarnExclusiveModeFailure(device); WarnExclusiveModeFailure(device);
DS4Controllers[i] = device; DS4Controllers[i] = device;
device.setUiContext(SynchronizationContext.Current);
device.Removal += this.On_DS4Removal; device.Removal += this.On_DS4Removal;
device.Removal += DS4Devices.On_Removal; device.Removal += DS4Devices.On_Removal;
device.SyncChange += DS4Devices.UpdateSerial; device.SyncChange += DS4Devices.UpdateSerial;
@ -270,29 +271,10 @@ namespace DS4Windows
return true; return true;
} }
public bool HotPlug() public bool HotPlug(SynchronizationContext uiContext)
{ {
if (running) if (running)
{ {
// Do first run check for Quick Charge checks. Needed so old device will
// be removed before performing another controller scan
/*if (getQuickCharge())
{
for (int i = 0, devlen = DS4Controllers.Length; i < devlen; i++)
{
DS4Device device = DS4Controllers[i];
if (device != null)
{
if (device.getConnectionType() == ConnectionType.BT && device.isCharging())
{
device.StopUpdate();
device.DisconnectBT(true);
}
}
}
}
*/
DS4Devices.findControllers(); DS4Devices.findControllers();
IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers(); IEnumerable<DS4Device> devices = DS4Devices.getDS4Controllers();
//foreach (DS4Device device in devices) //foreach (DS4Device device in devices)
@ -325,6 +307,7 @@ namespace DS4Windows
LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")"); LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
WarnExclusiveModeFailure(device); WarnExclusiveModeFailure(device);
DS4Controllers[Index] = device; DS4Controllers[Index] = device;
device.setUiContext(uiContext);
device.Removal += this.On_DS4Removal; device.Removal += this.On_DS4Removal;
device.Removal += DS4Devices.On_Removal; device.Removal += DS4Devices.On_Removal;
device.SyncChange += DS4Devices.UpdateSerial; device.SyncChange += DS4Devices.UpdateSerial;

View File

@ -2537,7 +2537,9 @@ namespace DS4Windows
horizontalRemainder = 0.0; horizontalRemainder = 0.0;
} }
double mouseXTemp = rawMouseX - (Math.IEEERemainder(rawMouseX * 1000.0, 1.0) / 1000.0); //double mouseXTemp = rawMouseX - (Math.IEEERemainder(rawMouseX * 1000.0, 1.0) / 1000.0);
double mouseXTemp = rawMouseX - (remainderCutoff(rawMouseX * 1000.0, 1.0) / 1000.0);
//double mouseXTemp = rawMouseX - (rawMouseX * 1000.0 - (1.0 * (int)(rawMouseX * 1000.0 / 1.0)));
mouseX = (int)mouseXTemp; mouseX = (int)mouseXTemp;
horizontalRemainder = mouseXTemp - mouseX; horizontalRemainder = mouseXTemp - mouseX;
//mouseX = (int)rawMouseX; //mouseX = (int)rawMouseX;
@ -2552,13 +2554,19 @@ namespace DS4Windows
verticalRemainder = 0.0; verticalRemainder = 0.0;
} }
double mouseYTemp = rawMouseY - (Math.IEEERemainder(rawMouseY * 1000.0, 1.0) / 1000.0); //double mouseYTemp = rawMouseY - (Math.IEEERemainder(rawMouseY * 1000.0, 1.0) / 1000.0);
double mouseYTemp = rawMouseY - (remainderCutoff(rawMouseY * 1000.0, 1.0) / 1000.0);
mouseY = (int)mouseYTemp; mouseY = (int)mouseYTemp;
verticalRemainder = mouseYTemp - mouseY; verticalRemainder = mouseYTemp - mouseY;
//mouseY = (int)rawMouseY; //mouseY = (int)rawMouseY;
//verticalRemainder = rawMouseY - mouseY; //verticalRemainder = rawMouseY - mouseY;
} }
private static double remainderCutoff(double dividend, double divisor)
{
return dividend - (divisor * (int)(dividend / divisor));
}
public static bool compare(byte b1, byte b2) public static bool compare(byte b1, byte b2)
{ {
bool result = true; bool result = true;

View File

@ -1005,7 +1005,9 @@ namespace DS4Windows
lbLastMessage.Text = string.Empty; lbLastMessage.Text = string.Empty;
} }
bool inHotPlug = false; private bool inHotPlug = false;
private int hotplugCounter = 0;
private object hotplugCounterLock = new object();
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
try try
@ -1015,10 +1017,18 @@ namespace DS4Windows
if (runHotPlug) if (runHotPlug)
{ {
Int32 Type = m.WParam.ToInt32(); Int32 Type = m.WParam.ToInt32();
lock (hotplugCounterLock)
{
hotplugCounter++;
}
if (!inHotPlug)
{
InnerHotplug2(); InnerHotplug2();
} }
} }
} }
}
catch { } catch { }
if (m.Msg == WM_QUERYENDSESSION) if (m.Msg == WM_QUERYENDSESSION)
systemShutdown = true; systemShutdown = true;
@ -1031,17 +1041,35 @@ namespace DS4Windows
protected async void InnerHotplug2() protected async void InnerHotplug2()
{ {
await System.Threading.Tasks.Task.Delay(50); //await System.Threading.Tasks.Task.Delay(50);
if (inHotPlug) /*if (inHotPlug)
{ {
await System.Threading.Tasks.Task.Run(() => { while (inHotPlug) { System.Threading.Thread.Sleep(50); } }); await System.Threading.Tasks.Task.Run(() => { while (inHotPlug) { System.Threading.Thread.Sleep(50); } });
} }
*/
lock (this) //lock (this)
{ {
inHotPlug = true; inHotPlug = true;
Program.rootHub.HotPlug(); System.Threading.SynchronizationContext uiContext = System.Threading.SynchronizationContext.Current;
int tempCount = 0;
lock (hotplugCounterLock)
{
tempCount = hotplugCounter;
}
while (tempCount > 0)
{
await System.Threading.Tasks.Task.Run(() => { Program.rootHub.HotPlug(uiContext); });
lock (hotplugCounterLock)
{
hotplugCounter--;
tempCount = hotplugCounter;
}
}
//Program.rootHub.HotPlug();
inHotPlug = false; inHotPlug = false;
} }
} }

View File

@ -164,6 +164,7 @@ namespace DS4Windows
public event EventHandler<EventArgs> Removal = null; public event EventHandler<EventArgs> Removal = null;
public event EventHandler<EventArgs> SyncChange = null; public event EventHandler<EventArgs> SyncChange = null;
public event EventHandler<EventArgs> SerialChange = null; public event EventHandler<EventArgs> SerialChange = null;
public event EventHandler<EventArgs> PublishRemoval = null;
public HidDevice HidDevice => hDevice; public HidDevice HidDevice => hDevice;
public bool IsExclusive => HidDevice.IsExclusive; public bool IsExclusive => HidDevice.IsExclusive;
@ -388,6 +389,10 @@ namespace DS4Windows
{ {
return uiContext; return uiContext;
} }
public void setUiContext(SynchronizationContext uiContext)
{
this.uiContext = uiContext;
}
private Queue<Action> eventQueue = new Queue<Action>(); private Queue<Action> eventQueue = new Queue<Action>();
private object eventQueueLock = new object(); private object eventQueueLock = new object();
@ -432,7 +437,6 @@ namespace DS4Windows
touchpad = new DS4Touchpad(); touchpad = new DS4Touchpad();
sixAxis = new DS4SixAxis(); sixAxis = new DS4SixAxis();
uiContext = SynchronizationContext.Current;
} }
private void timeoutTestThread() private void timeoutTestThread()
@ -699,6 +703,9 @@ namespace DS4Windows
Removal?.Invoke(this, EventArgs.Empty); Removal?.Invoke(this, EventArgs.Empty);
}), null); }), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
//Removal?.Invoke(this, EventArgs.Empty);
timeoutExecuted = true; timeoutExecuted = true;
return; return;
} }
@ -730,6 +737,9 @@ namespace DS4Windows
Removal?.Invoke(this, EventArgs.Empty); Removal?.Invoke(this, EventArgs.Empty);
}), null); }), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
//Removal?.Invoke(this, EventArgs.Empty);
timeoutExecuted = true; timeoutExecuted = true;
return; return;
} }
@ -1089,6 +1099,8 @@ namespace DS4Windows
{ {
Removal?.Invoke(this, EventArgs.Empty); Removal?.Invoke(this, EventArgs.Empty);
}), null); }), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
} }
} }
@ -1120,6 +1132,9 @@ namespace DS4Windows
{ {
Removal?.Invoke(this, EventArgs.Empty); Removal?.Invoke(this, EventArgs.Empty);
}), null); }), null);
//System.Threading.Tasks.Task.Factory.StartNew(() => { Removal?.Invoke(this, EventArgs.Empty); });
//Removal?.Invoke(this, EventArgs.Empty);
} }
else if (result && !remove) else if (result && !remove)
{ {