Minor performance tweaks for input thread

This commit is contained in:
Travis Nickles 2017-06-24 19:10:09 -07:00
parent 64693190f0
commit 4dfb2cf0db

View File

@ -642,6 +642,9 @@ namespace DS4Windows
public bool oldCharging = false; public bool oldCharging = false;
double curTimeDouble = 0.0; double curTimeDouble = 0.0;
double oldTimeDouble = 0.0; double oldTimeDouble = 0.0;
DateTime utcNow = DateTime.UtcNow;
bool ds4InactiveFrame = true;
bool idleInput = true;
private void performDs4Input() private void performDs4Input()
{ {
@ -656,6 +659,8 @@ namespace DS4Windows
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
timeoutEvent = false; timeoutEvent = false;
ds4InactiveFrame = true;
idleInput = true;
int maxBatteryValue = 0; int maxBatteryValue = 0;
int tempBattery = 0; int tempBattery = 0;
@ -769,7 +774,7 @@ namespace DS4Windows
continue; continue;
} }
DateTime utcNow = DateTime.UtcNow; // timestamp with UTC in case system time zone changes utcNow = DateTime.UtcNow; // timestamp with UTC in case system time zone changes
resetHapticState(); resetHapticState();
cState.ReportTimeStamp = utcNow; cState.ReportTimeStamp = utcNow;
cState.LX = inputReport[1]; cState.LX = inputReport[1];
@ -876,7 +881,7 @@ namespace DS4Windows
} }
} }
bool ds4InactiveFrame = cState.FrameCounter == pState.FrameCounter; ds4InactiveFrame = cState.FrameCounter == pState.FrameCounter;
if (!ds4InactiveFrame) if (!ds4InactiveFrame)
{ {
isRemoved = false; isRemoved = false;
@ -888,17 +893,21 @@ namespace DS4Windows
{ {
lastActive = utcNow; lastActive = utcNow;
} }
else if (!isDS4Idle()) else
{
idleInput = isDS4Idle();
if (!idleInput)
{ {
lastActive = utcNow; lastActive = utcNow;
} }
} }
}
else else
{ {
bool shouldDisconnect = false; bool shouldDisconnect = false;
if (!isRemoved && idleTimeout > 0) if (!isRemoved && idleTimeout > 0)
{ {
bool idleInput = isDS4Idle(); idleInput = isDS4Idle();
if (idleInput) if (idleInput)
{ {
DateTime timeout = lastActive + TimeSpan.FromSeconds(idleTimeout); DateTime timeout = lastActive + TimeSpan.FromSeconds(idleTimeout);