From 4a7d3ee1c8f959558fabb0a014bed7b8d3105854 Mon Sep 17 00:00:00 2001 From: Soren Jorvang Date: Sun, 16 Jan 2011 17:00:17 +0000 Subject: Deal with "hat" switches. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6863 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Src/ControllerInterface/OSX/OSXJoystick.h | 20 +++++ .../Src/ControllerInterface/OSX/OSXJoystick.mm | 98 +++++++++++++++++++--- 2 files changed, 107 insertions(+), 11 deletions(-) (limited to 'Source/Core/InputCommon') diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h index c9bb7bdfaf..c26df5e579 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.h @@ -53,6 +53,26 @@ protected: float m_scale; }; + class Hat : public Input + { + friend class Joystick; + public: + enum direction { + up = 0, + right, + down, + left + }; + std::string GetName() const; + protected: + Hat(IOHIDElementRef element, direction dir); + ControlState GetState(IOHIDDeviceRef device) const; + private: + IOHIDElementRef m_element; + std::string m_name; + direction m_direction; + }; + bool UpdateInput(); bool UpdateOutput(); diff --git a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm index b3012b6c87..223e363cce 100644 --- a/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm +++ b/Source/Core/InputCommon/Src/ControllerInterface/OSX/OSXJoystick.mm @@ -60,8 +60,15 @@ Joystick::Joystick(IOHIDDeviceRef device) (IOHIDElementRef)CFArrayGetValueAtIndex(axes, i); //DeviceElementDebugPrint(e, NULL); - AddInput(new Axis(e, Axis::negative)); - AddInput(new Axis(e, Axis::positive)); + if (IOHIDElementGetUsage(e) == kHIDUsage_GD_Hatswitch) { + AddInput(new Hat(e, Hat::up)); + AddInput(new Hat(e, Hat::right)); + AddInput(new Hat(e, Hat::down)); + AddInput(new Hat(e, Hat::left)); + } else { + AddInput(new Axis(e, Axis::negative)); + AddInput(new Axis(e, Axis::positive)); + } } CFRelease(axes); } @@ -159,15 +166,9 @@ Joystick::Axis::Axis(IOHIDElementRef element, direction dir) case kHIDUsage_GD_Wheel: description = "Wheel"; break; - case kHIDUsage_GD_Hatswitch: - description = "Hat"; - break; case kHIDUsage_Csmr_ACPan: description = "Pan"; break; - default: - WARN_LOG(PAD, "Unknown axis type 0x%x, using it anyway...", - IOHIDElementGetUsage(m_element)); } m_name = std::string("Axis ") + description; @@ -190,9 +191,9 @@ ControlState Joystick::Axis::GetState(IOHIDDeviceRef device) const return (position - m_neutral) * m_scale; if (m_direction == negative && position < m_neutral) return (m_neutral - position) * m_scale; - } - - return 0; + } + + return 0; } std::string Joystick::Axis::GetName() const @@ -200,6 +201,81 @@ std::string Joystick::Axis::GetName() const return m_name; } +Joystick::Hat::Hat(IOHIDElementRef element, direction dir) + : m_element(element) + , m_direction(dir) +{ + switch (dir) { + case up: + m_name = "Up"; + break; + case right: + m_name = "Right"; + break; + case down: + m_name = "Down"; + break; + case left: + m_name = "Left"; + break; + default: + m_name = "unk"; + } +} + +ControlState Joystick::Hat::GetState(IOHIDDeviceRef device) const +{ + IOHIDValueRef value; + int position; + + if (IOHIDDeviceGetValue(device, m_element, &value) == kIOReturnSuccess) + { + position = IOHIDValueGetIntegerValue(value); + + switch (position) { + case 0: + if (m_direction == up) + return 1; + break; + case 1: + if (m_direction == up || m_direction == right) + return 1; + break; + case 2: + if (m_direction == right) + return 1; + break; + case 3: + if (m_direction == right || m_direction == down) + return 1; + break; + case 4: + if (m_direction == down) + return 1; + break; + case 5: + if (m_direction == down || m_direction == left) + return 1; + break; + case 6: + if (m_direction == left) + return 1; + break; + case 7: + if (m_direction == left || m_direction == up) + return 1; + break; + }; + } + + return 0; +} + +std::string Joystick::Hat::GetName() const +{ + return m_name; +} + } } -- cgit v1.2.3