mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
Clean up "ControllerInterface" a bit.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7339 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -9,53 +9,40 @@ namespace OSX
|
||||
|
||||
class Joystick : public ControllerInterface::Device
|
||||
{
|
||||
friend class ControllerInterface;
|
||||
friend class ControllerInterface::ControlReference;
|
||||
|
||||
protected:
|
||||
class Input : public ControllerInterface::Device::Input
|
||||
{
|
||||
friend class Joystick;
|
||||
protected:
|
||||
virtual ControlState GetState(IOHIDDeviceRef device) const = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
class Button : public Input
|
||||
{
|
||||
friend class Joystick;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Button(IOHIDElementRef element);
|
||||
ControlState GetState(IOHIDDeviceRef device) const;
|
||||
Button(IOHIDElementRef element, IOHIDDeviceRef device)
|
||||
: m_element(element), m_device(device) {}
|
||||
ControlState GetState() const;
|
||||
private:
|
||||
IOHIDElementRef m_element;
|
||||
std::string m_name;
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
};
|
||||
|
||||
class Axis : public Input
|
||||
{
|
||||
friend class Joystick;
|
||||
public:
|
||||
enum direction {
|
||||
positive = 0,
|
||||
negative
|
||||
};
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Axis(IOHIDElementRef element, direction dir);
|
||||
ControlState GetState(IOHIDDeviceRef device) const;
|
||||
Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir);
|
||||
ControlState GetState() const;
|
||||
private:
|
||||
IOHIDElementRef m_element;
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
std::string m_name;
|
||||
direction m_direction;
|
||||
const direction m_direction;
|
||||
float m_neutral;
|
||||
float m_scale;
|
||||
};
|
||||
|
||||
class Hat : public Input
|
||||
{
|
||||
friend class Joystick;
|
||||
public:
|
||||
enum direction {
|
||||
up = 0,
|
||||
@ -64,25 +51,19 @@ protected:
|
||||
left
|
||||
};
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Hat(IOHIDElementRef element, direction dir);
|
||||
ControlState GetState(IOHIDDeviceRef device) const;
|
||||
Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir);
|
||||
ControlState GetState() const;
|
||||
private:
|
||||
IOHIDElementRef m_element;
|
||||
std::string m_name;
|
||||
direction m_direction;
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
const char* m_name;
|
||||
const direction m_direction;
|
||||
};
|
||||
|
||||
public:
|
||||
bool UpdateInput();
|
||||
bool UpdateOutput();
|
||||
|
||||
ControlState GetInputState(
|
||||
const ControllerInterface::Device::Input* const input) const;
|
||||
void SetOutputState(
|
||||
const ControllerInterface::Device::Output* const output,
|
||||
const ControlState state);
|
||||
|
||||
public:
|
||||
Joystick(IOHIDDeviceRef device, std::string name, int index);
|
||||
|
||||
std::string GetName() const;
|
||||
@ -90,9 +71,9 @@ public:
|
||||
int GetId() const;
|
||||
|
||||
private:
|
||||
IOHIDDeviceRef m_device;
|
||||
std::string m_device_name;
|
||||
int m_index;
|
||||
const IOHIDDeviceRef m_device;
|
||||
const std::string m_device_name;
|
||||
const int m_index;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index)
|
||||
(IOHIDElementRef)CFArrayGetValueAtIndex(buttons, i);
|
||||
//DeviceElementDebugPrint(e, NULL);
|
||||
|
||||
AddInput(new Button(e));
|
||||
AddInput(new Button(e, m_device));
|
||||
}
|
||||
CFRelease(buttons);
|
||||
}
|
||||
@ -59,31 +59,19 @@ Joystick::Joystick(IOHIDDeviceRef device, std::string name, int index)
|
||||
//DeviceElementDebugPrint(e, NULL);
|
||||
|
||||
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));
|
||||
AddInput(new Hat(e, m_device, Hat::up));
|
||||
AddInput(new Hat(e, m_device, Hat::right));
|
||||
AddInput(new Hat(e, m_device, Hat::down));
|
||||
AddInput(new Hat(e, m_device, Hat::left));
|
||||
} else {
|
||||
AddInput(new Axis(e, Axis::negative));
|
||||
AddInput(new Axis(e, Axis::positive));
|
||||
AddInput(new Axis(e, m_device, Axis::negative));
|
||||
AddInput(new Axis(e, m_device, Axis::positive));
|
||||
}
|
||||
}
|
||||
CFRelease(axes);
|
||||
}
|
||||
}
|
||||
|
||||
ControlState Joystick::GetInputState(
|
||||
const ControllerInterface::Device::Input* const input) const
|
||||
{
|
||||
return ((Input*)input)->GetState(m_device);
|
||||
}
|
||||
|
||||
void Joystick::SetOutputState(
|
||||
const ControllerInterface::Device::Output* const output,
|
||||
const ControlState state)
|
||||
{
|
||||
}
|
||||
|
||||
bool Joystick::UpdateInput()
|
||||
{
|
||||
return true;
|
||||
@ -109,18 +97,10 @@ int Joystick::GetId() const
|
||||
return m_index;
|
||||
}
|
||||
|
||||
Joystick::Button::Button(IOHIDElementRef element)
|
||||
: m_element(element)
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << IOHIDElementGetUsage(m_element);
|
||||
m_name = std::string("Button ") + s.str();
|
||||
}
|
||||
|
||||
ControlState Joystick::Button::GetState(IOHIDDeviceRef device) const
|
||||
ControlState Joystick::Button::GetState() const
|
||||
{
|
||||
IOHIDValueRef value;
|
||||
if (IOHIDDeviceGetValue(device, m_element, &value) == kIOReturnSuccess)
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
return IOHIDValueGetIntegerValue(value);
|
||||
else
|
||||
return 0;
|
||||
@ -128,12 +108,14 @@ ControlState Joystick::Button::GetState(IOHIDDeviceRef device) const
|
||||
|
||||
std::string Joystick::Button::GetName() const
|
||||
{
|
||||
return m_name;
|
||||
std::ostringstream s;
|
||||
s << IOHIDElementGetUsage(m_element);
|
||||
return std::string("Button ") + s.str();
|
||||
}
|
||||
|
||||
|
||||
Joystick::Axis::Axis(IOHIDElementRef element, direction dir)
|
||||
Joystick::Axis::Axis(IOHIDElementRef element, IOHIDDeviceRef device, direction dir)
|
||||
: m_element(element)
|
||||
, m_device(device)
|
||||
, m_direction(dir)
|
||||
{
|
||||
// Need to parse the element a bit first
|
||||
@ -174,11 +156,11 @@ Joystick::Axis::Axis(IOHIDElementRef element, direction dir)
|
||||
m_scale = 1 / fabs(IOHIDElementGetLogicalMax(m_element) - m_neutral);
|
||||
}
|
||||
|
||||
ControlState Joystick::Axis::GetState(IOHIDDeviceRef device) const
|
||||
ControlState Joystick::Axis::GetState() const
|
||||
{
|
||||
IOHIDValueRef value;
|
||||
|
||||
if (IOHIDDeviceGetValue(device, m_element, &value) == kIOReturnSuccess)
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
{
|
||||
// IOHIDValueGetIntegerValue() crashes when trying
|
||||
// to convert unusually large element values.
|
||||
@ -201,8 +183,9 @@ std::string Joystick::Axis::GetName() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
Joystick::Hat::Hat(IOHIDElementRef element, direction dir)
|
||||
Joystick::Hat::Hat(IOHIDElementRef element, IOHIDDeviceRef device, direction dir)
|
||||
: m_element(element)
|
||||
, m_device(device)
|
||||
, m_direction(dir)
|
||||
{
|
||||
switch (dir) {
|
||||
@ -223,12 +206,12 @@ Joystick::Hat::Hat(IOHIDElementRef element, direction dir)
|
||||
}
|
||||
}
|
||||
|
||||
ControlState Joystick::Hat::GetState(IOHIDDeviceRef device) const
|
||||
ControlState Joystick::Hat::GetState() const
|
||||
{
|
||||
IOHIDValueRef value;
|
||||
int position;
|
||||
|
||||
if (IOHIDDeviceGetValue(device, m_element, &value) == kIOReturnSuccess)
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
{
|
||||
position = IOHIDValueGetIntegerValue(value);
|
||||
|
||||
|
@ -9,40 +9,23 @@ namespace OSX
|
||||
|
||||
class Keyboard : public ControllerInterface::Device
|
||||
{
|
||||
friend class ControllerInterface;
|
||||
friend class ControllerInterface::ControlReference;
|
||||
|
||||
protected:
|
||||
class Input : public ControllerInterface::Device::Input
|
||||
{
|
||||
friend class Keyboard;
|
||||
protected:
|
||||
virtual ControlState GetState(IOHIDDeviceRef device) const = 0;
|
||||
};
|
||||
|
||||
private:
|
||||
class Key : public Input
|
||||
{
|
||||
friend class Keyboard;
|
||||
public:
|
||||
std::string GetName() const;
|
||||
protected:
|
||||
Key(IOHIDElementRef element);
|
||||
ControlState GetState(IOHIDDeviceRef device) const;
|
||||
Key(IOHIDElementRef element, IOHIDDeviceRef device);
|
||||
ControlState GetState() const;
|
||||
private:
|
||||
IOHIDElementRef m_element;
|
||||
const IOHIDElementRef m_element;
|
||||
const IOHIDDeviceRef m_device;
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
public:
|
||||
bool UpdateInput();
|
||||
bool UpdateOutput();
|
||||
|
||||
ControlState GetInputState(
|
||||
const ControllerInterface::Device::Input* const input) const;
|
||||
void SetOutputState(
|
||||
const ControllerInterface::Device::Output* const output,
|
||||
const ControlState state);
|
||||
|
||||
public:
|
||||
Keyboard(IOHIDDeviceRef device, std::string name, int index);
|
||||
|
||||
std::string GetName() const;
|
||||
@ -50,8 +33,8 @@ public:
|
||||
int GetId() const;
|
||||
|
||||
private:
|
||||
IOHIDDeviceRef m_device;
|
||||
std::string m_device_name;
|
||||
const IOHIDDeviceRef m_device;
|
||||
const std::string m_device_name;
|
||||
int m_index;
|
||||
};
|
||||
|
||||
|
@ -9,7 +9,6 @@ namespace ciface
|
||||
namespace OSX
|
||||
{
|
||||
|
||||
|
||||
Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index)
|
||||
: m_device(device)
|
||||
, m_device_name(name)
|
||||
@ -36,24 +35,12 @@ Keyboard::Keyboard(IOHIDDeviceRef device, std::string name, int index)
|
||||
(IOHIDElementRef)CFArrayGetValueAtIndex(elements, i);
|
||||
//DeviceElementDebugPrint(e, NULL);
|
||||
|
||||
AddInput(new Key(e));
|
||||
AddInput(new Key(e, m_device));
|
||||
}
|
||||
CFRelease(elements);
|
||||
}
|
||||
}
|
||||
|
||||
ControlState Keyboard::GetInputState(
|
||||
const ControllerInterface::Device::Input* const input) const
|
||||
{
|
||||
return ((Input*)input)->GetState(m_device);
|
||||
}
|
||||
|
||||
void Keyboard::SetOutputState(
|
||||
const ControllerInterface::Device::Output * const output,
|
||||
const ControlState state)
|
||||
{
|
||||
}
|
||||
|
||||
bool Keyboard::UpdateInput()
|
||||
{
|
||||
return true;
|
||||
@ -79,10 +66,11 @@ int Keyboard::GetId() const
|
||||
return m_index;
|
||||
}
|
||||
|
||||
Keyboard::Key::Key(IOHIDElementRef element)
|
||||
Keyboard::Key::Key(IOHIDElementRef element, IOHIDDeviceRef device)
|
||||
: m_element(element)
|
||||
, m_device(device)
|
||||
{
|
||||
const struct PrettyKeys {
|
||||
static const struct PrettyKeys {
|
||||
const uint32_t code;
|
||||
const char *const name;
|
||||
} named_keys[] = {
|
||||
@ -190,25 +178,24 @@ Keyboard::Key::Key(IOHIDElementRef element)
|
||||
{ kHIDUsage_KeyboardRightGUI, "Right Command" },
|
||||
{ 184, "Eject" },
|
||||
};
|
||||
std::stringstream ss;
|
||||
uint32_t i, keycode;
|
||||
|
||||
keycode = IOHIDElementGetUsage(m_element);
|
||||
for (i = 0; i < sizeof named_keys / sizeof *named_keys; i++)
|
||||
|
||||
const uint32_t keycode = IOHIDElementGetUsage(m_element);
|
||||
for (uint32_t i = 0; i < sizeof named_keys / sizeof *named_keys; i++)
|
||||
if (named_keys[i].code == keycode) {
|
||||
m_name = named_keys[i].name;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "Key " << keycode;
|
||||
m_name = ss.str();
|
||||
}
|
||||
|
||||
ControlState Keyboard::Key::GetState(IOHIDDeviceRef device) const
|
||||
ControlState Keyboard::Key::GetState() const
|
||||
{
|
||||
IOHIDValueRef value;
|
||||
|
||||
if (IOHIDDeviceGetValue(device, m_element, &value) == kIOReturnSuccess)
|
||||
if (IOHIDDeviceGetValue(m_device, m_element, &value) == kIOReturnSuccess)
|
||||
return IOHIDValueGetIntegerValue(value);
|
||||
else
|
||||
return 0;
|
||||
@ -219,6 +206,5 @@ std::string Keyboard::Key::GetName() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user