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

@ -60,11 +60,14 @@ else:
if sys.platform == 'win32':
files += [ "stdafx.cpp" ]
elif sys.platform == 'darwin':
if env['HAVE_WX']:
wxlibs += env['wxconfiglibs']
ldflags += [ '-Wl,-pagezero_size,0x1000' ]
exe = '#' + env['prefix'] + '/Dolphin.app/Contents/MacOS/Dolphin'
if env['HAVE_WX']:
wxlibs += env['wxconfiglibs']
else:
exe += 'NoGUI'
env.Install('#' + env['prefix'] + '/Dolphin.app/Contents/' +
'Library/Frameworks/Cg.framework', source = [
'#Externals/Cg/Cg.framework/Cg',

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

View File

@ -72,7 +72,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Dolphin", "Core\DolphinWX\D
{823DDC98-42D5-4A38-88CF-9DC06C788AE4} = {823DDC98-42D5-4A38-88CF-9DC06C788AE4}
{3D8156A9-64D1-4C8E-ADBE-1B319030E4A4} = {3D8156A9-64D1-4C8E-ADBE-1B319030E4A4}
{0E231FB1-F3C9-4724-ACCB-DE8BCB3C089E} = {0E231FB1-F3C9-4724-ACCB-DE8BCB3C089E}
{374E2DB7-42DF-4E59-8474-62B6687F4978} = {374E2DB7-42DF-4E59-8474-62B6687F4978}
{E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA} = {E5D1F0C0-AA07-4841-A4EB-4CF4DAA6B0FA}
{29C2ABC1-ADA5-42CD-A5FC-96022D52A510} = {29C2ABC1-ADA5-42CD-A5FC-96022D52A510}
{4D3CD4C5-412B-4B49-9B1B-A68A2A129C77} = {4D3CD4C5-412B-4B49-9B1B-A68A2A129C77}
@ -585,18 +584,6 @@ Global
{66A4E7BD-E2E8-4373-9B75-8750EB5AE683}.Release|Win32.Build.0 = Release|Win32
{66A4E7BD-E2E8-4373-9B75-8750EB5AE683}.Release|x64.ActiveCfg = Release|x64
{66A4E7BD-E2E8-4373-9B75-8750EB5AE683}.Release|x64.Build.0 = Release|x64
{374E2DB7-42DF-4E59-8474-62B6687F4978}.Debug|Win32.ActiveCfg = Debug|Win32
{374E2DB7-42DF-4E59-8474-62B6687F4978}.Debug|Win32.Build.0 = Debug|Win32
{374E2DB7-42DF-4E59-8474-62B6687F4978}.Debug|x64.ActiveCfg = Debug|x64
{374E2DB7-42DF-4E59-8474-62B6687F4978}.Debug|x64.Build.0 = Debug|x64
{374E2DB7-42DF-4E59-8474-62B6687F4978}.DebugFast|Win32.ActiveCfg = DebugFast|Win32
{374E2DB7-42DF-4E59-8474-62B6687F4978}.DebugFast|Win32.Build.0 = DebugFast|Win32
{374E2DB7-42DF-4E59-8474-62B6687F4978}.DebugFast|x64.ActiveCfg = DebugFast|x64
{374E2DB7-42DF-4E59-8474-62B6687F4978}.DebugFast|x64.Build.0 = DebugFast|x64
{374E2DB7-42DF-4E59-8474-62B6687F4978}.Release|Win32.ActiveCfg = Release|Win32
{374E2DB7-42DF-4E59-8474-62B6687F4978}.Release|Win32.Build.0 = Release|Win32
{374E2DB7-42DF-4E59-8474-62B6687F4978}.Release|x64.ActiveCfg = Release|x64
{374E2DB7-42DF-4E59-8474-62B6687F4978}.Release|x64.Build.0 = Release|x64
{21DBE606-2958-43AC-A14E-B6B798D56554}.Debug|Win32.ActiveCfg = Debug|Win32
{21DBE606-2958-43AC-A14E-B6B798D56554}.Debug|Win32.Build.0 = Debug|Win32
{21DBE606-2958-43AC-A14E-B6B798D56554}.Debug|x64.ActiveCfg = Debug|x64