Add support for asynchronous event via Nonblocking
This commit is contained in:
parent
0c8028c0a8
commit
6b16cee62b
11
Program.cs
11
Program.cs
@ -16,7 +16,10 @@ namespace SpaceNavWrapper
|
|||||||
//}
|
//}
|
||||||
SpaceNav navDriver = new SpaceNav();
|
SpaceNav navDriver = new SpaceNav();
|
||||||
navDriver.InitDevice();
|
navDriver.InitDevice();
|
||||||
navDriver.Button += OnButton;
|
navDriver.Button += delegate (object sender, ButtonEventArgs e)
|
||||||
|
{
|
||||||
|
navDriver.Nonblocking = !navDriver.Nonblocking;
|
||||||
|
};
|
||||||
navDriver.Motion += OnMotion;
|
navDriver.Motion += OnMotion;
|
||||||
|
|
||||||
Console.CancelKeyPress += delegate {
|
Console.CancelKeyPress += delegate {
|
||||||
@ -25,6 +28,7 @@ namespace SpaceNavWrapper
|
|||||||
for (; ; )
|
for (; ; )
|
||||||
{
|
{
|
||||||
navDriver.WaitEvent();
|
navDriver.WaitEvent();
|
||||||
|
Console.WriteLine("AA");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,10 +36,5 @@ namespace SpaceNavWrapper
|
|||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
Console.WriteLine(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void OnButton(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
Console.WriteLine(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
63
SpaceNav.cs
63
SpaceNav.cs
@ -20,6 +20,7 @@ namespace SpaceNavWrapper
|
|||||||
|
|
||||||
private double _sensitivity = 1.0;
|
private double _sensitivity = 1.0;
|
||||||
private int _threshold = 5;
|
private int _threshold = 5;
|
||||||
|
private bool _nonblocking;
|
||||||
private bool isDisposed;
|
private bool isDisposed;
|
||||||
|
|
||||||
#region Structures
|
#region Structures
|
||||||
@ -54,6 +55,8 @@ namespace SpaceNavWrapper
|
|||||||
private static extern int spnav_open(ushort vendor_id, ushort product_id);
|
private static extern int spnav_open(ushort vendor_id, ushort product_id);
|
||||||
[DllImport(DLL_NAME)]
|
[DllImport(DLL_NAME)]
|
||||||
private static extern int spnav_close();
|
private static extern int spnav_close();
|
||||||
|
[DllImport(DLL_NAME)]
|
||||||
|
private static extern int spnav_set_nonblocking(bool nonblock);
|
||||||
[DllImport(DLL_NAME)]
|
[DllImport(DLL_NAME)]
|
||||||
private static extern int spnav_wait_event(ref SpNavEvent ev);
|
private static extern int spnav_wait_event(ref SpNavEvent ev);
|
||||||
[DllImport(DLL_NAME)]
|
[DllImport(DLL_NAME)]
|
||||||
@ -97,26 +100,44 @@ namespace SpaceNavWrapper
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CloseDevice()
|
||||||
|
{
|
||||||
|
// TODO : handle retcode and errors
|
||||||
|
spnav_close();
|
||||||
|
}
|
||||||
|
|
||||||
public double Sensitivity
|
#region Properties
|
||||||
{
|
public double Sensitivity
|
||||||
get => _sensitivity;
|
{
|
||||||
set
|
get => _sensitivity;
|
||||||
{
|
set
|
||||||
_sensitivity = value;
|
{
|
||||||
spnav_sensitivity(value);
|
_sensitivity = value;
|
||||||
}
|
spnav_sensitivity(value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int Threshold
|
public int Threshold
|
||||||
{
|
{
|
||||||
get => _threshold;
|
get => _threshold;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_threshold = value;
|
_threshold = value;
|
||||||
spnav_deadzone(value);
|
spnav_deadzone(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Nonblocking
|
||||||
|
{
|
||||||
|
get => _nonblocking;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_nonblocking = value;
|
||||||
|
spnav_set_nonblocking(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
@ -128,11 +149,5 @@ namespace SpaceNavWrapper
|
|||||||
}
|
}
|
||||||
isDisposed = true;
|
isDisposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CloseDevice()
|
|
||||||
{
|
|
||||||
// TODO : handle retcode and errors
|
|
||||||
spnav_close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit f37537fa836f19905f43dc5fd49e58384790d38a
|
Subproject commit f654a62bdb4dbe14991fa89c2af69034587f816a
|
Loading…
x
Reference in New Issue
Block a user