Add support for asynchronous event via Nonblocking

This commit is contained in:
Thibaud Gasser 2018-05-31 00:38:44 +02:00
parent 0c8028c0a8
commit 6b16cee62b
3 changed files with 45 additions and 31 deletions

View File

@ -16,7 +16,10 @@ namespace SpaceNavWrapper
//}
SpaceNav navDriver = new SpaceNav();
navDriver.InitDevice();
navDriver.Button += OnButton;
navDriver.Button += delegate (object sender, ButtonEventArgs e)
{
navDriver.Nonblocking = !navDriver.Nonblocking;
};
navDriver.Motion += OnMotion;
Console.CancelKeyPress += delegate {
@ -25,6 +28,7 @@ namespace SpaceNavWrapper
for (; ; )
{
navDriver.WaitEvent();
Console.WriteLine("AA");
}
}
@ -32,10 +36,5 @@ namespace SpaceNavWrapper
{
Console.WriteLine(e);
}
private static void OnButton(object sender, EventArgs e)
{
Console.WriteLine(e);
}
}
}

View File

@ -20,6 +20,7 @@ namespace SpaceNavWrapper
private double _sensitivity = 1.0;
private int _threshold = 5;
private bool _nonblocking;
private bool isDisposed;
#region Structures
@ -54,6 +55,8 @@ namespace SpaceNavWrapper
private static extern int spnav_open(ushort vendor_id, ushort product_id);
[DllImport(DLL_NAME)]
private static extern int spnav_close();
[DllImport(DLL_NAME)]
private static extern int spnav_set_nonblocking(bool nonblock);
[DllImport(DLL_NAME)]
private static extern int spnav_wait_event(ref SpNavEvent ev);
[DllImport(DLL_NAME)]
@ -97,26 +100,44 @@ namespace SpaceNavWrapper
break;
}
}
private void CloseDevice()
{
// TODO : handle retcode and errors
spnav_close();
}
public double Sensitivity
{
get => _sensitivity;
set
{
_sensitivity = value;
spnav_sensitivity(value);
}
}
#region Properties
public double Sensitivity
{
get => _sensitivity;
set
{
_sensitivity = value;
spnav_sensitivity(value);
}
}
public int Threshold
{
get => _threshold;
set
{
_threshold = value;
spnav_deadzone(value);
}
}
public int Threshold
{
get => _threshold;
set
{
_threshold = value;
spnav_deadzone(value);
}
}
public bool Nonblocking
{
get => _nonblocking;
set
{
_nonblocking = value;
spnav_set_nonblocking(value);
}
}
#endregion
public void Dispose()
{
@ -128,11 +149,5 @@ namespace SpaceNavWrapper
}
isDisposed = true;
}
private void CloseDevice()
{
// TODO : handle retcode and errors
spnav_close();
}
}
}

@ -1 +1 @@
Subproject commit f37537fa836f19905f43dc5fd49e58384790d38a
Subproject commit f654a62bdb4dbe14991fa89c2af69034587f816a