Use IOHIDElementCookie which is really a void* rather than int.
This commit is contained in:
@@ -27,9 +27,9 @@ void InputHandler_MacOSX_HID::QueueCallBack( void *target, int result, void *ref
|
|||||||
HIDDevice *dev = This->m_vDevices[int( refcon )];
|
HIDDevice *dev = This->m_vDevices[int( refcon )];
|
||||||
vector<DeviceInput> vPresses;
|
vector<DeviceInput> vPresses;
|
||||||
|
|
||||||
LOG->Trace( "Got event with cookie %d, value %d", int(event.elementCookie), int(event.value) );
|
LOG->Trace( "Got event with cookie %p, value %d", event.elementCookie, int(event.value) );
|
||||||
while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess )
|
while( (result = CALL(queue, getNextEvent, &event, zeroTime, 0)) == kIOReturnSuccess )
|
||||||
dev->GetButtonPresses( vPresses, int(event.elementCookie), int(event.value), now );
|
dev->GetButtonPresses( vPresses, event.elementCookie, event.value, now );
|
||||||
FOREACH_CONST( DeviceInput, vPresses, i )
|
FOREACH_CONST( DeviceInput, vPresses, i )
|
||||||
INPUTFILTER->ButtonPressed( *i );
|
INPUTFILTER->ButtonPressed( *i );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,8 @@ void HIDDevice::AddElement( const void *value, void *context )
|
|||||||
CFDictionaryRef properties = CFDictionaryRef( value );
|
CFDictionaryRef properties = CFDictionaryRef( value );
|
||||||
HIDDevice *This = (HIDDevice *)context;
|
HIDDevice *This = (HIDDevice *)context;
|
||||||
CFTypeRef object;
|
CFTypeRef object;
|
||||||
int cookie, usage, usagePage;
|
int usage, usagePage;
|
||||||
|
long cookie;
|
||||||
|
|
||||||
// Recursively add elements
|
// Recursively add elements
|
||||||
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementKey) );
|
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementKey) );
|
||||||
@@ -248,9 +249,9 @@ void HIDDevice::AddElement( const void *value, void *context )
|
|||||||
|
|
||||||
// Get cookie
|
// Get cookie
|
||||||
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementCookieKey) );
|
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementCookieKey) );
|
||||||
if( !IntValue(object, cookie) )
|
if( !LongValue(object, cookie) )
|
||||||
return;
|
return;
|
||||||
This->AddElement( usagePage, usage, cookie, properties );
|
This->AddElement( usagePage, usage, IOHIDElementCookie(cookie), properties );
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <mach/mach_error.h>
|
#include <mach/mach_error.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <ext/hash_map>
|
||||||
|
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
#include "RageInputDevice.h"
|
#include "RageInputDevice.h"
|
||||||
@@ -35,6 +36,25 @@ inline Boolean IntValue( CFTypeRef o, int &n )
|
|||||||
return CFNumberGetValue( CFNumberRef(o), kCFNumberIntType, &n );
|
return CFNumberGetValue( CFNumberRef(o), kCFNumberIntType, &n );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline Boolean LongValue( CFTypeRef o, long &n )
|
||||||
|
{
|
||||||
|
if( !o || CFGetTypeID(o) != CFNumberGetTypeID() )
|
||||||
|
return false;
|
||||||
|
return CFNumberGetValue( CFNumberRef(o), kCFNumberLongType, &n );
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace __gnu_cxx
|
||||||
|
{
|
||||||
|
template<>
|
||||||
|
struct hash<IOHIDElementCookie> : private hash<uintptr_t>
|
||||||
|
{
|
||||||
|
size_t operator()( const IOHIDElementCookie& cookie ) const
|
||||||
|
{
|
||||||
|
return hash<unsigned long>::operator()( uintptr_t(cookie) );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is just awful, these aren't objects, treating them as such leads
|
* This is just awful, these aren't objects, treating them as such leads
|
||||||
* to: (*object)->function(object [, argument]...)
|
* to: (*object)->function(object [, argument]...)
|
||||||
@@ -65,7 +85,7 @@ protected:
|
|||||||
* If the most recently added logical device cares about the state of an element of type
|
* If the most recently added logical device cares about the state of an element of type
|
||||||
* (usagePage, usage), store the cookie.
|
* (usagePage, usage), store the cookie.
|
||||||
*/
|
*/
|
||||||
virtual void AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties ) = 0;
|
virtual void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties ) = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add any elements to the queue by calling AddElementToQueue() with the stored cookies.
|
* Add any elements to the queue by calling AddElementToQueue() with the stored cookies.
|
||||||
@@ -78,11 +98,11 @@ protected:
|
|||||||
virtual bool InitDevice( int vid, int pid ) { return true; }
|
virtual bool InitDevice( int vid, int pid ) { return true; }
|
||||||
|
|
||||||
// This adds the element with the given cookie to the queue to be notified of state changes.
|
// This adds the element with the given cookie to the queue to be notified of state changes.
|
||||||
inline void AddElementToQueue( int cookie )
|
inline void AddElementToQueue( IOHIDElementCookie cookie )
|
||||||
{
|
{
|
||||||
IOReturn ret = CALL( m_Queue, addElement, IOHIDElementCookie(cookie), 0 );
|
IOReturn ret = CALL( m_Queue, addElement, cookie, 0 );
|
||||||
if( ret != KERN_SUCCESS )
|
if( ret != KERN_SUCCESS )
|
||||||
LOG->Warn( "Failed to add HID element with cookie %d to queue: %d", cookie, ret );
|
LOG->Warn( "Failed to add HID element with cookie %p to queue: %u", cookie, ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform a synchronous set report on the HID interface.
|
// Perform a synchronous set report on the HID interface.
|
||||||
@@ -105,7 +125,7 @@ public:
|
|||||||
* The value of the element is passed to determine if this is a push or a release. The time
|
* The value of the element is passed to determine if this is a push or a release. The time
|
||||||
* is provided as an optimization.
|
* is provided as an optimization.
|
||||||
*/
|
*/
|
||||||
virtual void GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const = 0;
|
virtual void GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the number of IDs assigned starting from startID. This is not meaningful for devices like
|
* Returns the number of IDs assigned starting from startID. This is not meaningful for devices like
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ bool JoystickDevice::AddLogicalDevice( int usagePage, int usage )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoystickDevice::AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties )
|
void JoystickDevice::AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties )
|
||||||
{
|
{
|
||||||
if( usagePage >= kHIDPage_VendorDefinedStart )
|
if( usagePage >= kHIDPage_VendorDefinedStart )
|
||||||
return;
|
return;
|
||||||
@@ -137,7 +137,7 @@ void JoystickDevice::Open()
|
|||||||
ADD( x_rot ); ADD( y_rot ); ADD( z_rot );
|
ADD( x_rot ); ADD( y_rot ); ADD( z_rot );
|
||||||
ADD( hat );
|
ADD( hat );
|
||||||
#undef ADD
|
#undef ADD
|
||||||
for( hash_map<int,DeviceButton>::const_iterator j = js.mapping.begin(); j != js.mapping.end(); ++j )
|
for( hash_map<IOHIDElementCookie,DeviceButton>::const_iterator j = js.mapping.begin(); j != js.mapping.end(); ++j )
|
||||||
AddElementToQueue( j->first );
|
AddElementToQueue( j->first );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ bool JoystickDevice::InitDevice( int vid, int pid )
|
|||||||
return ret == kIOReturnSuccess;
|
return ret == kIOReturnSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JoystickDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const
|
void JoystickDevice::GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const
|
||||||
{
|
{
|
||||||
FOREACH_CONST( Joystick, m_vSticks, i )
|
FOREACH_CONST( Joystick, m_vSticks, i )
|
||||||
{
|
{
|
||||||
@@ -236,7 +236,7 @@ void JoystickDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// hash_map<T,U>::operator[] is not const
|
// hash_map<T,U>::operator[] is not const
|
||||||
hash_map<int, DeviceButton>::const_iterator iter;
|
hash_map<IOHIDElementCookie, DeviceButton>::const_iterator iter;
|
||||||
|
|
||||||
iter = js.mapping.find( cookie );
|
iter = js.mapping.find( cookie );
|
||||||
if( iter != js.mapping.end() )
|
if( iter != js.mapping.end() )
|
||||||
|
|||||||
@@ -2,20 +2,20 @@
|
|||||||
#define JOYSTICK_DEVICE_H
|
#define JOYSTICK_DEVICE_H
|
||||||
|
|
||||||
#include "HIDDevice.h"
|
#include "HIDDevice.h"
|
||||||
#include <ext/hash_map>
|
|
||||||
|
|
||||||
struct Joystick
|
struct Joystick
|
||||||
{
|
{
|
||||||
InputDevice id;
|
InputDevice id;
|
||||||
// map cookie to button
|
// map cookie to button
|
||||||
__gnu_cxx::hash_map<int, DeviceButton> mapping;
|
__gnu_cxx::hash_map<IOHIDElementCookie, DeviceButton> mapping;
|
||||||
int x_axis, x_min, x_max;
|
IOHIDElementCookie x_axis, y_axis, z_axis, x_rot, y_rot, z_rot, hat;
|
||||||
int y_axis, y_min, y_max;
|
int x_min, x_max;
|
||||||
int z_axis, z_min, z_max;
|
int y_min, y_max;
|
||||||
int x_rot, rx_min, rx_max;
|
int z_min, z_max;
|
||||||
int y_rot, ry_min, ry_max;
|
int rx_min, rx_max;
|
||||||
int z_rot, rz_min, rz_max;
|
int ry_min, ry_max;
|
||||||
int hat, hat_min, hat_max;
|
int rz_min, rz_max;
|
||||||
|
int hat_min, hat_max;
|
||||||
|
|
||||||
Joystick();
|
Joystick();
|
||||||
};
|
};
|
||||||
@@ -27,12 +27,12 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool AddLogicalDevice( int usagePage, int usage );
|
bool AddLogicalDevice( int usagePage, int usage );
|
||||||
void AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties );
|
void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties );
|
||||||
void Open();
|
void Open();
|
||||||
bool InitDevice( int vid, int pid );
|
bool InitDevice( int vid, int pid );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const;
|
void GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const;
|
||||||
int AssignIDs( InputDevice startID );
|
int AssignIDs( InputDevice startID );
|
||||||
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ static bool UsbKeyToDeviceButton( UInt8 iUsbKey, DeviceButton &buttonOut )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardDevice::AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties )
|
void KeyboardDevice::AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties )
|
||||||
{
|
{
|
||||||
if( usagePage != kHIDPage_KeyboardOrKeypad )
|
if( usagePage != kHIDPage_KeyboardOrKeypad )
|
||||||
return;
|
return;
|
||||||
@@ -162,13 +162,13 @@ void KeyboardDevice::AddElement( int usagePage, int usage, int cookie, const CFD
|
|||||||
|
|
||||||
void KeyboardDevice::Open()
|
void KeyboardDevice::Open()
|
||||||
{
|
{
|
||||||
for( hash_map<int,DeviceButton>::const_iterator i = m_Mapping.begin(); i != m_Mapping.end(); ++i )
|
for( hash_map<IOHIDElementCookie,DeviceButton>::const_iterator i = m_Mapping.begin(); i != m_Mapping.end(); ++i )
|
||||||
AddElementToQueue( i->first );
|
AddElementToQueue( i->first );
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const
|
void KeyboardDevice::GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const
|
||||||
{
|
{
|
||||||
hash_map<int, DeviceButton>::const_iterator iter = m_Mapping.find( cookie );
|
hash_map<IOHIDElementCookie, DeviceButton>::const_iterator iter = m_Mapping.find( cookie );
|
||||||
|
|
||||||
if( iter != m_Mapping.end() )
|
if( iter != m_Mapping.end() )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,20 +2,19 @@
|
|||||||
#define KEYBOARD_DEVICE_H
|
#define KEYBOARD_DEVICE_H
|
||||||
|
|
||||||
#include "HIDDevice.h"
|
#include "HIDDevice.h"
|
||||||
#include <ext/hash_map>
|
|
||||||
|
|
||||||
class KeyboardDevice : public HIDDevice
|
class KeyboardDevice : public HIDDevice
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
__gnu_cxx::hash_map<int, DeviceButton> m_Mapping;
|
__gnu_cxx::hash_map<IOHIDElementCookie, DeviceButton> m_Mapping;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool AddLogicalDevice( int usagePage, int usage );
|
bool AddLogicalDevice( int usagePage, int usage );
|
||||||
void AddElement( int usagePage, int usage, int cookie, const CFDictionaryRef properties );
|
void AddElement( int usagePage, int usage, IOHIDElementCookie cookie, const CFDictionaryRef properties );
|
||||||
void Open();
|
void Open();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const;
|
void GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const;
|
||||||
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
||||||
|
|
||||||
static bool DeviceButtonToMacVirtualKey( DeviceButton button, UInt8 &iMacVKOut );
|
static bool DeviceButtonToMacVirtualKey( DeviceButton button, UInt8 &iMacVKOut );
|
||||||
|
|||||||
@@ -3,22 +3,22 @@
|
|||||||
|
|
||||||
void PumpDevice::Open()
|
void PumpDevice::Open()
|
||||||
{
|
{
|
||||||
AddElementToQueue( 2 );
|
AddElementToQueue( IOHIDElementCookie(2) );
|
||||||
AddElementToQueue( 3 );
|
AddElementToQueue( IOHIDElementCookie(3) );
|
||||||
AddElementToQueue( 4 );
|
AddElementToQueue( IOHIDElementCookie(4) );
|
||||||
AddElementToQueue( 6 );
|
AddElementToQueue( IOHIDElementCookie(6) );
|
||||||
AddElementToQueue( 7 );
|
AddElementToQueue( IOHIDElementCookie(7) );
|
||||||
AddElementToQueue( 8 );
|
AddElementToQueue( IOHIDElementCookie(8) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void PumpDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const
|
void PumpDevice::GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const
|
||||||
{
|
{
|
||||||
DeviceButton db1 = DeviceButton_Invalid;
|
DeviceButton db1 = DeviceButton_Invalid;
|
||||||
DeviceButton db2 = DeviceButton_Invalid;
|
DeviceButton db2 = DeviceButton_Invalid;
|
||||||
bool pressed1 = !(value & 0x1);
|
bool pressed1 = !(value & 0x1);
|
||||||
bool pressed2 = !(value & 0x2);
|
bool pressed2 = !(value & 0x2);
|
||||||
|
|
||||||
switch( cookie )
|
switch( uintptr_t(cookie) )
|
||||||
{
|
{
|
||||||
case 2:
|
case 2:
|
||||||
db2 = JOY_BUTTON_1; // bit 9
|
db2 = JOY_BUTTON_1; // bit 9
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool AddLogicalDevice( int usagePage, int usage ) { return true; }
|
bool AddLogicalDevice( int usagePage, int usage ) { return true; }
|
||||||
void AddElement( int usagePage, int usage, int cookie,
|
void AddElement( int usagePage, int usage, IOHIDElementCookie cookie,
|
||||||
const CFDictionaryRef properties ) { }
|
const CFDictionaryRef properties ) { }
|
||||||
void Open();
|
void Open();
|
||||||
bool InitDevice( int vid, int pid ) { return vid == 0x0d2f && pid == 0x0001; }
|
bool InitDevice( int vid, int pid ) { return vid == 0x0d2f && pid == 0x0001; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void GetButtonPresses( vector<DeviceInput>& vPresses, int cookie, int value, const RageTimer& now ) const;
|
void GetButtonPresses( vector<DeviceInput>& vPresses, IOHIDElementCookie cookie, int value, const RageTimer& now ) const;
|
||||||
int AssignIDs( InputDevice startID );
|
int AssignIDs( InputDevice startID );
|
||||||
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user