public void TimerAccuracy(float interval, float duration) { // Skip test when running on Github CI due to high variance in timer latency. if (Environment.GetEnvironmentVariable("CI") is "true") { return; } var expectedFires = (int)(interval * 1000 / interval * duration); var timer = DesktopInterop.Timer; var list = new List <double>(expectedFires); var watch = new HPETDeltaStopwatch(true); timer.Interval = interval; timer.Elapsed += () => { list.Add(watch.Restart().TotalMilliseconds); }; timer.Start(); Thread.Sleep(TimeSpan.FromSeconds(duration)); timer.Stop(); // Windows timers are not guaranteed to stop immediately Thread.Sleep(TimeSpan.FromMilliseconds(50)); var average = list.Average(); var intervalTolerance = interval * TOLERANCE; var minimum = interval - intervalTolerance; var maximum = interval + intervalTolerance; var withinTolerance = (average > minimum) && (average < maximum); Assert.True(withinTolerance); }
public Vector2 Filter(Vector2 target) { Vector2 direction = target - cursor; float distToMove = SampleRadialCurve(direction.Length()); direction = Vector2.Normalize(direction); cursor = cursor + Vector2.Multiply(direction, distToMove); // Catch NaNs and pen redetection if (!(float.IsFinite(cursor.X) & float.IsFinite(cursor.Y) & stopwatch.Restart().TotalMilliseconds < 50)) { cursor = target; } return(cursor); }
public IDeviceReport Debounce(IDeviceReport input) { if (input is ITabletReport tabletReport) { if (!Drop_excess) { if (tabletReport.Pressure < Pressure_threshold) //pressure less than threshold { if (debounceStopwatch.Elapsed.TotalMilliseconds <= Debounce_timer) //pressure less than threshold and elapsed time less than or equal to debounce timer { tabletReport.Pressure = last_pressure; return(input); } else //pressure less than threshold and elapsed time greater than debounce timer { debounceStopwatch.Restart(); last_pressure = tabletReport.Pressure; return(input); } } else //pressure greater than threshold { if (!Disable_timer) { debounceStopwatch.Restart(); } last_pressure = tabletReport.Pressure; return(input); } } else { if (tabletReport.Pressure > Pressure_threshold) //pressure greater than thereshold { if (debounceStopwatch.Elapsed.TotalMilliseconds <= Debounce_timer) //pressure greater than threshold and elapsed time less than or equal to debounce timer { if (last_pressure < Pressure_threshold) //pressure greater than threshold, elapsed time less than or equal to debounce timer, and last pressure less than threshold { if (!Disable_timer) { debounceStopwatch.Restart(); } tabletReport.Pressure = 0; return(input); } else //pressure greater than threshold, elapsed time less than or equal to debounce timer, and last pressure greater or equal to threshold { return(input); } } else //pressure greater than threshold and elapsed time greater than debounce timer { last_pressure = tabletReport.Pressure; debounceStopwatch.Restart(); return(input); } } else //pressure less than threshold { last_pressure = tabletReport.Pressure; return(input); } } } else { return(input); } }