mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-29 08:15:18 -04:00
Switch to UPPER_CASE convention for enum classes as per PEP-8
Old names are still kept around for compatibility reasons, but deprecated - fortunately there are not that many cases of enum classes yet
This commit is contained in:
parent
bc039a0476
commit
c34f2bbc64
@ -24,7 +24,7 @@ TypeHandle ClientDevice::_type_handle;
|
|||||||
ClientDevice::
|
ClientDevice::
|
||||||
ClientDevice(ClientBase *client, TypeHandle device_type,
|
ClientDevice(ClientBase *client, TypeHandle device_type,
|
||||||
const std::string &device_name) :
|
const std::string &device_name) :
|
||||||
InputDevice(device_name, DeviceClass::unknown),
|
InputDevice(device_name, DeviceClass::UNKNOWN),
|
||||||
_client(client),
|
_client(client),
|
||||||
_device_type(device_type)
|
_device_type(device_type)
|
||||||
{
|
{
|
||||||
|
@ -18,5 +18,5 @@ INLINE ClientTrackerDevice::
|
|||||||
ClientTrackerDevice(ClientBase *client, const std::string &device_name):
|
ClientTrackerDevice(ClientBase *client, const std::string &device_name):
|
||||||
ClientDevice(client, get_class_type(), device_name)
|
ClientDevice(client, get_class_type(), device_name)
|
||||||
{
|
{
|
||||||
enable_feature(Feature::tracker);
|
enable_feature(Feature::TRACKER);
|
||||||
}
|
}
|
||||||
|
@ -80,41 +80,41 @@ static const struct DeviceMapping {
|
|||||||
int quirks;
|
int quirks;
|
||||||
} mapping_presets[] = {
|
} mapping_presets[] = {
|
||||||
// NVIDIA Shield Controller
|
// NVIDIA Shield Controller
|
||||||
{0x0955, 0x7214, InputDevice::DeviceClass::gamepad, QB_rstick_from_z},
|
{0x0955, 0x7214, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z},
|
||||||
// T.Flight Hotas X
|
// T.Flight Hotas X
|
||||||
{0x044f, 0xb108, InputDevice::DeviceClass::flight_stick, QB_centered_throttle | QB_reversed_throttle | QB_rudder_from_throttle},
|
{0x044f, 0xb108, InputDevice::DeviceClass::FLIGHT_STICK, QB_centered_throttle | QB_reversed_throttle | QB_rudder_from_throttle},
|
||||||
// Xbox 360 Wireless Controller
|
// Xbox 360 Wireless Controller
|
||||||
{0x045e, 0x0719, InputDevice::DeviceClass::gamepad, QB_connect_if_nonzero},
|
{0x045e, 0x0719, InputDevice::DeviceClass::GAMEPAD, QB_connect_if_nonzero},
|
||||||
// Steam Controller (wired)
|
// Steam Controller (wired)
|
||||||
{0x28de, 0x1102, InputDevice::DeviceClass::unknown, QB_steam_controller},
|
{0x28de, 0x1102, InputDevice::DeviceClass::UNKNOWN, QB_steam_controller},
|
||||||
// Steam Controller (wireless)
|
// Steam Controller (wireless)
|
||||||
{0x28de, 0x1142, InputDevice::DeviceClass::unknown, QB_steam_controller},
|
{0x28de, 0x1142, InputDevice::DeviceClass::UNKNOWN, QB_steam_controller},
|
||||||
// Jess Tech Colour Rumble Pad
|
// Jess Tech Colour Rumble Pad
|
||||||
{0x0f30, 0x0111, InputDevice::DeviceClass::gamepad, QB_rstick_from_z | QB_right_axes_swapped},
|
{0x0f30, 0x0111, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z | QB_right_axes_swapped},
|
||||||
// Trust GXT 24
|
// Trust GXT 24
|
||||||
{0x0079, 0x0006, InputDevice::DeviceClass::gamepad, QB_no_analog_triggers | QB_alt_button_mapping},
|
{0x0079, 0x0006, InputDevice::DeviceClass::GAMEPAD, QB_no_analog_triggers | QB_alt_button_mapping},
|
||||||
// 8bitdo N30 Pro Controller
|
// 8bitdo N30 Pro Controller
|
||||||
{0x2dc8, 0x9001, InputDevice::DeviceClass::gamepad, QB_rstick_from_z},
|
{0x2dc8, 0x9001, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z},
|
||||||
// Generic gamepad
|
// Generic gamepad
|
||||||
{0x0810, 0x0001, InputDevice::DeviceClass::gamepad, QB_no_analog_triggers | QB_alt_button_mapping | QB_rstick_from_z | QB_right_axes_swapped},
|
{0x0810, 0x0001, InputDevice::DeviceClass::GAMEPAD, QB_no_analog_triggers | QB_alt_button_mapping | QB_rstick_from_z | QB_right_axes_swapped},
|
||||||
// Generic gamepad without sticks
|
// Generic gamepad without sticks
|
||||||
{0x0810, 0xe501, InputDevice::DeviceClass::gamepad, QB_no_analog_triggers | QB_alt_button_mapping},
|
{0x0810, 0xe501, InputDevice::DeviceClass::GAMEPAD, QB_no_analog_triggers | QB_alt_button_mapping},
|
||||||
// 3Dconnexion Space Traveller 3D Mouse
|
// 3Dconnexion Space Traveller 3D Mouse
|
||||||
{0x046d, 0xc623, InputDevice::DeviceClass::spatial_mouse, 0},
|
{0x046d, 0xc623, InputDevice::DeviceClass::SPATIAL_MOUSE, 0},
|
||||||
// 3Dconnexion Space Pilot 3D Mouse
|
// 3Dconnexion Space Pilot 3D Mouse
|
||||||
{0x046d, 0xc625, InputDevice::DeviceClass::spatial_mouse, 0},
|
{0x046d, 0xc625, InputDevice::DeviceClass::SPATIAL_MOUSE, 0},
|
||||||
// 3Dconnexion Space Navigator 3D Mouse
|
// 3Dconnexion Space Navigator 3D Mouse
|
||||||
{0x046d, 0xc626, InputDevice::DeviceClass::spatial_mouse, 0},
|
{0x046d, 0xc626, InputDevice::DeviceClass::SPATIAL_MOUSE, 0},
|
||||||
// 3Dconnexion Space Explorer 3D Mouse
|
// 3Dconnexion Space Explorer 3D Mouse
|
||||||
{0x046d, 0xc627, InputDevice::DeviceClass::spatial_mouse, 0},
|
{0x046d, 0xc627, InputDevice::DeviceClass::SPATIAL_MOUSE, 0},
|
||||||
// 3Dconnexion Space Navigator for Notebooks
|
// 3Dconnexion Space Navigator for Notebooks
|
||||||
{0x046d, 0xc628, InputDevice::DeviceClass::spatial_mouse, 0},
|
{0x046d, 0xc628, InputDevice::DeviceClass::SPATIAL_MOUSE, 0},
|
||||||
// 3Dconnexion SpacePilot Pro 3D Mouse
|
// 3Dconnexion SpacePilot Pro 3D Mouse
|
||||||
{0x046d, 0xc629, InputDevice::DeviceClass::spatial_mouse, 0},
|
{0x046d, 0xc629, InputDevice::DeviceClass::SPATIAL_MOUSE, 0},
|
||||||
// 3Dconnexion Space Mouse Pro
|
// 3Dconnexion Space Mouse Pro
|
||||||
{0x046d, 0xc62b, InputDevice::DeviceClass::spatial_mouse, 0},
|
{0x046d, 0xc62b, InputDevice::DeviceClass::SPATIAL_MOUSE, 0},
|
||||||
// FrSky Simulator
|
// FrSky Simulator
|
||||||
{0x0483, 0x5720, InputDevice::DeviceClass::flight_stick, 0},
|
{0x0483, 0x5720, InputDevice::DeviceClass::FLIGHT_STICK, 0},
|
||||||
{0},
|
{0},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ init_device() {
|
|||||||
has_keys = true;
|
has_keys = true;
|
||||||
|
|
||||||
if (test_bit(KEY_A, keys) && test_bit(KEY_Z, keys)) {
|
if (test_bit(KEY_A, keys) && test_bit(KEY_Z, keys)) {
|
||||||
enable_feature(Feature::keyboard);
|
enable_feature(Feature::KEYBOARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,7 +364,7 @@ init_device() {
|
|||||||
// The Steam Controller reports as multiple devices, one of which a gamepad.
|
// The Steam Controller reports as multiple devices, one of which a gamepad.
|
||||||
if (quirks & QB_steam_controller) {
|
if (quirks & QB_steam_controller) {
|
||||||
if (test_bit(BTN_GAMEPAD, keys)) {
|
if (test_bit(BTN_GAMEPAD, keys)) {
|
||||||
_device_class = DeviceClass::gamepad;
|
_device_class = DeviceClass::GAMEPAD;
|
||||||
|
|
||||||
// If we have a virtual gamepad on the system, then careful: if Steam is
|
// If we have a virtual gamepad on the system, then careful: if Steam is
|
||||||
// running, it may disable its own gamepad in favour of the virtual
|
// running, it may disable its own gamepad in favour of the virtual
|
||||||
@ -380,41 +380,41 @@ init_device() {
|
|||||||
_quirks = quirks;
|
_quirks = quirks;
|
||||||
|
|
||||||
// Try to detect which type of device we have here
|
// Try to detect which type of device we have here
|
||||||
if (_device_class == DeviceClass::unknown) {
|
if (_device_class == DeviceClass::UNKNOWN) {
|
||||||
int device_scores[(size_t)DeviceClass::digitizer + 1] = {0};
|
int device_scores[(size_t)DeviceClass::DIGITIZER + 1] = {0};
|
||||||
|
|
||||||
// Test for specific keys
|
// Test for specific keys
|
||||||
if (test_bit(BTN_GAMEPAD, keys) && test_bit(ABS_X, axes) && test_bit(ABS_RX, axes)) {
|
if (test_bit(BTN_GAMEPAD, keys) && test_bit(ABS_X, axes) && test_bit(ABS_RX, axes)) {
|
||||||
device_scores[(size_t)DeviceClass::gamepad] += 5;
|
device_scores[(size_t)DeviceClass::GAMEPAD] += 5;
|
||||||
device_scores[(size_t)DeviceClass::steering_wheel] += 5;
|
device_scores[(size_t)DeviceClass::STEERING_WHEEL] += 5;
|
||||||
device_scores[(size_t)DeviceClass::flight_stick] += 5;
|
device_scores[(size_t)DeviceClass::FLIGHT_STICK] += 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test_bit(ABS_WHEEL, axes) && test_bit(ABS_GAS, axes) && test_bit(ABS_BRAKE, axes)) {
|
if (test_bit(ABS_WHEEL, axes) && test_bit(ABS_GAS, axes) && test_bit(ABS_BRAKE, axes)) {
|
||||||
device_scores[(size_t)DeviceClass::steering_wheel] += 10;
|
device_scores[(size_t)DeviceClass::STEERING_WHEEL] += 10;
|
||||||
}
|
}
|
||||||
if (test_bit(BTN_GEAR_DOWN, keys) && test_bit(BTN_GEAR_UP, keys)) {
|
if (test_bit(BTN_GEAR_DOWN, keys) && test_bit(BTN_GEAR_UP, keys)) {
|
||||||
device_scores[(size_t)DeviceClass::steering_wheel] += 10;
|
device_scores[(size_t)DeviceClass::STEERING_WHEEL] += 10;
|
||||||
}
|
}
|
||||||
if (test_bit(BTN_JOYSTICK, keys) && test_bit(ABS_X, axes)) {
|
if (test_bit(BTN_JOYSTICK, keys) && test_bit(ABS_X, axes)) {
|
||||||
device_scores[(size_t)DeviceClass::flight_stick] += 10;
|
device_scores[(size_t)DeviceClass::FLIGHT_STICK] += 10;
|
||||||
}
|
}
|
||||||
if (test_bit(BTN_MOUSE, keys) && test_bit(EV_REL, evtypes)) {
|
if (test_bit(BTN_MOUSE, keys) && test_bit(EV_REL, evtypes)) {
|
||||||
device_scores[(size_t)DeviceClass::mouse] += 20;
|
device_scores[(size_t)DeviceClass::MOUSE] += 20;
|
||||||
}
|
}
|
||||||
if (test_bit(BTN_DIGI, keys) && test_bit(EV_ABS, evtypes)) {
|
if (test_bit(BTN_DIGI, keys) && test_bit(EV_ABS, evtypes)) {
|
||||||
device_scores[(size_t)DeviceClass::digitizer] += 20;
|
device_scores[(size_t)DeviceClass::DIGITIZER] += 20;
|
||||||
}
|
}
|
||||||
uint8_t unknown_keys[] = {KEY_POWER};
|
uint8_t unknown_keys[] = {KEY_POWER};
|
||||||
for (int i = 0; i < 1; i++) {
|
for (int i = 0; i < 1; i++) {
|
||||||
if (test_bit(unknown_keys[i], keys)) {
|
if (test_bit(unknown_keys[i], keys)) {
|
||||||
if (unknown_keys[i] == KEY_POWER) {
|
if (unknown_keys[i] == KEY_POWER) {
|
||||||
}
|
}
|
||||||
device_scores[(size_t)DeviceClass::unknown] += 20;
|
device_scores[(size_t)DeviceClass::UNKNOWN] += 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_features & (unsigned int)Feature::keyboard) {
|
if (_features & (unsigned int)Feature::KEYBOARD) {
|
||||||
device_scores[(size_t)DeviceClass::keyboard] += 20;
|
device_scores[(size_t)DeviceClass::KEYBOARD] += 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test for specific name tags
|
// Test for specific name tags
|
||||||
@ -423,28 +423,28 @@ init_device() {
|
|||||||
lowercase_name[x] = tolower(lowercase_name[x]);
|
lowercase_name[x] = tolower(lowercase_name[x]);
|
||||||
}
|
}
|
||||||
if (lowercase_name.find("gamepad") != string::npos) {
|
if (lowercase_name.find("gamepad") != string::npos) {
|
||||||
device_scores[(size_t)DeviceClass::gamepad] += 10;
|
device_scores[(size_t)DeviceClass::GAMEPAD] += 10;
|
||||||
}
|
}
|
||||||
if (lowercase_name.find("wheel") != string::npos) {
|
if (lowercase_name.find("wheel") != string::npos) {
|
||||||
device_scores[(size_t)DeviceClass::steering_wheel] += 10;
|
device_scores[(size_t)DeviceClass::STEERING_WHEEL] += 10;
|
||||||
}
|
}
|
||||||
if (lowercase_name.find("mouse") != string::npos || lowercase_name.find("touchpad") != string::npos) {
|
if (lowercase_name.find("mouse") != string::npos || lowercase_name.find("touchpad") != string::npos) {
|
||||||
device_scores[(size_t)DeviceClass::mouse] += 10;
|
device_scores[(size_t)DeviceClass::MOUSE] += 10;
|
||||||
}
|
}
|
||||||
if (lowercase_name.find("keyboard") != string::npos) {
|
if (lowercase_name.find("keyboard") != string::npos) {
|
||||||
device_scores[(size_t)DeviceClass::keyboard] += 10;
|
device_scores[(size_t)DeviceClass::KEYBOARD] += 10;
|
||||||
}
|
}
|
||||||
// List of lowercase names that occur in unknown devices
|
// List of lowercase names that occur in unknown devices
|
||||||
string unknown_names[] = {"video bus", "power button", "sleep button"};
|
string unknown_names[] = {"video bus", "power button", "sleep button"};
|
||||||
for(int i = 0; i < 3; i++) {
|
for(int i = 0; i < 3; i++) {
|
||||||
if (lowercase_name.find(unknown_names[i]) != string::npos) {
|
if (lowercase_name.find(unknown_names[i]) != string::npos) {
|
||||||
device_scores[(size_t)DeviceClass::unknown] += 20;
|
device_scores[(size_t)DeviceClass::UNKNOWN] += 20;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check which device type got the most points
|
// Check which device type got the most points
|
||||||
int highest_score = 0;
|
int highest_score = 0;
|
||||||
for (size_t i = 0; i <= (size_t)DeviceClass::digitizer; i++) {
|
for (size_t i = 0; i <= (size_t)DeviceClass::DIGITIZER; i++) {
|
||||||
if (device_scores[i] > highest_score) {
|
if (device_scores[i] > highest_score) {
|
||||||
highest_score = device_scores[i];
|
highest_score = device_scores[i];
|
||||||
_device_class = (DeviceClass)i;
|
_device_class = (DeviceClass)i;
|
||||||
@ -499,113 +499,113 @@ 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)) {
|
||||||
Axis axis = Axis::none;
|
Axis axis = Axis::NONE;
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case ABS_X:
|
case ABS_X:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = InputDevice::Axis::left_x;
|
axis = Axis::LEFT_X;
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = InputDevice::Axis::roll;
|
axis = Axis::ROLL;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::x;
|
axis = Axis::X;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_Y:
|
case ABS_Y:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = InputDevice::Axis::left_y;
|
axis = Axis::LEFT_Y;
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = InputDevice::Axis::pitch;
|
axis = Axis::PITCH;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::y;
|
axis = Axis::Y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_Z:
|
case ABS_Z:
|
||||||
if (quirks & QB_rstick_from_z) {
|
if (quirks & QB_rstick_from_z) {
|
||||||
if (quirks & QB_right_axes_swapped) {
|
if (quirks & QB_right_axes_swapped) {
|
||||||
axis = InputDevice::Axis::right_y;
|
axis = Axis::RIGHT_Y;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::right_x;
|
axis = Axis::RIGHT_X;
|
||||||
}
|
}
|
||||||
} else if (_device_class == DeviceClass::gamepad) {
|
} else if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if ((quirks & QB_no_analog_triggers) == 0) {
|
if ((quirks & QB_no_analog_triggers) == 0) {
|
||||||
axis = InputDevice::Axis::left_trigger;
|
axis = Axis::LEFT_TRIGGER;
|
||||||
have_analog_triggers = true;
|
have_analog_triggers = true;
|
||||||
}
|
}
|
||||||
} else if (_device_class == DeviceClass::spatial_mouse) {
|
} else if (_device_class == DeviceClass::SPATIAL_MOUSE) {
|
||||||
axis = InputDevice::Axis::z;
|
axis = Axis::Z;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::throttle;
|
axis = Axis::THROTTLE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_RX:
|
case ABS_RX:
|
||||||
if (_device_class == DeviceClass::spatial_mouse) {
|
if (_device_class == DeviceClass::SPATIAL_MOUSE) {
|
||||||
axis = InputDevice::Axis::pitch;
|
axis = Axis::PITCH;
|
||||||
} else if ((quirks & QB_rstick_from_z) == 0) {
|
} else if ((quirks & QB_rstick_from_z) == 0) {
|
||||||
axis = InputDevice::Axis::right_x;
|
axis = Axis::RIGHT_X;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_RY:
|
case ABS_RY:
|
||||||
if (_device_class == DeviceClass::spatial_mouse) {
|
if (_device_class == DeviceClass::SPATIAL_MOUSE) {
|
||||||
axis = InputDevice::Axis::roll;
|
axis = Axis::ROLL;
|
||||||
} else if ((quirks & QB_rstick_from_z) == 0) {
|
} else if ((quirks & QB_rstick_from_z) == 0) {
|
||||||
axis = InputDevice::Axis::right_y;
|
axis = Axis::RIGHT_Y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_RZ:
|
case ABS_RZ:
|
||||||
if (quirks & QB_rstick_from_z) {
|
if (quirks & QB_rstick_from_z) {
|
||||||
if (quirks & QB_right_axes_swapped) {
|
if (quirks & QB_right_axes_swapped) {
|
||||||
axis = InputDevice::Axis::right_x;
|
axis = Axis::RIGHT_X;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::right_y;
|
axis = Axis::RIGHT_Y;
|
||||||
}
|
}
|
||||||
} else if (_device_class == DeviceClass::gamepad) {
|
} else if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if ((quirks & QB_no_analog_triggers) == 0) {
|
if ((quirks & QB_no_analog_triggers) == 0) {
|
||||||
axis = InputDevice::Axis::right_trigger;
|
axis = Axis::RIGHT_TRIGGER;
|
||||||
have_analog_triggers = true;
|
have_analog_triggers = true;
|
||||||
} else {
|
} else {
|
||||||
// Special weird case for Trust GXT 24
|
// Special weird case for Trust GXT 24
|
||||||
axis = InputDevice::Axis::right_y;
|
axis = Axis::RIGHT_Y;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::yaw;
|
axis = Axis::YAW;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_THROTTLE:
|
case ABS_THROTTLE:
|
||||||
if (quirks & QB_rudder_from_throttle) {
|
if (quirks & QB_rudder_from_throttle) {
|
||||||
axis = InputDevice::Axis::rudder;
|
axis = Axis::RUDDER;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::throttle;
|
axis = Axis::THROTTLE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_RUDDER:
|
case ABS_RUDDER:
|
||||||
axis = InputDevice::Axis::rudder;
|
axis = Axis::RUDDER;
|
||||||
break;
|
break;
|
||||||
case ABS_WHEEL:
|
case ABS_WHEEL:
|
||||||
axis = InputDevice::Axis::wheel;
|
axis = Axis::WHEEL;
|
||||||
break;
|
break;
|
||||||
case ABS_GAS:
|
case ABS_GAS:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if ((quirks & QB_no_analog_triggers) == 0) {
|
if ((quirks & QB_no_analog_triggers) == 0) {
|
||||||
axis = InputDevice::Axis::right_trigger;
|
axis = Axis::RIGHT_TRIGGER;
|
||||||
have_analog_triggers = true;
|
have_analog_triggers = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::accelerator;
|
axis = Axis::ACCELERATOR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_BRAKE:
|
case ABS_BRAKE:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = InputDevice::Axis::left_trigger;
|
axis = Axis::LEFT_TRIGGER;
|
||||||
have_analog_triggers = true;
|
have_analog_triggers = true;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::brake;
|
axis = Axis::BRAKE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_HAT0X:
|
case ABS_HAT0X:
|
||||||
if (emulate_dpad) {
|
if (emulate_dpad) {
|
||||||
_dpad_x_axis = i;
|
_dpad_x_axis = i;
|
||||||
_dpad_left_button = (int)_buttons.size();
|
_dpad_left_button = (int)_buttons.size();
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
_buttons.push_back(ButtonState(GamepadButton::dpad_left()));
|
_buttons.push_back(ButtonState(GamepadButton::dpad_left()));
|
||||||
_buttons.push_back(ButtonState(GamepadButton::dpad_right()));
|
_buttons.push_back(ButtonState(GamepadButton::dpad_right()));
|
||||||
} else {
|
} else {
|
||||||
@ -620,7 +620,7 @@ init_device() {
|
|||||||
if (emulate_dpad) {
|
if (emulate_dpad) {
|
||||||
_dpad_y_axis = i;
|
_dpad_y_axis = i;
|
||||||
_dpad_up_button = (int)_buttons.size();
|
_dpad_up_button = (int)_buttons.size();
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
_buttons.push_back(ButtonState(GamepadButton::dpad_up()));
|
_buttons.push_back(ButtonState(GamepadButton::dpad_up()));
|
||||||
_buttons.push_back(ButtonState(GamepadButton::dpad_down()));
|
_buttons.push_back(ButtonState(GamepadButton::dpad_down()));
|
||||||
} else {
|
} else {
|
||||||
@ -633,18 +633,18 @@ init_device() {
|
|||||||
break;
|
break;
|
||||||
case ABS_HAT2X:
|
case ABS_HAT2X:
|
||||||
if (quirks & QB_steam_controller) {
|
if (quirks & QB_steam_controller) {
|
||||||
axis = InputDevice::Axis::right_trigger;
|
axis = Axis::RIGHT_TRIGGER;
|
||||||
have_analog_triggers = true;
|
have_analog_triggers = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_HAT2Y:
|
case ABS_HAT2Y:
|
||||||
if (quirks & QB_steam_controller) {
|
if (quirks & QB_steam_controller) {
|
||||||
axis = InputDevice::Axis::left_trigger;
|
axis = Axis::LEFT_TRIGGER;
|
||||||
have_analog_triggers = true;
|
have_analog_triggers = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ABS_PRESSURE:
|
case ABS_PRESSURE:
|
||||||
axis = InputDevice::Axis::pressure;
|
axis = Axis::PRESSURE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -655,13 +655,13 @@ 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 == Axis::yaw || axis == Axis::rudder || axis == Axis::left_y || axis == Axis::right_y ||
|
if (axis == Axis::YAW || axis == Axis::RUDDER || axis == Axis::LEFT_Y || axis == Axis::RIGHT_Y ||
|
||||||
(axis == Axis::throttle && (quirks & QB_reversed_throttle) != 0) ||
|
(axis == Axis::THROTTLE && (quirks & QB_reversed_throttle) != 0) ||
|
||||||
(_device_class == DeviceClass::spatial_mouse && (axis == Axis::y || axis == Axis::z || axis == Axis::roll)) ||
|
(_device_class == DeviceClass::SPATIAL_MOUSE && (axis == Axis::Y || axis == Axis::Z || axis == Axis::ROLL)) ||
|
||||||
(_device_class == DeviceClass::digitizer && axis == Axis::y)) {
|
(_device_class == DeviceClass::DIGITIZER && axis == Axis::Y)) {
|
||||||
std::swap(absinfo.maximum, absinfo.minimum);
|
std::swap(absinfo.maximum, absinfo.minimum);
|
||||||
}
|
}
|
||||||
if (axis == Axis::throttle && (quirks & QB_centered_throttle) != 0) {
|
if (axis == Axis::THROTTLE && (quirks & QB_centered_throttle) != 0) {
|
||||||
index = add_axis(axis, absinfo.minimum, absinfo.maximum, true);
|
index = add_axis(axis, absinfo.minimum, absinfo.maximum, true);
|
||||||
} else {
|
} else {
|
||||||
index = add_axis(axis, absinfo.minimum, absinfo.maximum);
|
index = add_axis(axis, absinfo.minimum, absinfo.maximum);
|
||||||
@ -678,8 +678,8 @@ init_device() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (test_bit(EV_REL, evtypes)) {
|
if (test_bit(EV_REL, evtypes)) {
|
||||||
enable_feature(Feature::pointer);
|
enable_feature(Feature::POINTER);
|
||||||
add_pointer(PointerType::unknown, 0);
|
add_pointer(PointerType::UNKNOWN, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test_bit(EV_FF, evtypes)) {
|
if (test_bit(EV_FF, evtypes)) {
|
||||||
@ -688,7 +688,7 @@ init_device() {
|
|||||||
|
|
||||||
if (test_bit(FF_RUMBLE, effects)) {
|
if (test_bit(FF_RUMBLE, effects)) {
|
||||||
if (_can_write) {
|
if (_can_write) {
|
||||||
enable_feature(Feature::vibration);
|
enable_feature(Feature::VIBRATION);
|
||||||
} else {
|
} else {
|
||||||
// Let the user know what he's missing out on.
|
// Let the user know what he's missing out on.
|
||||||
device_cat.warning()
|
device_cat.warning()
|
||||||
@ -701,8 +701,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_axis = (int)_axes.size();
|
_ltrigger_axis = (int)_axes.size();
|
||||||
add_axis(Axis::left_trigger, 0, 1, false);
|
add_axis(Axis::LEFT_TRIGGER, 0, 1, false);
|
||||||
add_axis(Axis::right_trigger, 0, 1, false);
|
add_axis(Axis::RIGHT_TRIGGER, 0, 1, false);
|
||||||
} else {
|
} else {
|
||||||
_ltrigger_code = -1;
|
_ltrigger_code = -1;
|
||||||
_rtrigger_code = -1;
|
_rtrigger_code = -1;
|
||||||
@ -1033,7 +1033,7 @@ map_button(int code, DeviceClass device_class, int quirks) {
|
|||||||
// BTN_THUMB and BTN_THUMB2 detect touching the touchpads.
|
// BTN_THUMB and BTN_THUMB2 detect touching the touchpads.
|
||||||
return ButtonHandle::none();
|
return ButtonHandle::none();
|
||||||
|
|
||||||
} else if (device_class == DeviceClass::gamepad &&
|
} else if (device_class == DeviceClass::GAMEPAD &&
|
||||||
(quirks & QB_alt_button_mapping) != 0) {
|
(quirks & QB_alt_button_mapping) != 0) {
|
||||||
static const ButtonHandle mapping[] = {
|
static const ButtonHandle mapping[] = {
|
||||||
GamepadButton::face_y(),
|
GamepadButton::face_y(),
|
||||||
@ -1053,7 +1053,7 @@ map_button(int code, DeviceClass device_class, int quirks) {
|
|||||||
return mapping[code & 0xf];
|
return mapping[code & 0xf];
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (device_class == DeviceClass::gamepad) {
|
} else if (device_class == DeviceClass::GAMEPAD) {
|
||||||
// Based on "Jess Tech Colour Rumble Pad"
|
// Based on "Jess Tech Colour Rumble Pad"
|
||||||
static const ButtonHandle mapping[] = {
|
static const ButtonHandle mapping[] = {
|
||||||
GamepadButton::face_x(),
|
GamepadButton::face_x(),
|
||||||
|
@ -70,7 +70,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static ButtonHandle map_button(int code,
|
static ButtonHandle map_button(int code,
|
||||||
DeviceClass device_class = DeviceClass::unknown,
|
DeviceClass device_class = DeviceClass::UNKNOWN,
|
||||||
int quirks = 0);
|
int quirks = 0);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -105,7 +105,7 @@ has_feature(Feature feature) const {
|
|||||||
*/
|
*/
|
||||||
INLINE bool InputDevice::
|
INLINE bool InputDevice::
|
||||||
has_pointer() const {
|
has_pointer() const {
|
||||||
return has_feature(Feature::pointer);
|
return has_feature(Feature::POINTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,7 +113,7 @@ has_pointer() const {
|
|||||||
*/
|
*/
|
||||||
INLINE bool InputDevice::
|
INLINE bool InputDevice::
|
||||||
has_keyboard() const {
|
has_keyboard() const {
|
||||||
return has_feature(Feature::keyboard);
|
return has_feature(Feature::KEYBOARD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,7 +122,7 @@ has_keyboard() const {
|
|||||||
*/
|
*/
|
||||||
INLINE bool InputDevice::
|
INLINE bool InputDevice::
|
||||||
has_tracker() const {
|
has_tracker() const {
|
||||||
return has_feature(Feature::tracker);
|
return has_feature(Feature::TRACKER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,7 +131,7 @@ has_tracker() const {
|
|||||||
*/
|
*/
|
||||||
INLINE bool InputDevice::
|
INLINE bool InputDevice::
|
||||||
has_vibration() const {
|
has_vibration() const {
|
||||||
return has_feature(Feature::vibration);
|
return has_feature(Feature::VIBRATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,7 +140,7 @@ has_vibration() const {
|
|||||||
*/
|
*/
|
||||||
INLINE bool InputDevice::
|
INLINE bool InputDevice::
|
||||||
has_battery() const {
|
has_battery() const {
|
||||||
return has_feature(Feature::battery);
|
return has_feature(Feature::BATTERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,7 +270,7 @@ get_num_axes() const {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Associates the indicated Axis with the axis of the indicated index
|
* Associates the indicated Axis with the axis of the indicated index
|
||||||
* number. Pass Axis::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 axes by index number.
|
* the various axes by index number.
|
||||||
|
@ -134,18 +134,18 @@ add_axis(Axis axis, int minimum, int maximum, bool centered) {
|
|||||||
int InputDevice::
|
int InputDevice::
|
||||||
add_axis(Axis axis, int minimum, int maximum) {
|
add_axis(Axis axis, int minimum, int maximum) {
|
||||||
bool centered = (minimum < 0)
|
bool centered = (minimum < 0)
|
||||||
|| axis == Axis::x
|
|| axis == Axis::X
|
||||||
|| axis == Axis::y
|
|| axis == Axis::Y
|
||||||
|| axis == Axis::z
|
|| axis == Axis::Z
|
||||||
|| axis == Axis::yaw
|
|| axis == Axis::YAW
|
||||||
|| axis == Axis::pitch
|
|| axis == Axis::PITCH
|
||||||
|| axis == Axis::roll
|
|| axis == Axis::ROLL
|
||||||
|| axis == Axis::left_x
|
|| axis == Axis::LEFT_X
|
||||||
|| axis == Axis::left_y
|
|| axis == Axis::LEFT_Y
|
||||||
|| axis == Axis::right_x
|
|| axis == Axis::RIGHT_X
|
||||||
|| axis == Axis::right_y
|
|| axis == Axis::RIGHT_Y
|
||||||
|| axis == Axis::wheel
|
|| axis == Axis::WHEEL
|
||||||
|| axis == Axis::rudder;
|
|| axis == Axis::RUDDER;
|
||||||
return add_axis(axis, minimum, maximum, centered);
|
return add_axis(axis, minimum, maximum, centered);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,7 +321,7 @@ set_axis_value(int index, double value) {
|
|||||||
device_cat.spam()
|
device_cat.spam()
|
||||||
<< "Changed axis " << index;
|
<< "Changed axis " << index;
|
||||||
|
|
||||||
if (_axes[index].axis != Axis::none) {
|
if (_axes[index].axis != Axis::NONE) {
|
||||||
device_cat.spam(false) << " (" << _axes[index].axis << ")";
|
device_cat.spam(false) << " (" << _axes[index].axis << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ axis_changed(int index, int state) {
|
|||||||
device_cat.spam()
|
device_cat.spam()
|
||||||
<< "Changed axis " << index;
|
<< "Changed axis " << index;
|
||||||
|
|
||||||
if (_axes[index].axis != Axis::none) {
|
if (_axes[index].axis != Axis::NONE) {
|
||||||
device_cat.spam(false) << " (" << _axes[index].axis << ")";
|
device_cat.spam(false) << " (" << _axes[index].axis << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ output(std::ostream &out) const {
|
|||||||
|
|
||||||
out << "connected)";
|
out << "connected)";
|
||||||
|
|
||||||
if (_device_class != DeviceClass::unknown) {
|
if (_device_class != DeviceClass::UNKNOWN) {
|
||||||
out << ", " << _device_class;
|
out << ", " << _device_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,19 +404,19 @@ output(std::ostream &out) const {
|
|||||||
<< (_axes.size() != 1 ? 'e' : 'i') << 's';
|
<< (_axes.size() != 1 ? 'e' : 'i') << 's';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_features & (1 << (unsigned int)Feature::pointer)) {
|
if (_features & (1 << (unsigned int)Feature::POINTER)) {
|
||||||
out << ", pointer";
|
out << ", pointer";
|
||||||
}
|
}
|
||||||
if (_features & (1 << (unsigned int)Feature::keyboard)) {
|
if (_features & (1 << (unsigned int)Feature::KEYBOARD)) {
|
||||||
out << ", keyboard";
|
out << ", keyboard";
|
||||||
}
|
}
|
||||||
if (_features & (1 << (unsigned int)Feature::tracker)) {
|
if (_features & (1 << (unsigned int)Feature::TRACKER)) {
|
||||||
out << ", tracker";
|
out << ", tracker";
|
||||||
}
|
}
|
||||||
if (_features & (1 << (unsigned int)Feature::vibration)) {
|
if (_features & (1 << (unsigned int)Feature::VIBRATION)) {
|
||||||
out << ", vibration";
|
out << ", vibration";
|
||||||
}
|
}
|
||||||
if (_features & (1 << (unsigned int)Feature::battery)) {
|
if (_features & (1 << (unsigned int)Feature::BATTERY)) {
|
||||||
out << ", battery";
|
out << ", battery";
|
||||||
|
|
||||||
if (_battery_data.level > 0 && _battery_data.max_level > 0) {
|
if (_battery_data.level > 0 && _battery_data.max_level > 0) {
|
||||||
@ -546,40 +546,40 @@ do_poll() {
|
|||||||
std::string InputDevice::
|
std::string InputDevice::
|
||||||
format_device_class(DeviceClass dc) {
|
format_device_class(DeviceClass dc) {
|
||||||
switch (dc) {
|
switch (dc) {
|
||||||
case InputDevice::DeviceClass::unknown:
|
case InputDevice::DeviceClass::UNKNOWN:
|
||||||
return "unknown";
|
return "unknown";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::virtual_device:
|
case InputDevice::DeviceClass::VIRTUAL:
|
||||||
return "virtual_device";
|
return "virtual";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::keyboard:
|
case InputDevice::DeviceClass::KEYBOARD:
|
||||||
return "keyboard";
|
return "keyboard";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::mouse:
|
case InputDevice::DeviceClass::MOUSE:
|
||||||
return "mouse";
|
return "mouse";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::touch:
|
case InputDevice::DeviceClass::TOUCH:
|
||||||
return "touch";
|
return "touch";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::gamepad:
|
case InputDevice::DeviceClass::GAMEPAD:
|
||||||
return "gamepad";
|
return "gamepad";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::flight_stick:
|
case InputDevice::DeviceClass::FLIGHT_STICK:
|
||||||
return "flight_stick";
|
return "flight_stick";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::steering_wheel:
|
case InputDevice::DeviceClass::STEERING_WHEEL:
|
||||||
return "steering_wheel";
|
return "steering_wheel";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::dance_pad:
|
case InputDevice::DeviceClass::DANCE_PAD:
|
||||||
return "dance_pad";
|
return "dance_pad";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::hmd:
|
case InputDevice::DeviceClass::HMD:
|
||||||
return "hmd";
|
return "hmd";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::spatial_mouse:
|
case InputDevice::DeviceClass::SPATIAL_MOUSE:
|
||||||
return "spatial_mouse";
|
return "spatial_mouse";
|
||||||
|
|
||||||
case InputDevice::DeviceClass::digitizer:
|
case InputDevice::DeviceClass::DIGITIZER:
|
||||||
return "digitizer";
|
return "digitizer";
|
||||||
}
|
}
|
||||||
return "**invalid**";
|
return "**invalid**";
|
||||||
@ -591,64 +591,64 @@ format_device_class(DeviceClass dc) {
|
|||||||
std::string InputDevice::
|
std::string InputDevice::
|
||||||
format_axis(Axis axis) {
|
format_axis(Axis axis) {
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
case InputDevice::Axis::none:
|
case Axis::NONE:
|
||||||
return "none";
|
return "none";
|
||||||
|
|
||||||
case InputDevice::Axis::x:
|
case Axis::X:
|
||||||
return "x";
|
return "x";
|
||||||
|
|
||||||
case InputDevice::Axis::y:
|
case Axis::Y:
|
||||||
return "y";
|
return "y";
|
||||||
|
|
||||||
case InputDevice::Axis::z:
|
case Axis::Z:
|
||||||
return "z";
|
return "z";
|
||||||
|
|
||||||
case InputDevice::Axis::yaw:
|
case Axis::YAW:
|
||||||
return "yaw";
|
return "yaw";
|
||||||
|
|
||||||
case InputDevice::Axis::pitch:
|
case Axis::PITCH:
|
||||||
return "pitch";
|
return "pitch";
|
||||||
|
|
||||||
case InputDevice::Axis::roll:
|
case Axis::ROLL:
|
||||||
return "roll";
|
return "roll";
|
||||||
|
|
||||||
case InputDevice::Axis::left_x:
|
case Axis::LEFT_X:
|
||||||
return "left_x";
|
return "left_x";
|
||||||
|
|
||||||
case InputDevice::Axis::left_y:
|
case Axis::LEFT_Y:
|
||||||
return "left_y";
|
return "left_y";
|
||||||
|
|
||||||
case InputDevice::Axis::left_trigger:
|
case Axis::LEFT_TRIGGER:
|
||||||
return "left_trigger";
|
return "left_trigger";
|
||||||
|
|
||||||
case InputDevice::Axis::right_x:
|
case Axis::RIGHT_X:
|
||||||
return "right_x";
|
return "right_x";
|
||||||
|
|
||||||
case InputDevice::Axis::right_y:
|
case Axis::RIGHT_Y:
|
||||||
return "right_y";
|
return "right_y";
|
||||||
|
|
||||||
case InputDevice::Axis::right_trigger:
|
case Axis::RIGHT_TRIGGER:
|
||||||
return "right_trigger";
|
return "right_trigger";
|
||||||
|
|
||||||
//case InputDevice::Axis::trigger:
|
//case Axis::TRIGGER:
|
||||||
// return "trigger";
|
// return "trigger";
|
||||||
|
|
||||||
case InputDevice::Axis::throttle:
|
case Axis::THROTTLE:
|
||||||
return "throttle";
|
return "throttle";
|
||||||
|
|
||||||
case InputDevice::Axis::rudder:
|
case Axis::RUDDER:
|
||||||
return "rudder";
|
return "rudder";
|
||||||
|
|
||||||
case InputDevice::Axis::wheel:
|
case Axis::WHEEL:
|
||||||
return "wheel";
|
return "wheel";
|
||||||
|
|
||||||
case InputDevice::Axis::accelerator:
|
case Axis::ACCELERATOR:
|
||||||
return "accelerator";
|
return "accelerator";
|
||||||
|
|
||||||
case InputDevice::Axis::brake:
|
case Axis::BRAKE:
|
||||||
return "brake";
|
return "brake";
|
||||||
|
|
||||||
case InputDevice::Axis::pressure:
|
case Axis::PRESSURE:
|
||||||
return "pressure";
|
return "pressure";
|
||||||
}
|
}
|
||||||
return "**invalid**";
|
return "**invalid**";
|
||||||
|
@ -56,84 +56,126 @@ PUBLISHED:
|
|||||||
// type of input device.
|
// type of input device.
|
||||||
enum class DeviceClass {
|
enum class DeviceClass {
|
||||||
// It is not known what type of device this is.
|
// It is not known what type of device this is.
|
||||||
unknown,
|
UNKNOWN,
|
||||||
|
|
||||||
// This means that the device doesn't correspond to a physical
|
// This means that the device doesn't correspond to a physical
|
||||||
// device, but rather to a dynamic source of input events.
|
// device, but rather to a dynamic source of input events.
|
||||||
virtual_device,
|
VIRTUAL,
|
||||||
|
|
||||||
// A physical, alphabetical keyboard.
|
// A physical, alphabetical keyboard.
|
||||||
keyboard,
|
KEYBOARD,
|
||||||
|
|
||||||
mouse,
|
MOUSE,
|
||||||
touch,
|
TOUCH,
|
||||||
|
|
||||||
// A gamepad with action buttons, a D-pad, and thumbsticks.
|
// A gamepad with action buttons, a D-pad, and thumbsticks.
|
||||||
gamepad,
|
GAMEPAD,
|
||||||
|
|
||||||
flight_stick,
|
FLIGHT_STICK,
|
||||||
steering_wheel,
|
STEERING_WHEEL,
|
||||||
dance_pad,
|
DANCE_PAD,
|
||||||
|
|
||||||
// Head-mounted display.
|
// Head-mounted display.
|
||||||
hmd,
|
HMD,
|
||||||
|
|
||||||
// 3D mouse, such as produced by 3Dconnexion.
|
// 3D mouse, such as produced by 3Dconnexion.
|
||||||
spatial_mouse,
|
SPATIAL_MOUSE,
|
||||||
|
|
||||||
// A graphics tablet with stylus/pen.
|
// A graphics tablet with stylus/pen.
|
||||||
digitizer,
|
DIGITIZER,
|
||||||
|
|
||||||
|
// Deprecated aliases.
|
||||||
|
unknown = UNKNOWN,
|
||||||
|
virtual_device = VIRTUAL,
|
||||||
|
keyboard = KEYBOARD,
|
||||||
|
mouse = MOUSE,
|
||||||
|
touch = TOUCH,
|
||||||
|
gamepad = GAMEPAD,
|
||||||
|
flight_stick = FLIGHT_STICK,
|
||||||
|
steering_wheel = STEERING_WHEEL,
|
||||||
|
dance_pad = DANCE_PAD,
|
||||||
|
hmd = HMD,
|
||||||
|
spatial_mouse = SPATIAL_MOUSE,
|
||||||
|
digitizer = DIGITIZER,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Feature {
|
enum class Feature {
|
||||||
// The device provides absolute screen coordinates.
|
// The device provides absolute screen coordinates.
|
||||||
pointer,
|
POINTER,
|
||||||
|
|
||||||
// The device has an interface for providing text input.
|
// The device has an interface for providing text input.
|
||||||
keyboard,
|
KEYBOARD,
|
||||||
|
|
||||||
// The device has a motion tracker, such as an HMD.
|
// The device has a motion tracker, such as an HMD.
|
||||||
tracker,
|
TRACKER,
|
||||||
|
|
||||||
// The device can produce force feedback.
|
// The device can produce force feedback.
|
||||||
vibration,
|
VIBRATION,
|
||||||
|
|
||||||
// The device provides information about battery life.
|
// The device provides information about battery life.
|
||||||
battery,
|
BATTERY,
|
||||||
|
|
||||||
|
// Deprecated aliases.
|
||||||
|
pointer = POINTER,
|
||||||
|
keyboard = KEYBOARD,
|
||||||
|
tracker = TRACKER,
|
||||||
|
vibration = VIBRATION,
|
||||||
|
battery = BATTERY,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Axis {
|
enum class Axis {
|
||||||
none,
|
NONE,
|
||||||
|
|
||||||
// Generic translational axes
|
// Generic translational axes
|
||||||
x,
|
X,
|
||||||
y,
|
Y,
|
||||||
z,
|
Z,
|
||||||
|
|
||||||
// Generic rotational axes, used by joysticks and 3D mice
|
// Generic rotational axes, used by joysticks and 3D mice
|
||||||
yaw,
|
YAW,
|
||||||
pitch,
|
PITCH,
|
||||||
roll,
|
ROLL,
|
||||||
|
|
||||||
// Gamepad
|
// Gamepad
|
||||||
left_x,
|
LEFT_X,
|
||||||
left_y,
|
LEFT_Y,
|
||||||
left_trigger,
|
LEFT_TRIGGER,
|
||||||
right_x,
|
RIGHT_X,
|
||||||
right_y,
|
RIGHT_Y,
|
||||||
right_trigger,
|
RIGHT_TRIGGER,
|
||||||
|
|
||||||
// Flight stick specific
|
// Flight stick specific
|
||||||
throttle,
|
THROTTLE,
|
||||||
rudder, // When available separately from yaw
|
RUDDER, // When available separately from yaw
|
||||||
|
|
||||||
// Steering wheel / pedals
|
// Steering wheel / pedals
|
||||||
wheel,
|
WHEEL,
|
||||||
accelerator,
|
ACCELERATOR,
|
||||||
brake,
|
BRAKE,
|
||||||
|
|
||||||
// Pen pressure
|
// Pen pressure
|
||||||
pressure,
|
PRESSURE,
|
||||||
|
|
||||||
|
// Deprecated aliases
|
||||||
|
none = NONE,
|
||||||
|
x = X,
|
||||||
|
y = Y,
|
||||||
|
z = Z,
|
||||||
|
yaw = YAW,
|
||||||
|
pitch = PITCH,
|
||||||
|
roll = ROLL,
|
||||||
|
left_x = LEFT_X,
|
||||||
|
left_y = LEFT_Y,
|
||||||
|
left_trigger = LEFT_TRIGGER,
|
||||||
|
right_x = RIGHT_X,
|
||||||
|
right_y = RIGHT_Y,
|
||||||
|
right_trigger = RIGHT_TRIGGER,
|
||||||
|
throttle = THROTTLE,
|
||||||
|
rudder = RUDDER,
|
||||||
|
wheel = WHEEL,
|
||||||
|
accelerator = ACCELERATOR,
|
||||||
|
brake = BRAKE,
|
||||||
|
pressure = PRESSURE,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum State {
|
enum State {
|
||||||
@ -168,7 +210,7 @@ PUBLISHED:
|
|||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
operator bool() { return known && value != 0.0; }
|
operator bool() { return known && value != 0.0; }
|
||||||
|
|
||||||
Axis axis = Axis::none;
|
Axis axis = Axis::NONE;
|
||||||
double value = 0.0;
|
double value = 0.0;
|
||||||
bool known = false;
|
bool known = false;
|
||||||
|
|
||||||
@ -319,7 +361,7 @@ protected:
|
|||||||
std::string _name;
|
std::string _name;
|
||||||
std::string _serial_number;
|
std::string _serial_number;
|
||||||
std::string _manufacturer;
|
std::string _manufacturer;
|
||||||
DeviceClass _device_class = DeviceClass::unknown;
|
DeviceClass _device_class = DeviceClass::UNKNOWN;
|
||||||
unsigned int _features = 0;
|
unsigned int _features = 0;
|
||||||
int _event_sequence = 0;
|
int _event_sequence = 0;
|
||||||
unsigned short _vendor_id = 0;
|
unsigned short _vendor_id = 0;
|
||||||
|
@ -80,19 +80,25 @@ IOKitInputDevice(IOHIDDeviceRef device) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (IOHIDDeviceConformsTo(device, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)) {
|
if (IOHIDDeviceConformsTo(device, kHIDPage_GenericDesktop, kHIDUsage_GD_Mouse)) {
|
||||||
_device_class = DeviceClass::mouse;
|
_device_class = DeviceClass::MOUSE;
|
||||||
} else if (IOHIDDeviceConformsTo(device, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)) {
|
}
|
||||||
_device_class = DeviceClass::keyboard;
|
else if (IOHIDDeviceConformsTo(device, kHIDPage_GenericDesktop, kHIDUsage_GD_Keyboard)) {
|
||||||
} else if (IOHIDDeviceConformsTo(device, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad)) {
|
_device_class = DeviceClass::KEYBOARD;
|
||||||
_device_class = DeviceClass::gamepad;
|
}
|
||||||
} else if (IOHIDDeviceConformsTo(device, kHIDPage_Simulation, kHIDUsage_Sim_FlightStick)) {
|
else if (IOHIDDeviceConformsTo(device, kHIDPage_GenericDesktop, kHIDUsage_GD_GamePad)) {
|
||||||
_device_class = DeviceClass::flight_stick;
|
_device_class = DeviceClass::GAMEPAD;
|
||||||
} else if (IOHIDDeviceConformsTo(device, kHIDPage_Simulation, kHIDUsage_GD_Joystick)) {
|
}
|
||||||
_device_class = DeviceClass::flight_stick;
|
else if (IOHIDDeviceConformsTo(device, kHIDPage_Simulation, kHIDUsage_Sim_FlightStick)) {
|
||||||
} else if (_vendor_id == 0x044f && _product_id == 0xb108) {
|
_device_class = DeviceClass::FLIGHT_STICK;
|
||||||
|
}
|
||||||
|
else if (IOHIDDeviceConformsTo(device, kHIDPage_Simulation, kHIDUsage_GD_Joystick)) {
|
||||||
|
_device_class = DeviceClass::FLIGHT_STICK;
|
||||||
|
}
|
||||||
|
else if (_vendor_id == 0x044f && _product_id == 0xb108) {
|
||||||
// T.Flight Hotas X
|
// T.Flight Hotas X
|
||||||
_device_class = DeviceClass::flight_stick;
|
_device_class = DeviceClass::FLIGHT_STICK;
|
||||||
} else if (_vendor_id == 0x046d &&
|
}
|
||||||
|
else if (_vendor_id == 0x046d &&
|
||||||
(_product_id == 0xc623 ||
|
(_product_id == 0xc623 ||
|
||||||
_product_id == 0xc625 ||
|
_product_id == 0xc625 ||
|
||||||
_product_id == 0xc626 ||
|
_product_id == 0xc626 ||
|
||||||
@ -101,9 +107,10 @@ IOKitInputDevice(IOHIDDeviceRef device) :
|
|||||||
_product_id == 0xc629 ||
|
_product_id == 0xc629 ||
|
||||||
_product_id == 0xc62b)) {
|
_product_id == 0xc62b)) {
|
||||||
// 3Dconnexion SpaceNavigator and friends.
|
// 3Dconnexion SpaceNavigator and friends.
|
||||||
_device_class = DeviceClass::spatial_mouse;
|
_device_class = DeviceClass::SPATIAL_MOUSE;
|
||||||
} else if (_name == "usb gamepad") {
|
}
|
||||||
_device_class = DeviceClass::gamepad;
|
else if (_name == "usb gamepad") {
|
||||||
|
_device_class = DeviceClass::GAMEPAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device, nullptr, 0);
|
CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device, nullptr, 0);
|
||||||
@ -125,8 +132,8 @@ IOKitInputDevice(IOHIDDeviceRef device) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_pointer_x != nullptr && _pointer_y != nullptr) {
|
if (_pointer_x != nullptr && _pointer_y != nullptr) {
|
||||||
enable_feature(Feature::pointer);
|
enable_feature(Feature::POINTER);
|
||||||
add_pointer(PointerType::unknown, 0);
|
add_pointer(PointerType::UNKNOWN, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
_is_connected = true;
|
_is_connected = true;
|
||||||
@ -145,7 +152,7 @@ IOKitInputDevice::
|
|||||||
void IOKitInputDevice::
|
void IOKitInputDevice::
|
||||||
parse_element(IOHIDElementRef element) {
|
parse_element(IOHIDElementRef element) {
|
||||||
ButtonHandle handle = ButtonHandle::none();
|
ButtonHandle handle = ButtonHandle::none();
|
||||||
Axis axis = Axis::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);
|
||||||
|
|
||||||
@ -155,61 +162,61 @@ parse_element(IOHIDElementRef element) {
|
|||||||
case kHIDPage_GenericDesktop:
|
case kHIDPage_GenericDesktop:
|
||||||
switch (usage) {
|
switch (usage) {
|
||||||
case kHIDUsage_GD_X:
|
case kHIDUsage_GD_X:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::left_x;
|
axis = Axis::LEFT_X;
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = Axis::roll;
|
axis = Axis::ROLL;
|
||||||
} else if (_device_class == DeviceClass::mouse) {
|
} else if (_device_class == DeviceClass::MOUSE) {
|
||||||
_pointer_x = element;
|
_pointer_x = element;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::x;
|
axis = Axis::X;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_GD_Y:
|
case kHIDUsage_GD_Y:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::left_y;
|
axis = Axis::LEFT_Y;
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = Axis::pitch;
|
axis = Axis::PITCH;
|
||||||
} else if (_device_class == DeviceClass::mouse) {
|
} else if (_device_class == DeviceClass::MOUSE) {
|
||||||
_pointer_y = element;
|
_pointer_y = element;
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::y;
|
axis = Axis::Y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_GD_Z:
|
case kHIDUsage_GD_Z:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::left_trigger;
|
axis = Axis::LEFT_TRIGGER;
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = Axis::throttle;
|
axis = Axis::THROTTLE;
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::z;
|
axis = Axis::Z;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_GD_Rx:
|
case kHIDUsage_GD_Rx:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::right_x;
|
axis = Axis::RIGHT_X;
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::pitch;
|
axis = Axis::PITCH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_GD_Ry:
|
case kHIDUsage_GD_Ry:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::right_y;
|
axis = Axis::RIGHT_Y;
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::roll;
|
axis = Axis::ROLL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_GD_Rz:
|
case kHIDUsage_GD_Rz:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::right_trigger;
|
axis = Axis::RIGHT_TRIGGER;
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::yaw;
|
axis = Axis::YAW;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_GD_Slider:
|
case kHIDUsage_GD_Slider:
|
||||||
axis = Axis::rudder;
|
axis = Axis::RUDDER;
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_GD_Dial:
|
case kHIDUsage_GD_Dial:
|
||||||
break;
|
break;
|
||||||
@ -241,28 +248,28 @@ parse_element(IOHIDElementRef element) {
|
|||||||
case kHIDPage_Simulation:
|
case kHIDPage_Simulation:
|
||||||
switch (usage) {
|
switch (usage) {
|
||||||
case kHIDUsage_Sim_Rudder:
|
case kHIDUsage_Sim_Rudder:
|
||||||
axis = Axis::rudder;
|
axis = Axis::RUDDER;
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_Sim_Throttle:
|
case kHIDUsage_Sim_Throttle:
|
||||||
axis = Axis::throttle;
|
axis = Axis::THROTTLE;
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_Sim_Accelerator:
|
case kHIDUsage_Sim_Accelerator:
|
||||||
axis = Axis::accelerator;
|
axis = Axis::ACCELERATOR;
|
||||||
break;
|
break;
|
||||||
case kHIDUsage_Sim_Brake:
|
case kHIDUsage_Sim_Brake:
|
||||||
axis = Axis::brake;
|
axis = Axis::BRAKE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (axis != Axis::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 == Axis::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_axis(axis, max, min, true);
|
add_axis(axis, max, min, true);
|
||||||
} else if (axis == Axis::yaw || axis == Axis::rudder || axis == Axis::left_y || axis == Axis::right_y ||
|
} else if (axis == Axis::YAW || axis == Axis::RUDDER || axis == Axis::LEFT_Y || axis == Axis::RIGHT_Y ||
|
||||||
(_device_class == DeviceClass::spatial_mouse && (axis == Axis::y || axis == Axis::z || axis == Axis::roll))) {
|
(_device_class == DeviceClass::SPATIAL_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_axis(axis, max, min);
|
add_axis(axis, max, min);
|
||||||
@ -600,7 +607,7 @@ parse_element(IOHIDElementRef element) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case kHIDPage_Button:
|
case kHIDPage_Button:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if (_vendor_id == 0x0810 && _product_id == 0xe501) {
|
if (_vendor_id == 0x0810 && _product_id == 0xe501) {
|
||||||
// SNES-style USB gamepad
|
// SNES-style USB gamepad
|
||||||
static const ButtonHandle gamepad_buttons[] = {
|
static const ButtonHandle gamepad_buttons[] = {
|
||||||
@ -644,11 +651,11 @@ parse_element(IOHIDElementRef element) {
|
|||||||
handle = gamepad_buttons[usage];
|
handle = gamepad_buttons[usage];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
if (usage > 0) {
|
if (usage > 0) {
|
||||||
handle = GamepadButton::joystick(usage - 1);
|
handle = GamepadButton::joystick(usage - 1);
|
||||||
}
|
}
|
||||||
} else if (_device_class == DeviceClass::mouse) {
|
} else if (_device_class == DeviceClass::MOUSE) {
|
||||||
// In Panda, wheel and right button are flipped around...
|
// In Panda, wheel and right button are flipped around...
|
||||||
int button = (usage == 2 || usage == 3) ? (4 - usage) : (usage - 1);
|
int button = (usage == 2 || usage == 3) ? (4 - usage) : (usage - 1);
|
||||||
handle = MouseButton::button(button);
|
handle = MouseButton::button(button);
|
||||||
|
@ -136,9 +136,9 @@ open_device() {
|
|||||||
<< " button " << (int)i << ": 0x" << std::hex << btnmap[i] << "\n";
|
<< " button " << (int)i << ": 0x" << std::hex << btnmap[i] << "\n";
|
||||||
}
|
}
|
||||||
} else if (handle == GamepadButton::face_a()) {
|
} else if (handle == GamepadButton::face_a()) {
|
||||||
_device_class = DeviceClass::gamepad;
|
_device_class = DeviceClass::GAMEPAD;
|
||||||
} else if (handle == GamepadButton::trigger()) {
|
} else if (handle == GamepadButton::trigger()) {
|
||||||
_device_class = DeviceClass::flight_stick;
|
_device_class = DeviceClass::FLIGHT_STICK;
|
||||||
} else if (handle == GamepadButton::dpad_left()) {
|
} else if (handle == GamepadButton::dpad_left()) {
|
||||||
emulate_dpad = false;
|
emulate_dpad = false;
|
||||||
} else if (handle == GamepadButton::ltrigger()) {
|
} else if (handle == GamepadButton::ltrigger()) {
|
||||||
@ -155,71 +155,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) {
|
||||||
Axis axis = Axis::none;
|
Axis axis = Axis::NONE;
|
||||||
|
|
||||||
switch (axmap[i]) {
|
switch (axmap[i]) {
|
||||||
case ABS_X:
|
case ABS_X:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = InputDevice::Axis::left_x;
|
axis = Axis::LEFT_X;
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = InputDevice::Axis::roll;
|
axis = Axis::ROLL;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::x;
|
axis = Axis::X;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_Y:
|
case ABS_Y:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = InputDevice::Axis::left_y;
|
axis = Axis::LEFT_Y;
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = InputDevice::Axis::pitch;
|
axis = Axis::PITCH;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::y;
|
axis = Axis::Y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_Z:
|
case ABS_Z:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::left_trigger;
|
axis = Axis::LEFT_TRIGGER;
|
||||||
} else {
|
} else {
|
||||||
//axis = Axis::trigger;
|
//axis = Axis::TRIGGER;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_RX:
|
case ABS_RX:
|
||||||
axis = Axis::right_x;
|
axis = Axis::RIGHT_X;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_RY:
|
case ABS_RY:
|
||||||
axis = Axis::right_y;
|
axis = Axis::RIGHT_Y;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_RZ:
|
case ABS_RZ:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = InputDevice::Axis::right_trigger;
|
axis = Axis::RIGHT_TRIGGER;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::yaw;
|
axis = Axis::YAW;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_THROTTLE:
|
case ABS_THROTTLE:
|
||||||
axis = InputDevice::Axis::throttle;
|
axis = Axis::THROTTLE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_RUDDER:
|
case ABS_RUDDER:
|
||||||
axis = InputDevice::Axis::rudder;
|
axis = Axis::RUDDER;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_WHEEL:
|
case ABS_WHEEL:
|
||||||
axis = InputDevice::Axis::wheel;
|
axis = Axis::WHEEL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_GAS:
|
case ABS_GAS:
|
||||||
axis = InputDevice::Axis::accelerator;
|
axis = Axis::ACCELERATOR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_BRAKE:
|
case ABS_BRAKE:
|
||||||
axis = InputDevice::Axis::brake;
|
axis = Axis::BRAKE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_HAT0X:
|
case ABS_HAT0X:
|
||||||
@ -227,7 +227,7 @@ open_device() {
|
|||||||
// Emulate D-Pad or hat switch.
|
// Emulate D-Pad or hat switch.
|
||||||
_dpad_x_axis = i;
|
_dpad_x_axis = i;
|
||||||
_dpad_left_button = (int)_buttons.size();
|
_dpad_left_button = (int)_buttons.size();
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
add_button(GamepadButton::dpad_left());
|
add_button(GamepadButton::dpad_left());
|
||||||
add_button(GamepadButton::dpad_right());
|
add_button(GamepadButton::dpad_right());
|
||||||
} else {
|
} else {
|
||||||
@ -236,7 +236,7 @@ open_device() {
|
|||||||
}
|
}
|
||||||
_buttons[_dpad_left_button]._state = S_up;
|
_buttons[_dpad_left_button]._state = S_up;
|
||||||
_buttons[_dpad_left_button+1]._state = S_up;
|
_buttons[_dpad_left_button+1]._state = S_up;
|
||||||
axis = Axis::none;
|
axis = Axis::NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ open_device() {
|
|||||||
// Emulate D-Pad.
|
// Emulate D-Pad.
|
||||||
_dpad_y_axis = i;
|
_dpad_y_axis = i;
|
||||||
_dpad_up_button = (int)_buttons.size();
|
_dpad_up_button = (int)_buttons.size();
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
add_button(GamepadButton::dpad_up());
|
add_button(GamepadButton::dpad_up());
|
||||||
add_button(GamepadButton::dpad_down());
|
add_button(GamepadButton::dpad_down());
|
||||||
} else {
|
} else {
|
||||||
@ -254,19 +254,19 @@ open_device() {
|
|||||||
}
|
}
|
||||||
_buttons[_dpad_up_button]._state = S_up;
|
_buttons[_dpad_up_button]._state = S_up;
|
||||||
_buttons[_dpad_up_button+1]._state = S_up;
|
_buttons[_dpad_up_button+1]._state = S_up;
|
||||||
axis = Axis::none;
|
axis = Axis::NONE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_HAT2X:
|
case ABS_HAT2X:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = InputDevice::Axis::right_trigger;
|
axis = Axis::RIGHT_TRIGGER;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ABS_HAT2Y:
|
case ABS_HAT2Y:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = InputDevice::Axis::left_trigger;
|
axis = Axis::LEFT_TRIGGER;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -275,17 +275,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 = Axis::none;
|
axis = Axis::NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_axes[i].axis = axis;
|
_axes[i].axis = axis;
|
||||||
|
|
||||||
if (axis == Axis::left_trigger || axis == Axis::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.
|
||||||
_axes[i]._scale = 1.0 / 65534.0;
|
_axes[i]._scale = 1.0 / 65534.0;
|
||||||
_axes[i]._bias = 0.5;
|
_axes[i]._bias = 0.5;
|
||||||
have_analog_triggers = true;
|
have_analog_triggers = true;
|
||||||
} else if (axis == Axis::left_y || axis == Axis::right_y || axis == Axis::y) {
|
} else if (axis == Axis::LEFT_Y || axis == Axis::RIGHT_Y || axis == Axis::Y) {
|
||||||
_axes[i]._scale = 1.0 / -32767.0;
|
_axes[i]._scale = 1.0 / -32767.0;
|
||||||
_axes[i]._bias = 0.0;
|
_axes[i]._bias = 0.0;
|
||||||
} else {
|
} else {
|
||||||
@ -298,8 +298,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_axis = (int)_axes.size();
|
_ltrigger_axis = (int)_axes.size();
|
||||||
add_axis(Axis::left_trigger, 0, 1, false);
|
add_axis(Axis::LEFT_TRIGGER, 0, 1, false);
|
||||||
add_axis(Axis::right_trigger, 0, 1, false);
|
add_axis(Axis::RIGHT_TRIGGER, 0, 1, false);
|
||||||
} else {
|
} else {
|
||||||
_ltrigger_button = -1;
|
_ltrigger_button = -1;
|
||||||
_rtrigger_button = -1;
|
_rtrigger_button = -1;
|
||||||
|
@ -50,43 +50,43 @@ static const struct DeviceMapping {
|
|||||||
} mapping_presets[] = {
|
} mapping_presets[] = {
|
||||||
// SNES-style USB gamepad, or cheap unbranded USB gamepad with no sticks
|
// SNES-style USB gamepad, or cheap unbranded USB gamepad with no sticks
|
||||||
// ABXY are mapped based on their position, not based on their label.
|
// ABXY are mapped based on their position, not based on their label.
|
||||||
{0x0810, 0xe501, InputDevice::DeviceClass::gamepad, QB_no_analog_triggers,
|
{0x0810, 0xe501, InputDevice::DeviceClass::GAMEPAD, QB_no_analog_triggers,
|
||||||
{"face_y", "face_b", "face_a", "face_x", "lshoulder", "rshoulder", "ltrigger", "rtrigger", "back", "start"}
|
{"face_y", "face_b", "face_a", "face_x", "lshoulder", "rshoulder", "ltrigger", "rtrigger", "back", "start"}
|
||||||
},
|
},
|
||||||
// Unbranded generic cheap USB gamepad
|
// Unbranded generic cheap USB gamepad
|
||||||
{0x0810, 0x0001, InputDevice::DeviceClass::gamepad, QB_rstick_from_z | QB_no_analog_triggers | QB_right_axes_swapped,
|
{0x0810, 0x0001, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z | QB_no_analog_triggers | QB_right_axes_swapped,
|
||||||
{"face_y", "face_b", "face_a", "face_x", "lshoulder", "rshoulder", "ltrigger", "rtrigger", "back", "start", "lstick", "rstick"}
|
{"face_y", "face_b", "face_a", "face_x", "lshoulder", "rshoulder", "ltrigger", "rtrigger", "back", "start", "lstick", "rstick"}
|
||||||
},
|
},
|
||||||
// Trust GXT 24 / SPEED Link SL-6535-SBK-01
|
// Trust GXT 24 / SPEED Link SL-6535-SBK-01
|
||||||
{0x0079, 0x0006, InputDevice::DeviceClass::gamepad, QB_rstick_from_z | QB_no_analog_triggers,
|
{0x0079, 0x0006, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z | QB_no_analog_triggers,
|
||||||
{"face_y", "face_b", "face_a", "face_x", "lshoulder", "rshoulder", "ltrigger", "rtrigger", "back", "start", "lstick", "rstick"}
|
{"face_y", "face_b", "face_a", "face_x", "lshoulder", "rshoulder", "ltrigger", "rtrigger", "back", "start", "lstick", "rstick"}
|
||||||
},
|
},
|
||||||
// T.Flight Hotas X
|
// T.Flight Hotas X
|
||||||
{0x044f, 0xb108, InputDevice::DeviceClass::flight_stick, QB_centered_throttle | QB_reversed_throttle,
|
{0x044f, 0xb108, InputDevice::DeviceClass::FLIGHT_STICK, QB_centered_throttle | QB_reversed_throttle,
|
||||||
{0}
|
{0}
|
||||||
},
|
},
|
||||||
// NVIDIA Shield Controller
|
// NVIDIA Shield Controller
|
||||||
{0x0955, 0x7214, InputDevice::DeviceClass::gamepad, 0,
|
{0x0955, 0x7214, InputDevice::DeviceClass::GAMEPAD, 0,
|
||||||
{"face_a", "face_b", 0, "face_x", "face_y", "rshoulder", "lshoulder", "rshoulder", 0, 0, 0, "start", 0, "lstick", "rstick", 0}
|
{"face_a", "face_b", 0, "face_x", "face_y", "rshoulder", "lshoulder", "rshoulder", 0, 0, 0, "start", 0, "lstick", "rstick", 0}
|
||||||
},
|
},
|
||||||
// Dualshock (PS4)
|
// Dualshock (PS4)
|
||||||
{0x054c, 0x05c4, InputDevice::DeviceClass::gamepad, QB_rstick_from_z,
|
{0x054c, 0x05c4, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z,
|
||||||
{"face_x", "face_a", "face_b", "face_y", "lshoulder", "rshoulder", 0, 0, "back", "start", "lstick", "rstick", "guide", 0}
|
{"face_x", "face_a", "face_b", "face_y", "lshoulder", "rshoulder", 0, 0, "back", "start", "lstick", "rstick", "guide", 0}
|
||||||
},
|
},
|
||||||
// Dualshock 2nd Gen (PS4 Slim)
|
// Dualshock 2nd Gen (PS4 Slim)
|
||||||
{0x054c, 0x09cc, InputDevice::DeviceClass::gamepad, QB_rstick_from_z,
|
{0x054c, 0x09cc, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z,
|
||||||
{"face_x", "face_a", "face_b", "face_y", "lshoulder", "rshoulder", 0, 0, "back", "start", "lstick", "rstick", "guide", 0}
|
{"face_x", "face_a", "face_b", "face_y", "lshoulder", "rshoulder", 0, 0, "back", "start", "lstick", "rstick", "guide", 0}
|
||||||
},
|
},
|
||||||
// Dualshock 2nd Gen (PS4 wireless adapter)
|
// Dualshock 2nd Gen (PS4 wireless adapter)
|
||||||
{0x054c, 0x0ba0, InputDevice::DeviceClass::gamepad, QB_rstick_from_z,
|
{0x054c, 0x0ba0, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z,
|
||||||
{"face_x", "face_a", "face_b", "face_y", "lshoulder", "rshoulder", 0, 0, "back", "start", "lstick", "rstick", "guide", 0}
|
{"face_x", "face_a", "face_b", "face_y", "lshoulder", "rshoulder", 0, 0, "back", "start", "lstick", "rstick", "guide", 0}
|
||||||
},
|
},
|
||||||
// PS2 controller connected through a USB adapter
|
// PS2 controller connected through a USB adapter
|
||||||
{0x2563, 0x0523, InputDevice::DeviceClass::gamepad, QB_rstick_from_z | QB_no_analog_triggers,
|
{0x2563, 0x0523, InputDevice::DeviceClass::GAMEPAD, QB_rstick_from_z | QB_no_analog_triggers,
|
||||||
{"face_y", "face_b", "face_a", "face_x", "lshoulder", "rshoulder", "ltrigger", "rtrigger", "back", "start", "lstick", "rstick"}
|
{"face_y", "face_b", "face_a", "face_x", "lshoulder", "rshoulder", "ltrigger", "rtrigger", "back", "start", "lstick", "rstick"}
|
||||||
},
|
},
|
||||||
// FrSky Simulator
|
// FrSky Simulator
|
||||||
{0x0483, 0x5720, InputDevice::DeviceClass::flight_stick, 0,
|
{0x0483, 0x5720, InputDevice::DeviceClass::FLIGHT_STICK, 0,
|
||||||
{0}
|
{0}
|
||||||
},
|
},
|
||||||
{0},
|
{0},
|
||||||
@ -183,11 +183,11 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
|
|
||||||
switch (info.dwType) {
|
switch (info.dwType) {
|
||||||
case RIM_TYPEMOUSE:
|
case RIM_TYPEMOUSE:
|
||||||
_device_class = DeviceClass::mouse;
|
_device_class = DeviceClass::MOUSE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RIM_TYPEKEYBOARD:
|
case RIM_TYPEKEYBOARD:
|
||||||
_device_class = DeviceClass::keyboard;
|
_device_class = DeviceClass::KEYBOARD;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RIM_TYPEHID:
|
case RIM_TYPEHID:
|
||||||
@ -197,32 +197,32 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
// Gamepads
|
// Gamepads
|
||||||
if (info.hid.usUsagePage == HID_USAGE_PAGE_GENERIC &&
|
if (info.hid.usUsagePage == HID_USAGE_PAGE_GENERIC &&
|
||||||
info.hid.usUsage == HID_USAGE_GENERIC_GAMEPAD) {
|
info.hid.usUsage == HID_USAGE_GENERIC_GAMEPAD) {
|
||||||
_device_class = DeviceClass::gamepad;
|
_device_class = DeviceClass::GAMEPAD;
|
||||||
|
|
||||||
// Various game controllers, incl. flight sticks and some gamepads
|
// Various game controllers, incl. flight sticks and some gamepads
|
||||||
} else if (info.hid.usUsagePage == HID_USAGE_PAGE_GENERIC &&
|
} else if (info.hid.usUsagePage == HID_USAGE_PAGE_GENERIC &&
|
||||||
info.hid.usUsage == HID_USAGE_GENERIC_JOYSTICK) {
|
info.hid.usUsage == HID_USAGE_GENERIC_JOYSTICK) {
|
||||||
_device_class = DeviceClass::flight_stick;
|
_device_class = DeviceClass::FLIGHT_STICK;
|
||||||
|
|
||||||
if (_name == "usb gamepad") {
|
if (_name == "usb gamepad") {
|
||||||
// Well, it claims to be a gamepad...
|
// Well, it claims to be a gamepad...
|
||||||
_device_class = DeviceClass::gamepad;
|
_device_class = DeviceClass::GAMEPAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mice
|
// Mice
|
||||||
} else if (info.hid.usUsagePage == HID_USAGE_PAGE_GENERIC &&
|
} else if (info.hid.usUsagePage == HID_USAGE_PAGE_GENERIC &&
|
||||||
info.hid.usUsage == HID_USAGE_GENERIC_MOUSE) {
|
info.hid.usUsage == HID_USAGE_GENERIC_MOUSE) {
|
||||||
_device_class = DeviceClass::mouse;
|
_device_class = DeviceClass::MOUSE;
|
||||||
|
|
||||||
// Keyboards
|
// Keyboards
|
||||||
} else if (info.hid.usUsagePage == HID_USAGE_PAGE_GENERIC &&
|
} else if (info.hid.usUsagePage == HID_USAGE_PAGE_GENERIC &&
|
||||||
info.hid.usUsage == HID_USAGE_GENERIC_KEYBOARD) {
|
info.hid.usUsage == HID_USAGE_GENERIC_KEYBOARD) {
|
||||||
_device_class = DeviceClass::keyboard;
|
_device_class = DeviceClass::KEYBOARD;
|
||||||
|
|
||||||
// Digitizers
|
// Digitizers
|
||||||
} else if (info.hid.usUsagePage == HID_USAGE_PAGE_DIGITIZER &&
|
} else if (info.hid.usUsagePage == HID_USAGE_PAGE_DIGITIZER &&
|
||||||
info.hid.usUsage == 1) {
|
info.hid.usUsage == 1) {
|
||||||
_device_class = DeviceClass::digitizer;
|
_device_class = DeviceClass::DIGITIZER;
|
||||||
|
|
||||||
// 3Dconnexion SpaceNavigator and friends.
|
// 3Dconnexion SpaceNavigator and friends.
|
||||||
} else if (_vendor_id == 0x046d &&
|
} else if (_vendor_id == 0x046d &&
|
||||||
@ -233,7 +233,7 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
_product_id == 0xc628 ||
|
_product_id == 0xc628 ||
|
||||||
_product_id == 0xc629 ||
|
_product_id == 0xc629 ||
|
||||||
_product_id == 0xc62b)) {
|
_product_id == 0xc62b)) {
|
||||||
_device_class = DeviceClass::spatial_mouse;
|
_device_class = DeviceClass::SPATIAL_MOUSE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -241,8 +241,8 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_device_class == DeviceClass::gamepad ||
|
if (_device_class == DeviceClass::GAMEPAD ||
|
||||||
_device_class == DeviceClass::flight_stick) {
|
_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
// Do we have a built-in mapping?
|
// Do we have a built-in mapping?
|
||||||
const DeviceMapping *mapping = mapping_presets;
|
const DeviceMapping *mapping = mapping_presets;
|
||||||
while (mapping->vendor != 0) {
|
while (mapping->vendor != 0) {
|
||||||
@ -354,17 +354,17 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
ButtonHandle handle = ButtonHandle::none();
|
ButtonHandle handle = ButtonHandle::none();
|
||||||
switch (cap.UsagePage) {
|
switch (cap.UsagePage) {
|
||||||
case HID_USAGE_PAGE_BUTTON:
|
case HID_USAGE_PAGE_BUTTON:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if (usage > 0 && usage - 1 < _countof(default_gamepad_mapping)) {
|
if (usage > 0 && usage - 1 < _countof(default_gamepad_mapping)) {
|
||||||
if (gamepad_buttons[usage - 1] != nullptr) {
|
if (gamepad_buttons[usage - 1] != nullptr) {
|
||||||
handle = registry->find_button(gamepad_buttons[usage - 1]);
|
handle = registry->find_button(gamepad_buttons[usage - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
if (usage > 0) {
|
if (usage > 0) {
|
||||||
handle = GamepadButton::joystick(usage - 1);
|
handle = GamepadButton::joystick(usage - 1);
|
||||||
}
|
}
|
||||||
} else if (_device_class == DeviceClass::mouse) {
|
} else if (_device_class == DeviceClass::MOUSE) {
|
||||||
// In Panda, wheel and right button are flipped around...
|
// In Panda, wheel and right button are flipped around...
|
||||||
int button = (usage == 2 || usage == 3) ? (4 - usage) : (usage - 1);
|
int button = (usage == 2 || usage == 3) ? (4 - usage) : (usage - 1);
|
||||||
handle = MouseButton::button(button);
|
handle = MouseButton::button(button);
|
||||||
@ -434,44 +434,44 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
is_signed = false;
|
is_signed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Axis axis = Axis::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 == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::left_x;
|
axis = Axis::LEFT_X;
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = Axis::roll;
|
axis = Axis::ROLL;
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::x;
|
axis = Axis::X;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HID_USAGE_GENERIC_Y:
|
case HID_USAGE_GENERIC_Y:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
axis = Axis::left_y;
|
axis = Axis::LEFT_Y;
|
||||||
swap(cap.LogicalMin, cap.LogicalMax);
|
swap(cap.LogicalMin, cap.LogicalMax);
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = Axis::pitch;
|
axis = Axis::PITCH;
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::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 == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if (quirks & QB_rstick_from_z) {
|
if (quirks & QB_rstick_from_z) {
|
||||||
if (quirks & QB_right_axes_swapped) {
|
if (quirks & QB_right_axes_swapped) {
|
||||||
axis = InputDevice::Axis::right_y;
|
axis = InputDevice::Axis::RIGHT_Y;
|
||||||
swap(cap.LogicalMin, cap.LogicalMax);
|
swap(cap.LogicalMin, cap.LogicalMax);
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::right_x;
|
axis = InputDevice::Axis::RIGHT_X;
|
||||||
}
|
}
|
||||||
} else if ((quirks & QB_no_analog_triggers) == 0) {
|
} else if ((quirks & QB_no_analog_triggers) == 0) {
|
||||||
axis = Axis::left_trigger;
|
axis = Axis::LEFT_TRIGGER;
|
||||||
}
|
}
|
||||||
} else if (_device_class == DeviceClass::flight_stick) {
|
} else if (_device_class == DeviceClass::FLIGHT_STICK) {
|
||||||
axis = Axis::throttle;
|
axis = Axis::THROTTLE;
|
||||||
if ((quirks & QB_reversed_throttle) != 0) {
|
if ((quirks & QB_reversed_throttle) != 0) {
|
||||||
std::swap(cap.LogicalMin, cap.LogicalMax);
|
std::swap(cap.LogicalMin, cap.LogicalMax);
|
||||||
}
|
}
|
||||||
@ -479,63 +479,63 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
is_signed = false;
|
is_signed = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::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 == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if (quirks & QB_rstick_from_z) {
|
if (quirks & QB_rstick_from_z) {
|
||||||
if ((quirks & QB_no_analog_triggers) == 0) {
|
if ((quirks & QB_no_analog_triggers) == 0) {
|
||||||
axis = Axis::left_trigger;
|
axis = Axis::LEFT_TRIGGER;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::right_x;
|
axis = Axis::RIGHT_X;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::pitch;
|
axis = Axis::PITCH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case HID_USAGE_GENERIC_RY:
|
case HID_USAGE_GENERIC_RY:
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if (quirks & QB_rstick_from_z) {
|
if (quirks & QB_rstick_from_z) {
|
||||||
if ((quirks & QB_no_analog_triggers) == 0) {
|
if ((quirks & QB_no_analog_triggers) == 0) {
|
||||||
axis = Axis::right_trigger;
|
axis = Axis::RIGHT_TRIGGER;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::right_y;
|
axis = Axis::RIGHT_Y;
|
||||||
swap(cap.LogicalMin, cap.LogicalMax);
|
swap(cap.LogicalMin, cap.LogicalMax);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
axis = Axis::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 == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
if (quirks & QB_rstick_from_z) {
|
if (quirks & QB_rstick_from_z) {
|
||||||
if (quirks & QB_right_axes_swapped) {
|
if (quirks & QB_right_axes_swapped) {
|
||||||
axis = InputDevice::Axis::right_x;
|
axis = InputDevice::Axis::RIGHT_X;
|
||||||
} else {
|
} else {
|
||||||
axis = InputDevice::Axis::right_y;
|
axis = InputDevice::Axis::RIGHT_Y;
|
||||||
swap(cap.LogicalMin, cap.LogicalMax);
|
swap(cap.LogicalMin, cap.LogicalMax);
|
||||||
}
|
}
|
||||||
} else if ((quirks & QB_no_analog_triggers) == 0) {
|
} else if ((quirks & QB_no_analog_triggers) == 0) {
|
||||||
axis = Axis::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 = Axis::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 = Axis::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 = Axis::wheel;
|
axis = Axis::WHEEL;
|
||||||
break;
|
break;
|
||||||
case HID_USAGE_GENERIC_HATSWITCH:
|
case HID_USAGE_GENERIC_HATSWITCH:
|
||||||
// This is handled specially.
|
// This is handled specially.
|
||||||
@ -548,7 +548,7 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
case HID_USAGE_PAGE_DIGITIZER:
|
case HID_USAGE_PAGE_DIGITIZER:
|
||||||
switch (usage) {
|
switch (usage) {
|
||||||
case 0x30:
|
case 0x30:
|
||||||
axis = Axis::pressure;
|
axis = Axis::PRESSURE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -559,7 +559,7 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
// have a weird extra Z axis with DataIndex 2 that should be ignored.
|
// have a weird extra Z axis with DataIndex 2 that should be ignored.
|
||||||
for (size_t i = 0; i < _axes.size(); ++i) {
|
for (size_t i = 0; i < _axes.size(); ++i) {
|
||||||
if (_axes[i].axis == axis) {
|
if (_axes[i].axis == axis) {
|
||||||
axis = Axis::none;
|
axis = Axis::NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -589,7 +589,7 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
|
|||||||
// Do we need to emulate a hat switch or directional pad?
|
// Do we need to emulate a hat switch or directional pad?
|
||||||
if (_hat_data_index != -1) {
|
if (_hat_data_index != -1) {
|
||||||
_hat_left_button = (int)_buttons.size();
|
_hat_left_button = (int)_buttons.size();
|
||||||
if (_device_class == DeviceClass::gamepad) {
|
if (_device_class == DeviceClass::GAMEPAD) {
|
||||||
_buttons.push_back(ButtonState(GamepadButton::dpad_left()));
|
_buttons.push_back(ButtonState(GamepadButton::dpad_left()));
|
||||||
_buttons.push_back(ButtonState(GamepadButton::dpad_right()));
|
_buttons.push_back(ButtonState(GamepadButton::dpad_right()));
|
||||||
_buttons.push_back(ButtonState(GamepadButton::dpad_down()));
|
_buttons.push_back(ButtonState(GamepadButton::dpad_down()));
|
||||||
|
@ -335,43 +335,43 @@ init_device(const XINPUT_CAPABILITIES_EX &caps, const XINPUT_STATE &state) {
|
|||||||
switch (caps.SubType) {
|
switch (caps.SubType) {
|
||||||
default:
|
default:
|
||||||
case XINPUT_DEVSUBTYPE_GAMEPAD:
|
case XINPUT_DEVSUBTYPE_GAMEPAD:
|
||||||
_device_class = DeviceClass::gamepad;
|
_device_class = DeviceClass::GAMEPAD;
|
||||||
_axes[0].axis = Axis::left_trigger;
|
_axes[0].axis = Axis::LEFT_TRIGGER;
|
||||||
_axes[1].axis = Axis::right_trigger;
|
_axes[1].axis = Axis::RIGHT_TRIGGER;
|
||||||
_axes[2].axis = Axis::left_x;
|
_axes[2].axis = Axis::LEFT_X;
|
||||||
_axes[3].axis = Axis::left_y;
|
_axes[3].axis = Axis::LEFT_Y;
|
||||||
_axes[4].axis = Axis::right_x;
|
_axes[4].axis = Axis::RIGHT_X;
|
||||||
_axes[5].axis = Axis::right_y;
|
_axes[5].axis = Axis::RIGHT_Y;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XINPUT_DEVSUBTYPE_WHEEL:
|
case XINPUT_DEVSUBTYPE_WHEEL:
|
||||||
_device_class = DeviceClass::steering_wheel;
|
_device_class = DeviceClass::STEERING_WHEEL;
|
||||||
_axes[0].axis = Axis::brake;
|
_axes[0].axis = Axis::BRAKE;
|
||||||
_axes[1].axis = Axis::accelerator;
|
_axes[1].axis = Axis::ACCELERATOR;
|
||||||
_axes[2].axis = Axis::wheel;
|
_axes[2].axis = Axis::WHEEL;
|
||||||
_axes[3].axis = Axis::none;
|
_axes[3].axis = Axis::NONE;
|
||||||
_axes[4].axis = Axis::none;
|
_axes[4].axis = Axis::NONE;
|
||||||
_axes[5].axis = Axis::none;
|
_axes[5].axis = Axis::NONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
|
case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
|
||||||
_device_class = DeviceClass::flight_stick;
|
_device_class = DeviceClass::FLIGHT_STICK;
|
||||||
_axes[0].axis = Axis::yaw;
|
_axes[0].axis = Axis::YAW;
|
||||||
_axes[1].axis = Axis::throttle;
|
_axes[1].axis = Axis::THROTTLE;
|
||||||
_axes[2].axis = Axis::roll;
|
_axes[2].axis = Axis::ROLL;
|
||||||
_axes[3].axis = Axis::pitch;
|
_axes[3].axis = Axis::PITCH;
|
||||||
_axes[4].axis = Axis::none;
|
_axes[4].axis = Axis::NONE;
|
||||||
_axes[5].axis = Axis::none;
|
_axes[5].axis = Axis::NONE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XINPUT_DEVSUBTYPE_DANCE_PAD:
|
case XINPUT_DEVSUBTYPE_DANCE_PAD:
|
||||||
_device_class = DeviceClass::dance_pad;
|
_device_class = DeviceClass::DANCE_PAD;
|
||||||
_axes[0].axis = Axis::none;
|
_axes[0].axis = Axis::NONE;
|
||||||
_axes[1].axis = Axis::none;
|
_axes[1].axis = Axis::NONE;
|
||||||
_axes[2].axis = Axis::none;
|
_axes[2].axis = Axis::NONE;
|
||||||
_axes[3].axis = Axis::none;
|
_axes[3].axis = Axis::NONE;
|
||||||
_axes[4].axis = Axis::none;
|
_axes[4].axis = Axis::NONE;
|
||||||
_axes[5].axis = Axis::none;
|
_axes[5].axis = Axis::NONE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ init_device(const XINPUT_CAPABILITIES_EX &caps, const XINPUT_STATE &state) {
|
|||||||
|
|
||||||
if (caps.Vibration.wLeftMotorSpeed != 0 ||
|
if (caps.Vibration.wLeftMotorSpeed != 0 ||
|
||||||
caps.Vibration.wRightMotorSpeed != 0) {
|
caps.Vibration.wRightMotorSpeed != 0) {
|
||||||
enable_feature(Feature::vibration);
|
enable_feature(Feature::VIBRATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_battery_information != nullptr) {
|
if (get_battery_information != nullptr) {
|
||||||
@ -423,7 +423,7 @@ init_device(const XINPUT_CAPABILITIES_EX &caps, const XINPUT_STATE &state) {
|
|||||||
if (batt.BatteryType != BATTERY_TYPE_DISCONNECTED &&
|
if (batt.BatteryType != BATTERY_TYPE_DISCONNECTED &&
|
||||||
batt.BatteryType != BATTERY_TYPE_WIRED) {
|
batt.BatteryType != BATTERY_TYPE_WIRED) {
|
||||||
// This device has a battery. Report the battery level.
|
// This device has a battery. Report the battery level.
|
||||||
enable_feature(Feature::battery);
|
enable_feature(Feature::BATTERY);
|
||||||
_battery_data.level = batt.BatteryLevel;
|
_battery_data.level = batt.BatteryLevel;
|
||||||
_battery_data.max_level = BATTERY_LEVEL_FULL;
|
_battery_data.max_level = BATTERY_LEVEL_FULL;
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,14 @@ using std::string;
|
|||||||
*/
|
*/
|
||||||
GraphicsWindowInputDevice::
|
GraphicsWindowInputDevice::
|
||||||
GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, bool pointer, bool keyboard) :
|
GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, bool pointer, bool keyboard) :
|
||||||
InputDevice(name, DeviceClass::virtual_device)
|
InputDevice(name, DeviceClass::VIRTUAL)
|
||||||
{
|
{
|
||||||
if (pointer) {
|
if (pointer) {
|
||||||
enable_feature(Feature::pointer);
|
enable_feature(Feature::POINTER);
|
||||||
add_pointer(PointerType::mouse, 0);
|
add_pointer(PointerType::MOUSE, 0);
|
||||||
}
|
}
|
||||||
if (keyboard) {
|
if (keyboard) {
|
||||||
enable_feature(Feature::keyboard);
|
enable_feature(Feature::KEYBOARD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ set_pointer_in_window(double x, double y, double time) {
|
|||||||
LightMutexHolder holder(_lock);
|
LightMutexHolder holder(_lock);
|
||||||
PointerData data = _pointers[0];
|
PointerData data = _pointers[0];
|
||||||
data._id = 0;
|
data._id = 0;
|
||||||
data._type = PointerType::mouse;
|
data._type = PointerType::MOUSE;
|
||||||
data._xpos = x;
|
data._xpos = x;
|
||||||
data._ypos = y;
|
data._ypos = y;
|
||||||
data._in_window = true;
|
data._in_window = true;
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
bool _in_window = false;
|
bool _in_window = false;
|
||||||
int _id = 0;
|
int _id = 0;
|
||||||
PointerType _type = PointerType::unknown;
|
PointerType _type = PointerType::UNKNOWN;
|
||||||
double _xpos = 0.0;
|
double _xpos = 0.0;
|
||||||
double _ypos = 0.0;
|
double _ypos = 0.0;
|
||||||
double _dx = 0.0;
|
double _dx = 0.0;
|
||||||
|
@ -23,11 +23,18 @@ BEGIN_PUBLISH
|
|||||||
* Contains the types of pointer device.
|
* Contains the types of pointer device.
|
||||||
*/
|
*/
|
||||||
enum class PointerType {
|
enum class PointerType {
|
||||||
unknown,
|
UNKNOWN,
|
||||||
mouse,
|
MOUSE,
|
||||||
finger,
|
FINGER,
|
||||||
stylus,
|
STYLUS,
|
||||||
eraser,
|
ERASER,
|
||||||
|
|
||||||
|
// deprecated aliases
|
||||||
|
unknown = UNKNOWN,
|
||||||
|
mouse = MOUSE,
|
||||||
|
finger = FINGER,
|
||||||
|
stylus = STYLUS,
|
||||||
|
eraser = ERASER,
|
||||||
};
|
};
|
||||||
END_PUBLISH
|
END_PUBLISH
|
||||||
|
|
||||||
@ -61,7 +68,7 @@ public:
|
|||||||
double _xpos = 0.0;
|
double _xpos = 0.0;
|
||||||
double _ypos = 0.0;
|
double _ypos = 0.0;
|
||||||
double _pressure = 0.0;
|
double _pressure = 0.0;
|
||||||
PointerType _type = PointerType::unknown;
|
PointerType _type = PointerType::UNKNOWN;
|
||||||
int _id = 0;
|
int _id = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user