Deal with "hat" switches.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6863 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Soren Jorvang
2011-01-16 17:00:17 +00:00
parent 7e612a613a
commit 4a7d3ee1c8
4 changed files with 112 additions and 26 deletions

View File

@ -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();

View File

@ -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;
}
}
}