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 )];
|
||||
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 )
|
||||
dev->GetButtonPresses( vPresses, int(event.elementCookie), int(event.value), now );
|
||||
dev->GetButtonPresses( vPresses, event.elementCookie, event.value, now );
|
||||
FOREACH_CONST( DeviceInput, vPresses, i )
|
||||
INPUTFILTER->ButtonPressed( *i );
|
||||
}
|
||||
|
||||
@@ -223,7 +223,8 @@ void HIDDevice::AddElement( const void *value, void *context )
|
||||
CFDictionaryRef properties = CFDictionaryRef( value );
|
||||
HIDDevice *This = (HIDDevice *)context;
|
||||
CFTypeRef object;
|
||||
int cookie, usage, usagePage;
|
||||
int usage, usagePage;
|
||||
long cookie;
|
||||
|
||||
// Recursively add elements
|
||||
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementKey) );
|
||||
@@ -248,9 +249,9 @@ void HIDDevice::AddElement( const void *value, void *context )
|
||||
|
||||
// Get cookie
|
||||
object = CFDictionaryGetValue( properties, CFSTR(kIOHIDElementCookieKey) );
|
||||
if( !IntValue(object, cookie) )
|
||||
if( !LongValue(object, cookie) )
|
||||
return;
|
||||
This->AddElement( usagePage, usage, cookie, properties );
|
||||
This->AddElement( usagePage, usage, IOHIDElementCookie(cookie), properties );
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <mach/mach_error.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <ext/hash_map>
|
||||
|
||||
#include "RageLog.h"
|
||||
#include "RageInputDevice.h"
|
||||
@@ -35,6 +36,25 @@ inline Boolean IntValue( CFTypeRef o, int &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
|
||||
* 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
|
||||
* (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.
|
||||
@@ -78,11 +98,11 @@ protected:
|
||||
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.
|
||||
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 )
|
||||
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.
|
||||
@@ -105,7 +125,7 @@ public:
|
||||
* The value of the element is passed to determine if this is a push or a release. The time
|
||||
* 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
|
||||
|
||||
@@ -33,7 +33,7 @@ bool JoystickDevice::AddLogicalDevice( int usagePage, int usage )
|
||||
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 )
|
||||
return;
|
||||
@@ -137,7 +137,7 @@ void JoystickDevice::Open()
|
||||
ADD( x_rot ); ADD( y_rot ); ADD( z_rot );
|
||||
ADD( hat );
|
||||
#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 );
|
||||
}
|
||||
}
|
||||
@@ -155,7 +155,7 @@ bool JoystickDevice::InitDevice( int vid, int pid )
|
||||
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 )
|
||||
{
|
||||
@@ -236,7 +236,7 @@ void JoystickDevice::GetButtonPresses( vector<DeviceInput>& vPresses, int cookie
|
||||
else
|
||||
{
|
||||
// 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 );
|
||||
if( iter != js.mapping.end() )
|
||||
|
||||
@@ -2,20 +2,20 @@
|
||||
#define JOYSTICK_DEVICE_H
|
||||
|
||||
#include "HIDDevice.h"
|
||||
#include <ext/hash_map>
|
||||
|
||||
struct Joystick
|
||||
{
|
||||
InputDevice id;
|
||||
// map cookie to button
|
||||
__gnu_cxx::hash_map<int, DeviceButton> mapping;
|
||||
int x_axis, x_min, x_max;
|
||||
int y_axis, y_min, y_max;
|
||||
int z_axis, z_min, z_max;
|
||||
int x_rot, rx_min, rx_max;
|
||||
int y_rot, ry_min, ry_max;
|
||||
int z_rot, rz_min, rz_max;
|
||||
int hat, hat_min, hat_max;
|
||||
__gnu_cxx::hash_map<IOHIDElementCookie, DeviceButton> mapping;
|
||||
IOHIDElementCookie x_axis, y_axis, z_axis, x_rot, y_rot, z_rot, hat;
|
||||
int x_min, x_max;
|
||||
int y_min, y_max;
|
||||
int z_min, z_max;
|
||||
int rx_min, rx_max;
|
||||
int ry_min, ry_max;
|
||||
int rz_min, rz_max;
|
||||
int hat_min, hat_max;
|
||||
|
||||
Joystick();
|
||||
};
|
||||
@@ -27,12 +27,12 @@ private:
|
||||
|
||||
protected:
|
||||
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();
|
||||
bool InitDevice( int vid, int pid );
|
||||
|
||||
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 );
|
||||
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
||||
};
|
||||
|
||||
@@ -150,7 +150,7 @@ static bool UsbKeyToDeviceButton( UInt8 iUsbKey, DeviceButton &buttonOut )
|
||||
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 )
|
||||
return;
|
||||
@@ -162,13 +162,13 @@ void KeyboardDevice::AddElement( int usagePage, int usage, int cookie, const CFD
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
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() )
|
||||
{
|
||||
|
||||
@@ -2,20 +2,19 @@
|
||||
#define KEYBOARD_DEVICE_H
|
||||
|
||||
#include "HIDDevice.h"
|
||||
#include <ext/hash_map>
|
||||
|
||||
class KeyboardDevice : public HIDDevice
|
||||
{
|
||||
private:
|
||||
__gnu_cxx::hash_map<int, DeviceButton> m_Mapping;
|
||||
__gnu_cxx::hash_map<IOHIDElementCookie, DeviceButton> m_Mapping;
|
||||
|
||||
protected:
|
||||
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();
|
||||
|
||||
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;
|
||||
|
||||
static bool DeviceButtonToMacVirtualKey( DeviceButton button, UInt8 &iMacVKOut );
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
|
||||
void PumpDevice::Open()
|
||||
{
|
||||
AddElementToQueue( 2 );
|
||||
AddElementToQueue( 3 );
|
||||
AddElementToQueue( 4 );
|
||||
AddElementToQueue( 6 );
|
||||
AddElementToQueue( 7 );
|
||||
AddElementToQueue( 8 );
|
||||
AddElementToQueue( IOHIDElementCookie(2) );
|
||||
AddElementToQueue( IOHIDElementCookie(3) );
|
||||
AddElementToQueue( IOHIDElementCookie(4) );
|
||||
AddElementToQueue( IOHIDElementCookie(6) );
|
||||
AddElementToQueue( IOHIDElementCookie(7) );
|
||||
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 db2 = DeviceButton_Invalid;
|
||||
bool pressed1 = !(value & 0x1);
|
||||
bool pressed2 = !(value & 0x2);
|
||||
|
||||
switch( cookie )
|
||||
switch( uintptr_t(cookie) )
|
||||
{
|
||||
case 2:
|
||||
db2 = JOY_BUTTON_1; // bit 9
|
||||
|
||||
@@ -10,13 +10,13 @@ private:
|
||||
|
||||
protected:
|
||||
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 ) { }
|
||||
void Open();
|
||||
bool InitDevice( int vid, int pid ) { return vid == 0x0d2f && pid == 0x0001; }
|
||||
|
||||
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 );
|
||||
void GetDevicesAndDescriptions( vector<InputDeviceInfo>& vDevices ) const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user