Merge pull request #3192 from Hinsbart/trigger-as-axis
Analog values for gamepad triggers, using axes 6 & 7.
This commit is contained in:
commit
59143847f7
4 changed files with 26 additions and 11 deletions
|
@ -143,6 +143,9 @@ enum {
|
||||||
|
|
||||||
JOY_ANALOG_2_X = JOY_AXIS_4,
|
JOY_ANALOG_2_X = JOY_AXIS_4,
|
||||||
JOY_ANALOG_2_Y = JOY_AXIS_5,
|
JOY_ANALOG_2_Y = JOY_AXIS_5,
|
||||||
|
|
||||||
|
JOY_ANALOG_L2 = JOY_AXIS_6,
|
||||||
|
JOY_ANALOG_R2 = JOY_AXIS_7,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -545,7 +545,12 @@ uint32_t InputDefault::joy_button(uint32_t p_last_id, int p_device, int p_button
|
||||||
|
|
||||||
JoyEvent map = el->get();
|
JoyEvent map = el->get();
|
||||||
if (map.type == TYPE_BUTTON) {
|
if (map.type == TYPE_BUTTON) {
|
||||||
|
//fake additional axis event for triggers
|
||||||
|
if (map.index == JOY_L2 || map.index == JOY_R2) {
|
||||||
|
float value = p_pressed ? 1.0f : 0.0f;
|
||||||
|
int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2;
|
||||||
|
p_last_id = _axis_event(p_last_id, p_device, axis, value);
|
||||||
|
}
|
||||||
return _button_event(p_last_id, p_device, map.index, p_pressed);
|
return _button_event(p_last_id, p_device, map.index, p_pressed);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -580,8 +585,9 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
|
||||||
|
|
||||||
|
|
||||||
joy.last_axis[p_axis] = p_value.value;
|
joy.last_axis[p_axis] = p_value.value;
|
||||||
if (joy.mapping == -1) {
|
|
||||||
float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value;
|
float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value;
|
||||||
|
|
||||||
|
if (joy.mapping == -1) {
|
||||||
return _axis_event(p_last_id, p_device, p_axis, val);
|
return _axis_event(p_last_id, p_device, p_axis, val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -595,6 +601,12 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
|
||||||
JoyEvent map = el->get();
|
JoyEvent map = el->get();
|
||||||
|
|
||||||
if (map.type == TYPE_BUTTON) {
|
if (map.type == TYPE_BUTTON) {
|
||||||
|
//send axis event for triggers
|
||||||
|
if (map.index == JOY_L2 || map.index == JOY_R2) {
|
||||||
|
float value = p_value.min == 0 ? p_value.value : 0.5f + p_value.value / 2.0f;
|
||||||
|
int axis = map.index == JOY_L2 ? JOY_ANALOG_L2 : JOY_ANALOG_R2;
|
||||||
|
p_last_id = _axis_event(p_last_id, p_device, axis, value);
|
||||||
|
}
|
||||||
float deadzone = p_value.min == 0 ? 0.5f : 0.0f;
|
float deadzone = p_value.min == 0 ? 0.5f : 0.0f;
|
||||||
bool pressed = p_value.value > deadzone ? true : false;
|
bool pressed = p_value.value > deadzone ? true : false;
|
||||||
if (pressed == joy_buttons_pressed.has(_combine_device(map.index,p_device))) {
|
if (pressed == joy_buttons_pressed.has(_combine_device(map.index,p_device))) {
|
||||||
|
@ -606,7 +618,6 @@ uint32_t InputDefault::joy_axis(uint32_t p_last_id, int p_device, int p_axis, co
|
||||||
|
|
||||||
if (map.type == TYPE_AXIS) {
|
if (map.type == TYPE_AXIS) {
|
||||||
|
|
||||||
float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value;
|
|
||||||
return _axis_event(p_last_id, p_device, map.index, val );
|
return _axis_event(p_last_id, p_device, map.index, val );
|
||||||
};
|
};
|
||||||
//printf("invalid mapping\n");
|
//printf("invalid mapping\n");
|
||||||
|
|
|
@ -45,11 +45,11 @@ static const char* ignore_str = "/dev/input/js";
|
||||||
joystick_linux::Joystick::Joystick() {
|
joystick_linux::Joystick::Joystick() {
|
||||||
fd = -1;
|
fd = -1;
|
||||||
dpad = 0;
|
dpad = 0;
|
||||||
|
dev = NULL;
|
||||||
|
devpath = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void joystick_linux::Joystick::reset() {
|
void joystick_linux::Joystick::reset() {
|
||||||
num_buttons = 0;
|
|
||||||
num_axes = 0;
|
|
||||||
dpad = 0;
|
dpad = 0;
|
||||||
fd = -1;
|
fd = -1;
|
||||||
for (int i=0; i < MAX_ABS; i++) {
|
for (int i=0; i < MAX_ABS; i++) {
|
||||||
|
@ -225,20 +225,23 @@ static String _hex_str(uint8_t p_byte) {
|
||||||
void joystick_linux::setup_joystick_properties(int p_id) {
|
void joystick_linux::setup_joystick_properties(int p_id) {
|
||||||
|
|
||||||
Joystick* joy = &joysticks[p_id];
|
Joystick* joy = &joysticks[p_id];
|
||||||
|
|
||||||
libevdev* dev = joy->dev;
|
libevdev* dev = joy->dev;
|
||||||
|
|
||||||
|
int num_buttons = 0;
|
||||||
|
int num_axes = 0;
|
||||||
|
|
||||||
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
|
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
|
||||||
|
|
||||||
if (libevdev_has_event_code(dev, EV_KEY, i)) {
|
if (libevdev_has_event_code(dev, EV_KEY, i)) {
|
||||||
|
|
||||||
joy->key_map[i] = joy->num_buttons++;
|
joy->key_map[i] = num_buttons++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = BTN_MISC; i < BTN_JOYSTICK; ++i) {
|
for (int i = BTN_MISC; i < BTN_JOYSTICK; ++i) {
|
||||||
|
|
||||||
if (libevdev_has_event_code(dev, EV_KEY, i)) {
|
if (libevdev_has_event_code(dev, EV_KEY, i)) {
|
||||||
|
|
||||||
joy->key_map[i] = joy->num_buttons++;
|
joy->key_map[i] = num_buttons++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < ABS_MISC; ++i) {
|
for (int i = 0; i < ABS_MISC; ++i) {
|
||||||
|
@ -249,7 +252,7 @@ void joystick_linux::setup_joystick_properties(int p_id) {
|
||||||
}
|
}
|
||||||
if (libevdev_has_event_code(dev, EV_ABS, i)) {
|
if (libevdev_has_event_code(dev, EV_ABS, i)) {
|
||||||
|
|
||||||
joy->abs_map[i] = joy->num_axes++;
|
joy->abs_map[i] = num_axes++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,6 @@ private:
|
||||||
struct Joystick {
|
struct Joystick {
|
||||||
int key_map[MAX_KEY - BT_MISC];
|
int key_map[MAX_KEY - BT_MISC];
|
||||||
int abs_map[MAX_ABS];
|
int abs_map[MAX_ABS];
|
||||||
int num_buttons;
|
|
||||||
int num_axes;
|
|
||||||
int dpad;
|
int dpad;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue