Some improvements for wiimote-support (Darkice).

This commit is contained in:
Florian Küpper committed 2013-08-25 14:57:00 +02:00
1 parent da34aee4a1
commit 8e524b6f48
3 files changed
+37 -33

No files matched your search

+13 -15
View File
@@ -23,20 +23,20 @@ using Vocaluxe.Base;
namespace Vocaluxe.Lib.Input namespace Vocaluxe.Lib.Input
{ {
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SHIDDeviceInfo public struct SHIDDeviceInfo
{ {
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
[MarshalAs(UnmanagedType.LPTStr)] public readonly String Path; [MarshalAs(UnmanagedType.LPTStr)] public readonly String Path;
public readonly ushort VendorString; [MarshalAs(UnmanagedType.LPWStr)] public readonly ushort VendorString;
public readonly ushort ProductID; [MarshalAs(UnmanagedType.LPWStr)] public readonly ushort ProductID;
public readonly String SerialNumber; [MarshalAs(UnmanagedType.LPWStr)] public readonly String SerialNumber;
public readonly ushort ReleaseNumber; [MarshalAs(UnmanagedType.LPWStr)] public readonly ushort ReleaseNumber;
public readonly String ManufacturerString; [MarshalAs(UnmanagedType.LPWStr)] public readonly String ManufacturerString;
public readonly String ProductString; [MarshalAs(UnmanagedType.LPWStr)] public readonly String ProductString;
public readonly ushort UsagePage; [MarshalAs(UnmanagedType.LPWStr)] public readonly ushort UsagePage;
public readonly ushort Usage; [MarshalAs(UnmanagedType.LPWStr)] public readonly ushort Usage;
public readonly int InterfaceNumber; [MarshalAs(UnmanagedType.LPWStr)] public readonly int InterfaceNumber;
internal IntPtr Next; internal IntPtr Next;
// ReSharper restore MemberCanBePrivate.Global // ReSharper restore MemberCanBePrivate.Global
} }
@@ -62,12 +62,14 @@ namespace Vocaluxe.Lib.Input
private const string _HIDApiDll = "libhidapi.so"; private const string _HIDApiDll = "libhidapi.so";
#endif #endif
#endif #endif
private static IntPtr dataPtr;
[DllImport(_HIDApiDll, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, EntryPoint = "hid_init", CharSet = CharSet.Unicode)] [DllImport(_HIDApiDll, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, EntryPoint = "hid_init", CharSet = CharSet.Unicode)]
private static extern int hid_init(); private static extern int hid_init();
public static bool Init() public static bool Init()
{ {
dataPtr = Marshal.AllocCoTaskMem(22);
int result; int result;
try try
{ {
@@ -160,11 +162,8 @@ namespace Vocaluxe.Lib.Input
[DllImport(_HIDApiDll, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, EntryPoint = "hid_read_timeout", CharSet = CharSet.Unicode)] [DllImport(_HIDApiDll, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl, EntryPoint = "hid_read_timeout", CharSet = CharSet.Unicode)]
private static extern int hid_read_timeout(IntPtr device, IntPtr data, int length, int milliseconds); private static extern int hid_read_timeout(IntPtr device, IntPtr data, int length, int milliseconds);
public static int ReadTimeout(IntPtr device, out byte[] data, int length, int milliseconds) public static int ReadTimeout(IntPtr device, ref byte[] data, int length, int milliseconds)
{ {
data = new byte[length];
IntPtr dataPtr = Marshal.AllocHGlobal(length);
int result; int result;
try try
{ {
@@ -181,7 +180,6 @@ namespace Vocaluxe.Lib.Input
else else
data = null; data = null;
Marshal.FreeHGlobal(dataPtr);
return result; return result;
} }
+1
View File
@@ -71,6 +71,7 @@ namespace Vocaluxe.Lib.Input.WiiMote
public void Close() public void Close()
{ {
_Active = false; _Active = false;
_WiiMote.Disconnect();
} }
public void Connect() public void Connect()
+23 -18
View File
@@ -198,6 +198,16 @@ namespace Vocaluxe.Lib.Input.WiiMote
_Error = false; _Error = false;
_Reader = new Thread(_ReaderLoop); _Reader = new Thread(_ReaderLoop);
_Reader.Start(); _Reader.Start();
if (!CHIDApi.Init())
{
CLog.LogError("WiiMoteLib: Can't initialize HID API");
const string msg = "Please install the Visual C++ Redistributable Packages 2008!";
CLog.LogError(msg);
_Active = false;
_Error = true;
}
} }
~CWiiMoteLib() ~CWiiMoteLib()
@@ -224,35 +234,30 @@ namespace Vocaluxe.Lib.Input.WiiMote
if (_Error) if (_Error)
return false; return false;
CHIDApi.Exit();
if (!CHIDApi.Init())
{
CLog.LogError("WiiMoteLib: Can't initialize HID API");
const string msg = "Please install the Visual C++ Redistributable Packages 2008!";
CLog.LogError(msg);
_Active = false;
_Error = true;
return false;
}
//Try WiiMotion //Try WiiMotion
if (Connected = CHIDApi.Open(_VID, _PID, out _Handle)) Connected = CHIDApi.Open(_VID, _PID, out _Handle);
if (Connected)
{ {
if (!(Connected = _ReadCalibration())) Connected = _ReadCalibration();
if (!Connected)
CHIDApi.Close(_Handle); CHIDApi.Close(_Handle);
} }
else
CHIDApi.Close(_Handle);
if (Connected) if (Connected)
return true; return true;
//Try WiiMotion Plus //Try WiiMotion Plus
if (Connected = CHIDApi.Open(_VID, _PIDPlus, out _Handle)) Connected = CHIDApi.Open(_VID, _PIDPlus, out _Handle);
if (Connected)
{ {
if (!(Connected = _ReadCalibration())) Connected = _ReadCalibration();
if (!Connected)
CHIDApi.Close(_Handle); CHIDApi.Close(_Handle);
} }
else
CHIDApi.Close(_Handle);
return Connected; return Connected;
@@ -335,7 +340,7 @@ namespace Vocaluxe.Lib.Input.WiiMote
try try
{ {
CHIDApi.ReadTimeout(_Handle, out buff, _ReportLength, 100); CHIDApi.ReadTimeout(_Handle, ref buff, _ReportLength, 200);
} }
catch (Exception e) catch (Exception e)
{ {