#ifdef __DARWIN__
#include "wx/mac/corefoundation/hid.h"
-#include "wx/string.h"
-#include "wx/log.h"
-#include "wx/mac/corefoundation/cfstring.h"
-#include "wx/utils.h"
-#include "wx/module.h"
-#include "wx/dynarray.h"
+#ifndef WX_PRECOMP
+ #include "wx/dynarray.h"
+ #include "wx/string.h"
+ #include "wx/log.h"
+ #include "wx/utils.h"
+ #include "wx/module.h"
+#endif
+
+#include "wx/mac/corefoundation/cfstring.h"
// ============================================================================
// implementation
// ----------------------------------------------------------------------------
// wxHIDDevice::Create
//
-// nClass is the HID Page such as
+// nClass is the HID Page such as
// kHIDPage_GenericDesktop
// nType is the HID Usage such as
// kHIDUsage_GD_Joystick,kHIDUsage_GD_Mouse,kHIDUsage_GD_Keyboard
// nDev is the device number to use
-//
+//
// ----------------------------------------------------------------------------
bool wxHIDDevice::Create (int nClass, int nType, int nDev)
{
//Now get the maching services
io_iterator_t pIterator;
- if( IOServiceGetMatchingServices(m_pPort,
+ if( IOServiceGetMatchingServices(m_pPort,
pDictionary, &pIterator) != kIOReturnSuccess )
{
wxLogSysError(_T("No Matching HID Services"));
return false;
}
-
+
//Were there any devices matched?
if(pIterator == 0)
return false; // No devices found
//
//Get [product] name
- CFStringRef cfsProduct = (CFStringRef)
+ CFStringRef cfsProduct = (CFStringRef)
CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductKey));
- m_szProductName =
- wxMacCFStringHolder( cfsProduct,
- false
+ m_szProductName =
+ wxMacCFStringHolder( cfsProduct,
+ false
).AsString();
//Get the Product ID Key
- CFNumberRef cfnProductId = (CFNumberRef)
+ CFNumberRef cfnProductId = (CFNumberRef)
CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDProductIDKey));
if (cfnProductId)
{
}
//Get the Vendor ID Key
- CFNumberRef cfnVendorId = (CFNumberRef)
+ CFNumberRef cfnVendorId = (CFNumberRef)
CFDictionaryGetValue(pDictionary, CFSTR(kIOHIDVendorIDKey));
if (cfnVendorId)
{
//Create the interface (good grief - long function names!)
SInt32 nScore;
IOCFPlugInInterface** ppPlugin;
- if(IOCreatePlugInInterfaceForService(pObject,
+ if(IOCreatePlugInInterfaceForService(pObject,
kIOHIDDeviceUserClientTypeID,
- kIOCFPlugInInterfaceID, &ppPlugin,
+ kIOCFPlugInInterfaceID, &ppPlugin,
&nScore) != kIOReturnSuccess)
{
wxLogSysError(wxT("Could not create HID Interface for product"));
//Get the HID interface from the plugin to the mach port
if((*ppPlugin)->QueryInterface(ppPlugin,
- CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
+ CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID),
(void**) &m_ppDevice) != S_OK)
{
wxLogSysError(wxT("Could not get device interface from HID interface"));
wxLogDebug(_T("HID device: open failed"));
//
- //Now the hard part - in order to scan things we need "cookies"
+ //Now the hard part - in order to scan things we need "cookies"
//
- CFArrayRef cfaCookies = (CFArrayRef)CFDictionaryGetValue(pDictionary,
+ CFArrayRef cfaCookies = (CFArrayRef)CFDictionaryGetValue(pDictionary,
CFSTR(kIOHIDElementKey));
BuildCookies(cfaCookies);
-
+
//cleanup
CFRelease(pDictionary);
IOObjectRelease(pObject);
return true;
}
-
+
//iterator cleanup
IOObjectRelease(pIterator);
wxLogSysError(wxT("Could not create mach port"));
return false;
}
-
+
//Dictionary that will hold first
//the matching dictionary for determining which kind of devices we want,
//then later some registry properties from an iterator (see below)
//Now get the maching services
io_iterator_t pIterator;
- if( IOServiceGetMatchingServices(pPort,
+ if( IOServiceGetMatchingServices(pPort,
pDictionary, &pIterator) != kIOReturnSuccess )
{
wxLogSysError(_T("No Matching HID Services"));
return false;
}
-
- //If the iterator doesn't exist there are no devices :)
+
+ //If the iterator doesn't exist there are no devices :)
if ( !pIterator )
return 0;
++nCount;
IOObjectRelease(pObject);
}
-
+
//cleanup
IOObjectRelease(pIterator);
mach_port_deallocate(mach_task_self(), pPort);
-
+
return nCount;
}//end Create()
wxLogDebug(_T("HID device: create failed"));
}
}
-
+
//make sure that cookie array is clear
memset(m_pCookies, 0, sizeof(*m_pCookies) * dwSize);
}
//check here
return false;
}
-
+
IOHIDEventStruct Event;
(*m_ppDevice)->getElementValue(m_ppDevice, m_pCookies[nIndex], &Event);
return !!Event.value;
// ----------------------------------------------------------------------------
int wxHIDKeyboard::GetCount()
{
- return wxHIDDevice::GetCount(kHIDPage_GenericDesktop,
+ return wxHIDDevice::GetCount(kHIDPage_GenericDesktop,
kHIDUsage_GD_Keyboard);
}
// ----------------------------------------------------------------------------
bool wxHIDKeyboard::Create(int nDev /* = 1*/)
{
- return wxHIDDevice::Create(kHIDPage_GenericDesktop,
+ return wxHIDDevice::Create(kHIDPage_GenericDesktop,
kHIDUsage_GD_Keyboard,
nDev);
}
// ----------------------------------------------------------------------------
// wxHIDKeyboard::AddCookie
//
-// Overloaded version of wxHIDDevice::AddCookie that simply does not
+// Overloaded version of wxHIDDevice::AddCookie that simply does not
// add a cookie if a duplicate is found
// ----------------------------------------------------------------------------
void wxHIDKeyboard::AddCookie(CFTypeRef Data, int i)
// ----------------------------------------------------------------------------
void wxHIDKeyboard::BuildCookies(CFArrayRef Array)
{
- //Create internal cookie array
+ //Create internal cookie array
InitCookies(500);
-
+
//Begin recursing in array
DoBuildCookies(Array);
}
for (i = 0; i < CFArrayGetCount(Array); ++i)
{
const void* ref = CFDictionaryGetValue(
- (CFDictionaryRef)CFArrayGetValueAtIndex(Array, i),
+ (CFDictionaryRef)CFArrayGetValueAtIndex(Array, i),
CFSTR(kIOHIDElementKey)
);
// Get the usage #
//
CFNumberGetValue(
- (CFNumberRef)
- CFDictionaryGetValue((CFDictionaryRef)
- CFArrayGetValueAtIndex(Array, i),
+ (CFNumberRef)
+ CFDictionaryGetValue((CFDictionaryRef)
+ CFArrayGetValueAtIndex(Array, i),
CFSTR(kIOHIDElementUsageKey)
),
- kCFNumberLongType,
+ kCFNumberLongType,
&nUsage);
//
// Now translate the usage # into a wx keycode
- //
+ //
//
// OK, this is strange - basically this kind of strange -
// bEOTriggered = true;
//}
//Instead of that though we now just don't add duplicate keys
-
+
if (nUsage >= kHIDUsage_KeyboardA && nUsage <= kHIDUsage_KeyboardZ)
AddCookie(CFArrayGetValueAtIndex(Array, i), 'A' + (nUsage - kHIDUsage_KeyboardA) );
else if (nUsage >= kHIDUsage_Keyboard1 && nUsage <= kHIDUsage_Keyboard9)
if (wxHIDModule::sm_keyboards.GetCount() == 0)
{
int nKeyboards = wxHIDKeyboard::GetCount();
-
+
for(int i = 1; i <= nKeyboards; ++i)
{
wxHIDKeyboard* keyboard = new wxHIDKeyboard();
{
wxHIDKeyboard* keyboard = (wxHIDKeyboard*)
wxHIDModule::sm_keyboards[i];
-
+
switch(key)
{
case WXK_SHIFT:
break;
}
}
-
+
return false; //not down/error
}