forked from nefarius/ScpToolkit
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from rajkosto/master
Merge of rajkosto ScpToolkit gyro fixes/improvements
- Loading branch information
Showing
21 changed files
with
1,867 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using ScpControl.Shared.Win32; | ||
using System.ComponentModel; | ||
|
||
namespace ScpControl.Shared.Utilities | ||
{ | ||
public class AccurateTime | ||
{ | ||
private long value; | ||
static private double scale; | ||
|
||
static AccurateTime() //figure out QPF only once | ||
{ | ||
long currentQpf = 0; | ||
if (!Kernel32Natives.QueryPerformanceFrequency(out currentQpf)) | ||
throw new Win32Exception(); | ||
|
||
scale = 1.0 / (double)currentQpf; | ||
} | ||
|
||
public AccurateTime(long timeSpan) | ||
{ | ||
value = timeSpan; | ||
} | ||
|
||
static public AccurateTime Now | ||
{ | ||
get | ||
{ | ||
long currentQpc; | ||
if (!Kernel32Natives.QueryPerformanceCounter(out currentQpc)) | ||
throw new Win32Exception(); | ||
|
||
return new AccurateTime(currentQpc); | ||
} | ||
} | ||
|
||
public static AccurateTime operator+(AccurateTime startTime, AccurateTime span) | ||
{ | ||
return new AccurateTime(startTime.value + span.value); | ||
} | ||
public static AccurateTime operator-(AccurateTime startTime, AccurateTime span) | ||
{ | ||
return new AccurateTime(startTime.value - span.value); | ||
} | ||
|
||
public double ToSeconds() | ||
{ | ||
return (double)(value) * scale; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return ToSeconds().ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.