device: change ControlAxis enum to an Axis enum class

This commit is contained in:
rdb 2018-08-26 21:18:29 +02:00
parent aae2b1e5ad
commit 7cc100c38c
9 changed files with 209 additions and 232 deletions

View File

@ -419,89 +419,89 @@ init_device() {
for (int i = 0; i < num_bits; ++i) { for (int i = 0; i < num_bits; ++i) {
if (test_bit(i, axes)) { if (test_bit(i, axes)) {
ControlAxis axis = C_none; Axis axis = Axis::none;
switch (i) { switch (i) {
case ABS_X: case ABS_X:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = InputDevice::C_left_x; axis = InputDevice::Axis::left_x;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = InputDevice::C_roll; axis = InputDevice::Axis::roll;
} else { } else {
axis = InputDevice::C_x; axis = InputDevice::Axis::x;
} }
break; break;
case ABS_Y: case ABS_Y:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = InputDevice::C_left_y; axis = InputDevice::Axis::left_y;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = InputDevice::C_pitch; axis = InputDevice::Axis::pitch;
} else { } else {
axis = InputDevice::C_y; axis = InputDevice::Axis::y;
} }
break; break;
case ABS_Z: case ABS_Z:
if (quirks & QB_rstick_from_z) { if (quirks & QB_rstick_from_z) {
axis = InputDevice::C_right_x; axis = InputDevice::Axis::right_x;
} else if (_device_class == DC_gamepad) { } else if (_device_class == DC_gamepad) {
axis = InputDevice::C_left_trigger; axis = InputDevice::Axis::left_trigger;
have_analog_triggers = true; have_analog_triggers = true;
} else if (_device_class == DC_3d_mouse) { } else if (_device_class == DC_3d_mouse) {
axis = InputDevice::C_z; axis = InputDevice::Axis::z;
} else { } else {
axis = InputDevice::C_throttle; axis = InputDevice::Axis::throttle;
} }
break; break;
case ABS_RX: case ABS_RX:
if (_device_class == DC_3d_mouse) { if (_device_class == DC_3d_mouse) {
axis = InputDevice::C_pitch; axis = InputDevice::Axis::pitch;
} else if ((quirks & QB_rstick_from_z) == 0) { } else if ((quirks & QB_rstick_from_z) == 0) {
axis = InputDevice::C_right_x; axis = InputDevice::Axis::right_x;
} }
break; break;
case ABS_RY: case ABS_RY:
if (_device_class == DC_3d_mouse) { if (_device_class == DC_3d_mouse) {
axis = InputDevice::C_roll; axis = InputDevice::Axis::roll;
} else if ((quirks & QB_rstick_from_z) == 0) { } else if ((quirks & QB_rstick_from_z) == 0) {
axis = InputDevice::C_right_y; axis = InputDevice::Axis::right_y;
} }
break; break;
case ABS_RZ: case ABS_RZ:
if (quirks & QB_rstick_from_z) { if (quirks & QB_rstick_from_z) {
axis = InputDevice::C_right_y; axis = InputDevice::Axis::right_y;
} else if (_device_class == DC_gamepad) { } else if (_device_class == DC_gamepad) {
axis = InputDevice::C_right_trigger; axis = InputDevice::Axis::right_trigger;
have_analog_triggers = true; have_analog_triggers = true;
} else { } else {
axis = InputDevice::C_yaw; axis = InputDevice::Axis::yaw;
} }
break; break;
case ABS_THROTTLE: case ABS_THROTTLE:
if (quirks & QB_rudder_from_throttle) { if (quirks & QB_rudder_from_throttle) {
axis = InputDevice::C_rudder; axis = InputDevice::Axis::rudder;
} else { } else {
axis = InputDevice::C_throttle; axis = InputDevice::Axis::throttle;
} }
break; break;
case ABS_RUDDER: case ABS_RUDDER:
axis = InputDevice::C_rudder; axis = InputDevice::Axis::rudder;
break; break;
case ABS_WHEEL: case ABS_WHEEL:
axis = InputDevice::C_wheel; axis = InputDevice::Axis::wheel;
break; break;
case ABS_GAS: case ABS_GAS:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = InputDevice::C_right_trigger; axis = InputDevice::Axis::right_trigger;
have_analog_triggers = true; have_analog_triggers = true;
} else { } else {
axis = InputDevice::C_accelerator; axis = InputDevice::Axis::accelerator;
} }
break; break;
case ABS_BRAKE: case ABS_BRAKE:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = InputDevice::C_left_trigger; axis = InputDevice::Axis::left_trigger;
have_analog_triggers = true; have_analog_triggers = true;
} else { } else {
axis = InputDevice::C_brake; axis = InputDevice::Axis::brake;
} }
break; break;
case ABS_HAT0X: case ABS_HAT0X:
@ -539,12 +539,12 @@ init_device() {
// We'd like to reverse the Y axis to match the XInput behavior. // We'd like to reverse the Y axis to match the XInput behavior.
// Also reverse the yaw axis to match right-hand coordinate system. // Also reverse the yaw axis to match right-hand coordinate system.
// Also T.Flight Hotas X throttle is reversed and can go backwards. // Also T.Flight Hotas X throttle is reversed and can go backwards.
if (axis == C_yaw || axis == C_rudder || axis == C_left_y || axis == C_right_y || if (axis == Axis::yaw || axis == Axis::rudder || axis == Axis::left_y || axis == Axis::right_y ||
(axis == C_throttle && (quirks & QB_reversed_throttle) != 0) || (axis == Axis::throttle && (quirks & QB_reversed_throttle) != 0) ||
(_device_class == DC_3d_mouse && (axis == C_y || axis == C_z || axis == C_roll))) { (_device_class == DC_3d_mouse && (axis == Axis::y || axis == Axis::z || axis == Axis::roll))) {
std::swap(absinfo.maximum, absinfo.minimum); std::swap(absinfo.maximum, absinfo.minimum);
} }
if (axis == C_throttle && (quirks & QB_centered_throttle) != 0) { if (axis == Axis::throttle && (quirks & QB_centered_throttle) != 0) {
index = add_control(axis, absinfo.maximum, absinfo.minimum, true); index = add_control(axis, absinfo.maximum, absinfo.minimum, true);
} else { } else {
index = add_control(axis, absinfo.minimum, absinfo.maximum); index = add_control(axis, absinfo.minimum, absinfo.maximum);
@ -584,8 +584,8 @@ init_device() {
if (_ltrigger_code >= 0 && _rtrigger_code >= 0 && !have_analog_triggers) { if (_ltrigger_code >= 0 && _rtrigger_code >= 0 && !have_analog_triggers) {
// Emulate analog triggers. // Emulate analog triggers.
_ltrigger_control = (int)_controls.size(); _ltrigger_control = (int)_controls.size();
add_control(C_left_trigger, 0, 1, false); add_control(Axis::left_trigger, 0, 1, false);
add_control(C_right_trigger, 0, 1, false); add_control(Axis::right_trigger, 0, 1, false);
} else { } else {
_ltrigger_code = -1; _ltrigger_code = -1;
_rtrigger_code = -1; _rtrigger_code = -1;

View File

@ -292,14 +292,14 @@ get_num_controls() const {
} }
/** /**
* Associates the indicated ControlAxis with the control of the indicated index * Associates the indicated Axis with the control of the indicated index
* number. Pass C_none to turn off any association. * number. Pass Axis::none to turn off any association.
* *
* It is not necessary to call this if you simply want to query the state of * It is not necessary to call this if you simply want to query the state of
* the various controls by index number. * the various controls by index number.
*/ */
INLINE void InputDevice:: INLINE void InputDevice::
set_control_map(size_t index, InputDevice::ControlAxis axis) { set_control_map(size_t index, InputDevice::Axis axis) {
LightMutexHolder holder(_lock); LightMutexHolder holder(_lock);
if (index >= _controls.size()) { if (index >= _controls.size()) {
_controls.resize(index + 1, AnalogState()); _controls.resize(index + 1, AnalogState());
@ -309,16 +309,16 @@ set_control_map(size_t index, InputDevice::ControlAxis axis) {
} }
/** /**
* Returns the ControlAxis that was previously associated with the given index * Returns the Axis that was previously associated with the given index
* number by a call to set_control_map(), or C_none if no control was * number by a call to set_control_map(), or Axis::none if no control was
* associated. * associated.
*/ */
INLINE InputDevice::ControlAxis InputDevice:: INLINE InputDevice::Axis InputDevice::
get_control_map(size_t index) const { get_control_map(size_t index) const {
if (index < _controls.size()) { if (index < _controls.size()) {
return _controls[index].axis; return _controls[index].axis;
} else { } else {
return C_none; return Axis::none;
} }
} }
@ -356,7 +356,7 @@ get_control(size_t index) const {
* if the axis was not found in the list. * if the axis was not found in the list.
*/ */
INLINE InputDevice::AnalogState InputDevice:: INLINE InputDevice::AnalogState InputDevice::
find_control(InputDevice::ControlAxis axis) const { find_control(InputDevice::Axis axis) const {
for (size_t i = 0; i < _controls.size(); ++i) { for (size_t i = 0; i < _controls.size(); ++i) {
if (_controls[i].axis == axis) { if (_controls[i].axis == axis) {
return _controls[i]; return _controls[i];
@ -444,16 +444,6 @@ operator < (const InputDevice &) const {
return false; return false;
} }
/**
*
*/
INLINE InputDevice::ButtonState::
ButtonState() :
handle(ButtonHandle::none()),
state(S_unknown)
{
}
/** /**
* *
*/ */
@ -463,16 +453,3 @@ ButtonState(ButtonHandle handle) :
state(S_unknown) state(S_unknown)
{ {
} }
/**
*
*/
INLINE InputDevice::AnalogState::
AnalogState() :
axis(C_none),
state(0.0),
known(false),
_scale(1.0),
_bias(0.0)
{
}

View File

@ -124,7 +124,7 @@ get_pointer_events() {
* Called by the implementation to add a new known control. * Called by the implementation to add a new known control.
*/ */
int InputDevice:: int InputDevice::
add_control(ControlAxis axis, int minimum, int maximum, bool centered) { add_control(Axis axis, int minimum, int maximum, bool centered) {
AnalogState state; AnalogState state;
state.axis = axis; state.axis = axis;
if (centered) { if (centered) {
@ -146,20 +146,20 @@ add_control(ControlAxis axis, int minimum, int maximum, bool centered) {
* tries to guess whether the control is centered or not. * tries to guess whether the control is centered or not.
*/ */
int InputDevice:: int InputDevice::
add_control(ControlAxis axis, int minimum, int maximum) { add_control(Axis axis, int minimum, int maximum) {
bool centered = (minimum < 0) bool centered = (minimum < 0)
|| axis == C_x || axis == Axis::x
|| axis == C_y || axis == Axis::y
|| axis == C_z || axis == Axis::z
|| axis == C_yaw || axis == Axis::yaw
|| axis == C_pitch || axis == Axis::pitch
|| axis == C_roll || axis == Axis::roll
|| axis == C_left_x || axis == Axis::left_x
|| axis == C_left_y || axis == Axis::left_y
|| axis == C_right_x || axis == Axis::right_x
|| axis == C_right_y || axis == Axis::right_y
|| axis == C_wheel || axis == Axis::wheel
|| axis == C_rudder; || axis == Axis::rudder;
return add_control(axis, minimum, maximum, centered); return add_control(axis, minimum, maximum, centered);
} }
@ -287,7 +287,7 @@ set_control_state(int index, double state) {
device_cat.spam() device_cat.spam()
<< "Changed control " << index; << "Changed control " << index;
if (_controls[index].axis != C_none) { if (_controls[index].axis != Axis::none) {
device_cat.spam(false) << " (" << _controls[index].axis << ")"; device_cat.spam(false) << " (" << _controls[index].axis << ")";
} }
@ -315,7 +315,7 @@ control_changed(int index, int state) {
device_cat.spam() device_cat.spam()
<< "Changed control " << index; << "Changed control " << index;
if (_controls[index].axis != C_none) { if (_controls[index].axis != Axis::none) {
device_cat.spam(false) << " (" << _controls[index].axis << ")"; device_cat.spam(false) << " (" << _controls[index].axis << ")";
} }
@ -556,63 +556,63 @@ format_device_class(DeviceClass dc) {
* Returns a string describing the given axis enumerant. * Returns a string describing the given axis enumerant.
*/ */
std::string InputDevice:: std::string InputDevice::
format_axis(ControlAxis axis) { format_axis(Axis axis) {
switch (axis) { switch (axis) {
case InputDevice::C_none: case InputDevice::Axis::none:
return "none"; return "none";
case InputDevice::C_x: case InputDevice::Axis::x:
return "x"; return "x";
case InputDevice::C_y: case InputDevice::Axis::y:
return "y"; return "y";
case InputDevice::C_z: case InputDevice::Axis::z:
return "z"; return "z";
case InputDevice::C_yaw: case InputDevice::Axis::yaw:
return "yaw"; return "yaw";
case InputDevice::C_pitch: case InputDevice::Axis::pitch:
return "pitch"; return "pitch";
case InputDevice::C_roll: case InputDevice::Axis::roll:
return "roll"; return "roll";
case InputDevice::C_left_x: case InputDevice::Axis::left_x:
return "left_x"; return "left_x";
case InputDevice::C_left_y: case InputDevice::Axis::left_y:
return "left_y"; return "left_y";
case InputDevice::C_left_trigger: case InputDevice::Axis::left_trigger:
return "left_trigger"; return "left_trigger";
case InputDevice::C_right_x: case InputDevice::Axis::right_x:
return "right_x"; return "right_x";
case InputDevice::C_right_y: case InputDevice::Axis::right_y:
return "right_y"; return "right_y";
case InputDevice::C_right_trigger: case InputDevice::Axis::right_trigger:
return "right_trigger"; return "right_trigger";
//case InputDevice::C_trigger: //case InputDevice::Axis::trigger:
// return "trigger"; // return "trigger";
case InputDevice::C_throttle: case InputDevice::Axis::throttle:
return "throttle"; return "throttle";
case InputDevice::C_rudder: case InputDevice::Axis::rudder:
return "rudder"; return "rudder";
case InputDevice::C_wheel: case InputDevice::Axis::wheel:
return "wheel"; return "wheel";
case InputDevice::C_accelerator: case InputDevice::Axis::accelerator:
return "accelerator"; return "accelerator";
case InputDevice::C_brake: case InputDevice::Axis::brake:
return "brake"; return "brake";
} }
return "**invalid**"; return "**invalid**";
@ -625,7 +625,7 @@ operator << (std::ostream &out, InputDevice::DeviceClass dc) {
} }
std::ostream & std::ostream &
operator << (std::ostream &out, InputDevice::ControlAxis axis) { operator << (std::ostream &out, InputDevice::Axis axis) {
out << InputDevice::format_axis(axis); out << InputDevice::format_axis(axis);
return out; return out;
} }

View File

@ -95,35 +95,35 @@ public:
~InputDevice(); ~InputDevice();
PUBLISHED: PUBLISHED:
enum ControlAxis { enum class Axis {
C_none, none,
// Generic translational axes // Generic translational axes
C_x, x,
C_y, y,
C_z, z,
// Generic rotational axes, used by joysticks and 3D mice // Generic rotational axes, used by joysticks and 3D mice
C_yaw, yaw,
C_pitch, pitch,
C_roll, roll,
// Gamepad // Gamepad
C_left_x, left_x,
C_left_y, left_y,
C_left_trigger, left_trigger,
C_right_x, right_x,
C_right_y, right_y,
C_right_trigger, right_trigger,
// Flight stick specific // Flight stick specific
C_throttle, throttle,
C_rudder, // When available separately from yaw rudder, // When available separately from yaw
// Steering wheel / pedals // Steering wheel / pedals
C_wheel, wheel,
C_accelerator, accelerator,
C_brake, brake,
}; };
INLINE std::string get_name() const; INLINE std::string get_name() const;
@ -172,8 +172,8 @@ PUBLISHED:
INLINE bool is_button_known(size_t index) const; INLINE bool is_button_known(size_t index) const;
INLINE size_t get_num_controls() const; INLINE size_t get_num_controls() const;
INLINE void set_control_map(size_t index, ControlAxis axis); INLINE void set_control_map(size_t index, Axis axis);
INLINE ControlAxis get_control_map(size_t index) const; INLINE Axis get_control_map(size_t index) const;
INLINE double get_control_state(size_t index) const; INLINE double get_control_state(size_t index) const;
INLINE bool is_control_known(size_t index) const; INLINE bool is_control_known(size_t index) const;
@ -191,12 +191,12 @@ PUBLISHED:
virtual void output(std::ostream &out) const; virtual void output(std::ostream &out) const;
static std::string format_device_class(DeviceClass dc); static std::string format_device_class(DeviceClass dc);
static std::string format_axis(ControlAxis axis); static std::string format_axis(Axis axis);
protected: protected:
// Called during the constructor to add new controls or buttons // Called during the constructor to add new controls or buttons
int add_control(ControlAxis axis, int minimum, int maximum, bool centered); int add_control(Axis axis, int minimum, int maximum, bool centered);
int add_control(ControlAxis axis, int minimum, int maximum); int add_control(Axis axis, int minimum, int maximum);
void set_pointer(bool inwin, double x, double y, double time); void set_pointer(bool inwin, double x, double y, double time);
void set_pointer_out_of_window(double time); void set_pointer_out_of_window(double time);
@ -271,28 +271,28 @@ PUBLISHED:
class ButtonState { class ButtonState {
public: public:
INLINE ButtonState(); constexpr ButtonState() = default;
INLINE ButtonState(ButtonHandle handle); INLINE ButtonState(ButtonHandle handle);
PUBLISHED: PUBLISHED:
ButtonHandle handle; ButtonHandle handle = ButtonHandle::none();
State state; State state = S_unknown;
}; };
typedef pvector<ButtonState> Buttons; typedef pvector<ButtonState> Buttons;
Buttons _buttons; Buttons _buttons;
class AnalogState { class AnalogState {
public: public:
INLINE AnalogState(); constexpr AnalogState() = default;
PUBLISHED: PUBLISHED:
ControlAxis axis; Axis axis = Axis::none;
double state; double state = 0.0;
bool known; bool known = false;
public: public:
double _scale; double _scale = 1.0;
double _bias; double _bias = 0.0;
}; };
typedef pvector<AnalogState> Controls; typedef pvector<AnalogState> Controls;
Controls _controls; Controls _controls;
@ -307,7 +307,7 @@ PUBLISHED:
INLINE ButtonState find_button(ButtonHandle handle) const; INLINE ButtonState find_button(ButtonHandle handle) const;
INLINE AnalogState get_control(size_t index) const; INLINE AnalogState get_control(size_t index) const;
INLINE AnalogState find_control(ControlAxis axis) const; INLINE AnalogState find_control(Axis axis) const;
// Make device buttons and controls iterable // Make device buttons and controls iterable
MAKE_SEQ_PROPERTY(buttons, get_num_buttons, get_button); MAKE_SEQ_PROPERTY(buttons, get_num_buttons, get_button);
@ -337,7 +337,7 @@ INLINE std::ostream &operator << (std::ostream &out, const InputDevice &device)
} }
EXPCL_PANDA_DEVICE std::ostream &operator << (std::ostream &out, InputDevice::DeviceClass dc); EXPCL_PANDA_DEVICE std::ostream &operator << (std::ostream &out, InputDevice::DeviceClass dc);
EXPCL_PANDA_DEVICE std::ostream &operator << (std::ostream &out, InputDevice::ControlAxis axis); EXPCL_PANDA_DEVICE std::ostream &operator << (std::ostream &out, InputDevice::Axis axis);
#include "inputDevice.I" #include "inputDevice.I"

View File

@ -172,7 +172,7 @@ on_remove() {
void IOKitInputDevice:: void IOKitInputDevice::
parse_element(IOHIDElementRef element) { parse_element(IOHIDElementRef element) {
ButtonHandle handle = ButtonHandle::none(); ButtonHandle handle = ButtonHandle::none();
ControlAxis axis = C_none; Axis axis = Axis::none;
uint32_t page = IOHIDElementGetUsagePage(element); uint32_t page = IOHIDElementGetUsagePage(element);
uint32_t usage = IOHIDElementGetUsage(element); uint32_t usage = IOHIDElementGetUsage(element);
@ -183,60 +183,60 @@ parse_element(IOHIDElementRef element) {
switch (usage) { switch (usage) {
case kHIDUsage_GD_X: case kHIDUsage_GD_X:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_left_x; axis = Axis::left_x;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = C_roll; axis = Axis::roll;
} else if (_device_class == DC_mouse) { } else if (_device_class == DC_mouse) {
_pointer_x = element; _pointer_x = element;
return; return;
} else { } else {
axis = C_x; axis = Axis::x;
} }
break; break;
case kHIDUsage_GD_Y: case kHIDUsage_GD_Y:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_left_y; axis = Axis::left_y;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = C_pitch; axis = Axis::pitch;
} else if (_device_class == DC_mouse) { } else if (_device_class == DC_mouse) {
_pointer_y = element; _pointer_y = element;
return; return;
} else { } else {
axis = C_y; axis = Axis::y;
} }
break; break;
case kHIDUsage_GD_Z: case kHIDUsage_GD_Z:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_left_trigger; axis = Axis::left_trigger;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = C_throttle; axis = Axis::throttle;
} else { } else {
axis = C_z; axis = Axis::z;
} }
break; break;
case kHIDUsage_GD_Rx: case kHIDUsage_GD_Rx:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_right_x; axis = Axis::right_x;
} else { } else {
axis = C_pitch; axis = Axis::pitch;
} }
break; break;
case kHIDUsage_GD_Ry: case kHIDUsage_GD_Ry:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_right_y; axis = Axis::right_y;
} else { } else {
axis = C_roll; axis = Axis::roll;
} }
break; break;
case kHIDUsage_GD_Rz: case kHIDUsage_GD_Rz:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_right_trigger; axis = Axis::right_trigger;
} else { } else {
axis = C_yaw; axis = Axis::yaw;
} }
break; break;
case kHIDUsage_GD_Slider: case kHIDUsage_GD_Slider:
axis = C_rudder; axis = Axis::rudder;
break; break;
case kHIDUsage_GD_Dial: case kHIDUsage_GD_Dial:
break; break;
@ -268,28 +268,28 @@ parse_element(IOHIDElementRef element) {
case kHIDPage_Simulation: case kHIDPage_Simulation:
switch (usage) { switch (usage) {
case kHIDUsage_Sim_Rudder: case kHIDUsage_Sim_Rudder:
axis = C_rudder; axis = Axis::rudder;
break; break;
case kHIDUsage_Sim_Throttle: case kHIDUsage_Sim_Throttle:
axis = C_throttle; axis = Axis::throttle;
break; break;
case kHIDUsage_Sim_Accelerator: case kHIDUsage_Sim_Accelerator:
axis = C_accelerator; axis = Axis::accelerator;
break; break;
case kHIDUsage_Sim_Brake: case kHIDUsage_Sim_Brake:
axis = C_brake; axis = Axis::brake;
break; break;
} }
break; break;
} }
if (axis != C_none) { if (axis != Axis::none) {
int min = IOHIDElementGetLogicalMin(element); int min = IOHIDElementGetLogicalMin(element);
int max = IOHIDElementGetLogicalMax(element); int max = IOHIDElementGetLogicalMax(element);
if (_vendor_id == 0x044f && _product_id == 0xb108 && axis == C_throttle) { if (_vendor_id == 0x044f && _product_id == 0xb108 && axis == Axis::throttle) {
// T.Flight Hotas X throttle is reversed and can go backwards. // T.Flight Hotas X throttle is reversed and can go backwards.
add_control(axis, max, min, true); add_control(axis, max, min, true);
} else if (axis == C_yaw || axis == C_rudder || axis == C_left_y || axis == C_right_y || } else if (axis == Axis::yaw || axis == Axis::rudder || axis == Axis::left_y || axis == Axis::right_y ||
(_device_class == DC_3d_mouse && (axis == C_y || axis == C_z || axis == C_roll))) { (_device_class == DC_3d_mouse && (axis == Axis::y || axis == Axis::z || axis == Axis::roll))) {
// We'd like to reverse the Y axis to match the XInput behavior. // We'd like to reverse the Y axis to match the XInput behavior.
// We also reverse yaw to obey the right-hand rule. // We also reverse yaw to obey the right-hand rule.
add_control(axis, max, min); add_control(axis, max, min);

View File

@ -118,10 +118,10 @@ consider_add_evdev_device(size_t ev_index) {
_evdev_devices[ev_index] = device; _evdev_devices[ev_index] = device;
if (device->is_connected()) { if (device->is_connected()) {
_connected_devices.add_device(MOVE(device)); _connected_devices.add_device(std::move(device));
} else { } else {
// Wait for activity on the device before it is considered connected. // Wait for activity on the device before it is considered connected.
_inactive_devices.add_device(MOVE(device)); _inactive_devices.add_device(std::move(device));
} }
return _evdev_devices[ev_index]; return _evdev_devices[ev_index];
} }
@ -189,10 +189,10 @@ consider_add_js_device(size_t js_index) {
InputDevice *device_p = device.p(); InputDevice *device_p = device.p();
if (device->is_connected()) { if (device->is_connected()) {
_connected_devices.add_device(MOVE(device)); _connected_devices.add_device(std::move(device));
} else { } else {
// Wait for activity on the device before it is considered connected. // Wait for activity on the device before it is considered connected.
_inactive_devices.add_device(MOVE(device)); _inactive_devices.add_device(std::move(device));
} }
return device_p; return device_p;
} }

View File

@ -152,71 +152,71 @@ open_device() {
ioctl(_fd, JSIOCGAXMAP, axmap); ioctl(_fd, JSIOCGAXMAP, axmap);
for (uint8_t i = 0; i < num_axes; ++i) { for (uint8_t i = 0; i < num_axes; ++i) {
ControlAxis axis = C_none; Axis axis = Axis::none;
switch (axmap[i]) { switch (axmap[i]) {
case ABS_X: case ABS_X:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = InputDevice::C_left_x; axis = InputDevice::Axis::left_x;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = InputDevice::C_roll; axis = InputDevice::Axis::roll;
} else { } else {
axis = InputDevice::C_x; axis = InputDevice::Axis::x;
} }
break; break;
case ABS_Y: case ABS_Y:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = InputDevice::C_left_y; axis = InputDevice::Axis::left_y;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = InputDevice::C_pitch; axis = InputDevice::Axis::pitch;
} else { } else {
axis = InputDevice::C_y; axis = InputDevice::Axis::y;
} }
break; break;
case ABS_Z: case ABS_Z:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_left_trigger; axis = Axis::left_trigger;
} else { } else {
//axis = C_trigger; //axis = Axis::trigger;
} }
break; break;
case ABS_RX: case ABS_RX:
axis = C_right_x; axis = Axis::right_x;
break; break;
case ABS_RY: case ABS_RY:
axis = C_right_y; axis = Axis::right_y;
break; break;
case ABS_RZ: case ABS_RZ:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = InputDevice::C_right_trigger; axis = InputDevice::Axis::right_trigger;
} else { } else {
axis = InputDevice::C_yaw; axis = InputDevice::Axis::yaw;
} }
break; break;
case ABS_THROTTLE: case ABS_THROTTLE:
axis = InputDevice::C_throttle; axis = InputDevice::Axis::throttle;
break; break;
case ABS_RUDDER: case ABS_RUDDER:
axis = InputDevice::C_rudder; axis = InputDevice::Axis::rudder;
break; break;
case ABS_WHEEL: case ABS_WHEEL:
axis = InputDevice::C_wheel; axis = InputDevice::Axis::wheel;
break; break;
case ABS_GAS: case ABS_GAS:
axis = InputDevice::C_accelerator; axis = InputDevice::Axis::accelerator;
break; break;
case ABS_BRAKE: case ABS_BRAKE:
axis = InputDevice::C_brake; axis = InputDevice::Axis::brake;
break; break;
case ABS_HAT0X: case ABS_HAT0X:
@ -231,7 +231,7 @@ open_device() {
_buttons.push_back(ButtonState(GamepadButton::hat_left())); _buttons.push_back(ButtonState(GamepadButton::hat_left()));
_buttons.push_back(ButtonState(GamepadButton::hat_right())); _buttons.push_back(ButtonState(GamepadButton::hat_right()));
} }
axis = C_none; axis = Axis::none;
} }
break; break;
@ -247,7 +247,7 @@ open_device() {
_buttons.push_back(ButtonState(GamepadButton::hat_up())); _buttons.push_back(ButtonState(GamepadButton::hat_up()));
_buttons.push_back(ButtonState(GamepadButton::hat_down())); _buttons.push_back(ButtonState(GamepadButton::hat_down()));
} }
axis = C_none; axis = Axis::none;
} }
break; break;
@ -256,17 +256,17 @@ open_device() {
device_cat.debug() << "Unmapped /dev/input/js" << _index device_cat.debug() << "Unmapped /dev/input/js" << _index
<< " axis " << (int)i << ": 0x" << std::hex << (int)axmap[i] << "\n"; << " axis " << (int)i << ": 0x" << std::hex << (int)axmap[i] << "\n";
} }
axis = C_none; axis = Axis::none;
break; break;
} }
_controls[i].axis = axis; _controls[i].axis = axis;
if (axis == C_left_trigger || axis == C_right_trigger) { if (axis == Axis::left_trigger || axis == Axis::right_trigger) {
// We'd like to use 0.0 to indicate the resting position. // We'd like to use 0.0 to indicate the resting position.
_controls[i]._scale = 1.0 / 65534.0; _controls[i]._scale = 1.0 / 65534.0;
_controls[i]._bias = 0.5; _controls[i]._bias = 0.5;
have_analog_triggers = true; have_analog_triggers = true;
} else if (axis == C_left_y || axis == C_right_y || axis == C_y) { } else if (axis == Axis::left_y || axis == Axis::right_y || axis == Axis::y) {
_controls[i]._scale = 1.0 / -32767.0; _controls[i]._scale = 1.0 / -32767.0;
_controls[i]._bias = 0.0; _controls[i]._bias = 0.0;
} else { } else {
@ -279,8 +279,8 @@ open_device() {
if (_ltrigger_button >= 0 && _rtrigger_button >= 0 && !have_analog_triggers) { if (_ltrigger_button >= 0 && _rtrigger_button >= 0 && !have_analog_triggers) {
// Emulate analog triggers. // Emulate analog triggers.
_ltrigger_control = (int)_controls.size(); _ltrigger_control = (int)_controls.size();
add_control(C_left_trigger, 0, 1, false); add_control(Axis::left_trigger, 0, 1, false);
add_control(C_right_trigger, 0, 1, false); add_control(Axis::right_trigger, 0, 1, false);
} else { } else {
_ltrigger_button = -1; _ltrigger_button = -1;
_rtrigger_button = -1; _rtrigger_button = -1;

View File

@ -478,71 +478,71 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
is_signed = false; is_signed = false;
} }
ControlAxis axis = C_none; Axis axis = Axis::none;
switch (cap.UsagePage) { switch (cap.UsagePage) {
case HID_USAGE_PAGE_GENERIC: case HID_USAGE_PAGE_GENERIC:
switch (usage) { switch (usage) {
case HID_USAGE_GENERIC_X: case HID_USAGE_GENERIC_X:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_left_x; axis = Axis::left_x;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = C_roll; axis = Axis::roll;
} else { } else {
axis = C_x; axis = Axis::x;
} }
break; break;
case HID_USAGE_GENERIC_Y: case HID_USAGE_GENERIC_Y:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_left_y; axis = Axis::left_y;
swap(cap.LogicalMin, cap.LogicalMax); swap(cap.LogicalMin, cap.LogicalMax);
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = C_pitch; axis = Axis::pitch;
} else { } else {
axis = C_y; axis = Axis::y;
swap(cap.LogicalMin, cap.LogicalMax); swap(cap.LogicalMin, cap.LogicalMax);
} }
break; break;
case HID_USAGE_GENERIC_Z: case HID_USAGE_GENERIC_Z:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_left_trigger; axis = Axis::left_trigger;
} else if (_device_class == DC_flight_stick) { } else if (_device_class == DC_flight_stick) {
axis = C_throttle; axis = Axis::throttle;
} else { } else {
axis = C_z; axis = Axis::z;
swap(cap.LogicalMin, cap.LogicalMax); swap(cap.LogicalMin, cap.LogicalMax);
} }
break; break;
case HID_USAGE_GENERIC_RX: case HID_USAGE_GENERIC_RX:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_right_x; axis = Axis::right_x;
} else { } else {
axis = C_pitch; axis = Axis::pitch;
} }
break; break;
case HID_USAGE_GENERIC_RY: case HID_USAGE_GENERIC_RY:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_right_y; axis = Axis::right_y;
} else { } else {
axis = C_roll; axis = Axis::roll;
} }
swap(cap.LogicalMin, cap.LogicalMax); swap(cap.LogicalMin, cap.LogicalMax);
break; break;
case HID_USAGE_GENERIC_RZ: case HID_USAGE_GENERIC_RZ:
if (_device_class == DC_gamepad) { if (_device_class == DC_gamepad) {
axis = C_right_trigger; axis = Axis::right_trigger;
} else { } else {
// Flip to match Panda's convention for heading. // Flip to match Panda's convention for heading.
axis = C_yaw; axis = Axis::yaw;
swap(cap.LogicalMin, cap.LogicalMax); swap(cap.LogicalMin, cap.LogicalMax);
} }
break; break;
case HID_USAGE_GENERIC_SLIDER: case HID_USAGE_GENERIC_SLIDER:
// Flip to match Panda's convention for heading. // Flip to match Panda's convention for heading.
axis = C_rudder; axis = Axis::rudder;
swap(cap.LogicalMin, cap.LogicalMax); swap(cap.LogicalMin, cap.LogicalMax);
break; break;
case HID_USAGE_GENERIC_WHEEL: case HID_USAGE_GENERIC_WHEEL:
axis = C_wheel; axis = Axis::wheel;
break; break;
case HID_USAGE_GENERIC_HATSWITCH: case HID_USAGE_GENERIC_HATSWITCH:
// This is handled specially. // This is handled specially.
@ -554,7 +554,7 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
} }
int control_index; int control_index;
if (_vendor_id == 0x044f && _product_id == 0xb108 && axis == C_throttle) { if (_vendor_id == 0x044f && _product_id == 0xb108 && axis == Axis::throttle) {
// T.Flight Hotas X throttle is reversed and can go backwards. // T.Flight Hotas X throttle is reversed and can go backwards.
control_index = add_control(axis, cap.LogicalMax, cap.LogicalMin, true); control_index = add_control(axis, cap.LogicalMax, cap.LogicalMin, true);
} else if (!is_signed) { } else if (!is_signed) {

View File

@ -315,42 +315,42 @@ init_device(const XINPUT_CAPABILITIES_EX &caps, const XINPUT_STATE &state) {
default: default:
case XINPUT_DEVSUBTYPE_GAMEPAD: case XINPUT_DEVSUBTYPE_GAMEPAD:
_device_class = DC_gamepad; _device_class = DC_gamepad;
set_control_map(0, C_left_trigger); set_control_map(0, Axis::left_trigger);
set_control_map(1, C_right_trigger); set_control_map(1, Axis::right_trigger);
set_control_map(2, C_left_x); set_control_map(2, Axis::left_x);
set_control_map(3, C_left_y); set_control_map(3, Axis::left_y);
set_control_map(4, C_right_x); set_control_map(4, Axis::right_x);
set_control_map(5, C_right_y); set_control_map(5, Axis::right_y);
break; break;
case XINPUT_DEVSUBTYPE_WHEEL: case XINPUT_DEVSUBTYPE_WHEEL:
_device_class = DC_steering_wheel; _device_class = DC_steering_wheel;
set_control_map(0, C_brake); set_control_map(0, Axis::brake);
set_control_map(1, C_accelerator); set_control_map(1, Axis::accelerator);
set_control_map(2, C_wheel); set_control_map(2, Axis::wheel);
set_control_map(3, C_none); set_control_map(3, Axis::none);
set_control_map(4, C_none); set_control_map(4, Axis::none);
set_control_map(5, C_none); set_control_map(5, Axis::none);
break; break;
case XINPUT_DEVSUBTYPE_FLIGHT_STICK: case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
_device_class = DC_flight_stick; _device_class = DC_flight_stick;
set_control_map(0, C_yaw); set_control_map(0, Axis::yaw);
set_control_map(1, C_throttle); set_control_map(1, Axis::throttle);
set_control_map(2, C_roll); set_control_map(2, Axis::roll);
set_control_map(3, C_pitch); set_control_map(3, Axis::pitch);
set_control_map(4, C_none); set_control_map(4, Axis::none);
set_control_map(5, C_none); set_control_map(5, Axis::none);
break; break;
case XINPUT_DEVSUBTYPE_DANCE_PAD: case XINPUT_DEVSUBTYPE_DANCE_PAD:
_device_class = DC_dance_pad; _device_class = DC_dance_pad;
set_control_map(0, C_none); set_control_map(0, Axis::none);
set_control_map(1, C_none); set_control_map(1, Axis::none);
set_control_map(2, C_none); set_control_map(2, Axis::none);
set_control_map(3, C_none); set_control_map(3, Axis::none);
set_control_map(4, C_none); set_control_map(4, Axis::none);
set_control_map(5, C_none); set_control_map(5, Axis::none);
break; break;
} }