Commit ce6fcfcd authored by Phillip Castaneda's avatar Phillip Castaneda
Browse files

Adding Joystick patch/fixes

parent 6be8481b
...@@ -28,9 +28,18 @@ ...@@ -28,9 +28,18 @@
namespace OIS namespace OIS
{ {
struct AxisInfo
{
int min;
int max;
AxisInfo(int min, int max)
: min(min), max(max) {}
};
typedef struct cookie_struct typedef struct cookie_struct
{ {
std::vector<IOHIDElementCookie> axisCookies; std::map<IOHIDElementCookie, AxisInfo> axisCookies;
std::vector<IOHIDElementCookie> buttonCookies; std::vector<IOHIDElementCookie> buttonCookies;
} cookie_struct_t; } cookie_struct_t;
...@@ -39,7 +48,7 @@ namespace OIS ...@@ -39,7 +48,7 @@ namespace OIS
class MacJoyStick : public JoyStick class MacJoyStick : public JoyStick
{ {
public: public:
MacJoyStick(const std::string& vendor, bool buffered, HidInfo* info, InputManager* creator); MacJoyStick(const std::string& vendor, bool buffered, HidInfo* info, InputManager* creator, int devID);
virtual ~MacJoyStick(); virtual ~MacJoyStick();
......
...@@ -406,7 +406,11 @@ Object* MacHIDManager::createObject(InputManager* creator, Type iType, bool buff ...@@ -406,7 +406,11 @@ Object* MacHIDManager::createObject(InputManager* creator, Type iType, bool buff
switch(iType) switch(iType)
{ {
case OISJoyStick: case OISJoyStick:
obj = new MacJoyStick(vendor, bufferMode, *it, creator); int totalDevs = totalDevices(iType);
int freeDevs = freeDevices(iType);
int devID = totalDevs - freeDevs;
obj = new MacJoyStick((*it)->combinedKey, bufferMode, *it, creator, devID);
(*it)->inUse = true; (*it)->inUse = true;
return obj; return obj;
case OISTablet: case OISTablet:
......
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
using namespace OIS; using namespace OIS;
//--------------------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------------------//
MacJoyStick::MacJoyStick(const std::string &vendor, bool buffered, HidInfo* info, InputManager* creator) : MacJoyStick::MacJoyStick(const std::string &vendor, bool buffered, HidInfo* info, InputManager* creator, int devID) :
JoyStick(vendor, buffered, 0 /*device id*/, creator), mInfo(info) JoyStick(vendor, buffered, devID, creator), mInfo(info)
{ {
} }
...@@ -75,6 +75,18 @@ void MacJoyStick::_initialize() ...@@ -75,6 +75,18 @@ void MacJoyStick::_initialize()
mQueue = _createQueue(); mQueue = _createQueue();
} }
class FindAxisCookie : public std::unary_function<std::pair<IOHIDElementCookie, AxisInfo>&, bool>
{
public:
FindAxisCookie(IOHIDElementCookie cookie) : m_Cookie(cookie) {}
bool operator()(const std::pair<IOHIDElementCookie, AxisInfo>& pair) const
{
return pair.first == m_Cookie;
}
private:
IOHIDElementCookie m_Cookie;
};
//--------------------------------------------------------------------------------------------------// //--------------------------------------------------------------------------------------------------//
void MacJoyStick::capture() void MacJoyStick::capture()
{ {
...@@ -106,8 +118,15 @@ void MacJoyStick::capture() ...@@ -106,8 +118,15 @@ void MacJoyStick::capture()
case kIOHIDElementTypeInput_Misc: case kIOHIDElementTypeInput_Misc:
//TODO: It's an axis! - kind of - for gamepads - or should this be a pov? //TODO: It's an axis! - kind of - for gamepads - or should this be a pov?
case kIOHIDElementTypeInput_Axis: case kIOHIDElementTypeInput_Axis:
mState.mAxes[(int)event.elementCookie].abs = event.value; std::map<IOHIDElementCookie, AxisInfo>::iterator axisIt = std::find_if(mCookies.axisCookies.begin(), mCookies.axisCookies.end(), FindAxisCookie(event.elementCookie));
if(mBuffered && mListener) mListener->axisMoved(JoyStickEvent(this, mState), (int)event.elementCookie); int axis = std::distance(mCookies.axisCookies.begin(), axisIt);
//Copied from LinuxJoyStickEvents.cpp, line 149
const AxisInfo& axisInfo = axisIt->second;
float proportion = (float) (event.value - axisInfo.max) / (float) (axisInfo.min - axisInfo.max);
mState.mAxes[axis].abs = -JoyStick::MIN_AXIS - (JoyStick::MAX_AXIS * 2 * proportion);
if(mBuffered && mListener) mListener->axisMoved(JoyStickEvent(this, mState), axis);
break; break;
} }
...@@ -144,6 +163,8 @@ void MacJoyStick::_enumerateCookies() ...@@ -144,6 +163,8 @@ void MacJoyStick::_enumerateCookies()
IOHIDElementCookie cookie; IOHIDElementCookie cookie;
long usage; long usage;
long usagePage; long usagePage;
int min;
int max;
CFDictionaryRef element; CFDictionaryRef element;
...@@ -181,6 +202,25 @@ void MacJoyStick::_enumerateCookies() ...@@ -181,6 +202,25 @@ void MacJoyStick::_enumerateCookies()
continue; continue;
usage = number; usage = number;
//Get min
object = CFDictionaryGetValue(element,
CFSTR(kIOHIDElementMinKey)); // kIOHIDElementMinKey or kIOHIDElementScaledMinKey?, no idea ...
if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID())
continue;
if (!CFNumberGetValue((CFNumberRef) object, kCFNumberIntType,
&number))
continue;
min = number;
//Get max
object = CFDictionaryGetValue(element,
CFSTR(kIOHIDElementMaxKey)); // kIOHIDElementMaxKey or kIOHIDElementScaledMaxKey?, no idea ...
if (object == 0 || CFGetTypeID(object) != CFNumberGetTypeID())
continue;
if (!CFNumberGetValue((CFNumberRef) object, kCFNumberIntType,
&number))
continue;
max = number;
//Get usage page //Get usage page
object = CFDictionaryGetValue(element, object = CFDictionaryGetValue(element,
...@@ -207,7 +247,7 @@ void MacJoyStick::_enumerateCookies() ...@@ -207,7 +247,7 @@ void MacJoyStick::_enumerateCookies()
case kHIDUsage_GD_Rx: case kHIDUsage_GD_Rx:
case kHIDUsage_GD_Ry: case kHIDUsage_GD_Ry:
case kHIDUsage_GD_Rz: case kHIDUsage_GD_Rz:
mCookies.axisCookies.push_back(cookie); mCookies.axisCookies.insert(std::make_pair(cookie, AxisInfo(min, max)));
break; break;
case kHIDUsage_GD_Slider: case kHIDUsage_GD_Slider:
case kHIDUsage_GD_Dial: case kHIDUsage_GD_Dial:
...@@ -250,16 +290,16 @@ IOHIDQueueInterface** MacJoyStick::_createQueue(unsigned int depth) ...@@ -250,16 +290,16 @@ IOHIDQueueInterface** MacJoyStick::_createQueue(unsigned int depth)
if(result == kIOReturnSuccess) if(result == kIOReturnSuccess)
{ {
//add elements to the queue //add elements to the queue
std::vector<IOHIDElementCookie>::iterator it = mCookies.axisCookies.begin(); std::map<IOHIDElementCookie, AxisInfo>::iterator axisIt = mCookies.axisCookies.begin();
for(; it != mCookies.axisCookies.end(); ++it) for(; axisIt != mCookies.axisCookies.end(); ++axisIt)
{ {
result = (*queue)->addElement(queue, (*it), 0); result = (*queue)->addElement(queue, axisIt->first, 0);
} }
it = mCookies.buttonCookies.begin(); std::vector<IOHIDElementCookie>::iterator buttonIt = mCookies.buttonCookies.begin();
for(; it != mCookies.buttonCookies.end(); ++it) for(; buttonIt != mCookies.buttonCookies.end(); ++buttonIt)
{ {
result = (*queue)->addElement(queue, (*it), 0); result = (*queue)->addElement(queue, (*buttonIt), 0);
} }
//start data delivery to queue //start data delivery to queue
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment