join analogs and gyroscope
This commit is contained in:
parent
d208f5dc2a
commit
026e970615
8 changed files with 90 additions and 0 deletions
|
|
@ -134,6 +134,14 @@ static void handle_incoming_message_gamepad_set(
|
||||||
inout_gamepad->touchpad_press = msg_payload->status.btn;
|
inout_gamepad->touchpad_press = msg_payload->status.btn;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case GAMEPAD_BTN_JOIN_LEFT_ANALOG_AND_GYROSCOPE: {
|
||||||
|
inout_gamepad->join_left_analog_and_gyroscope = msg_payload->status.btn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GAMEPAD_BTN_JOIN_RIGHT_ANALOG_AND_GYROSCOPE: {
|
||||||
|
inout_gamepad->join_right_analog_and_gyroscope = msg_payload->status.btn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case GAMEPAD_LEFT_JOYSTICK_X: {
|
case GAMEPAD_LEFT_JOYSTICK_X: {
|
||||||
inout_gamepad->joystick_positions[0][0] = msg_payload->status.joystick_pos;
|
inout_gamepad->joystick_positions[0][0] = msg_payload->status.joystick_pos;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,8 @@ void gamepad_status_init(gamepad_status_t *const stats) {
|
||||||
stats->touchpad_touch_num = -1;
|
stats->touchpad_touch_num = -1;
|
||||||
stats->touchpad_x = 0;
|
stats->touchpad_x = 0;
|
||||||
stats->touchpad_y = 0;
|
stats->touchpad_y = 0;
|
||||||
|
stats->join_left_analog_and_gyroscope = 0;
|
||||||
|
stats->join_right_analog_and_gyroscope = 0;
|
||||||
stats->flags = 0;
|
stats->flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,9 @@ typedef struct gamepad_status {
|
||||||
uint64_t leds_events_count;
|
uint64_t leds_events_count;
|
||||||
uint8_t leds_colors[3]; // r | g | b
|
uint8_t leds_colors[3]; // r | g | b
|
||||||
|
|
||||||
|
uint8_t join_left_analog_and_gyroscope;
|
||||||
|
uint8_t join_right_analog_and_gyroscope;
|
||||||
|
|
||||||
volatile uint32_t flags;
|
volatile uint32_t flags;
|
||||||
|
|
||||||
} gamepad_status_t;
|
} gamepad_status_t;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ typedef enum in_message_gamepad_btn {
|
||||||
GAMEPAD_BTN_L5,
|
GAMEPAD_BTN_L5,
|
||||||
GAMEPAD_BTN_R5,
|
GAMEPAD_BTN_R5,
|
||||||
GAMEPAD_BTN_TOUCHPAD,
|
GAMEPAD_BTN_TOUCHPAD,
|
||||||
|
GAMEPAD_BTN_JOIN_LEFT_ANALOG_AND_GYROSCOPE,
|
||||||
|
GAMEPAD_BTN_JOIN_RIGHT_ANALOG_AND_GYROSCOPE,
|
||||||
|
|
||||||
GAMEPAD_LEFT_JOYSTICK_X,
|
GAMEPAD_LEFT_JOYSTICK_X,
|
||||||
GAMEPAD_LEFT_JOYSTICK_Y,
|
GAMEPAD_LEFT_JOYSTICK_Y,
|
||||||
|
|
|
||||||
28
rog_ally.c
28
rog_ally.c
|
|
@ -224,6 +224,20 @@ static int asus_kbd_ev_map(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
messages[written_msg++] = current_message;
|
||||||
|
} else if (conf->m1m2_mode == 2) {
|
||||||
|
const in_message_t current_message = {
|
||||||
|
.type = GAMEPAD_SET_ELEMENT,
|
||||||
|
.data = {
|
||||||
|
.gamepad_set = {
|
||||||
|
.element = GAMEPAD_BTN_JOIN_RIGHT_ANALOG_AND_GYROSCOPE,
|
||||||
|
.status = {
|
||||||
|
.btn = e->ev[1].value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
messages[written_msg++] = current_message;
|
messages[written_msg++] = current_message;
|
||||||
}
|
}
|
||||||
} else if (e->ev[i].code == KEY_F15) {
|
} else if (e->ev[i].code == KEY_F15) {
|
||||||
|
|
@ -262,6 +276,20 @@ static int asus_kbd_ev_map(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
messages[written_msg++] = current_message;
|
||||||
|
} else if (conf->m1m2_mode == 2) {
|
||||||
|
const in_message_t current_message = {
|
||||||
|
.type = GAMEPAD_SET_ELEMENT,
|
||||||
|
.data = {
|
||||||
|
.gamepad_set = {
|
||||||
|
.element = GAMEPAD_BTN_JOIN_LEFT_ANALOG_AND_GYROSCOPE,
|
||||||
|
.status = {
|
||||||
|
.btn = e->ev[1].value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
messages[written_msg++] = current_message;
|
messages[written_msg++] = current_message;
|
||||||
}
|
}
|
||||||
} else if ((e->ev[i].code == KEY_F16) && (e->ev[i].value != 0)) {
|
} else if ((e->ev[i].code == KEY_F16) && (e->ev[i].value != 0)) {
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,9 @@ int32_t div_round_closest(int32_t x, int32_t divisor) {
|
||||||
const int32_t __d = divisor;
|
const int32_t __d = divisor;
|
||||||
return ((__x) > 0) == ((__d) > 0) ? (((__x) + ((__d) / 2)) / (__d)) : (((__x) - ((__d) / 2)) / (__d));
|
return ((__x) > 0) == ((__d) > 0) ? (((__x) + ((__d) / 2)) / (__d)) : (((__x) - ((__d) / 2)) / (__d));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t div_round_closest_i64(int64_t x, int64_t divisor) {
|
||||||
|
const int64_t __x = x;
|
||||||
|
const int64_t __d = divisor;
|
||||||
|
return ((__x) > 0) == ((__d) > 0) ? (((__x) + ((__d) / 2)) / (__d)) : (((__x) - ((__d) / 2)) / (__d));
|
||||||
|
}
|
||||||
|
|
@ -61,3 +61,5 @@
|
||||||
|
|
||||||
// also courtesy of linux kernel
|
// also courtesy of linux kernel
|
||||||
int32_t div_round_closest(int32_t x, int32_t divisor);
|
int32_t div_round_closest(int32_t x, int32_t divisor);
|
||||||
|
|
||||||
|
int64_t div_round_closest_i64(int64_t x, int64_t divisor);
|
||||||
|
|
|
||||||
39
virt_ds5.c
39
virt_ds5.c
|
|
@ -1282,6 +1282,45 @@ void virt_dualsense_compose(virt_dualsense_t *const gamepad, gamepad_status_t *c
|
||||||
out_shifted_buf[2] = ((uint64_t)((int64_t)in_device_status->joystick_positions[0][1] + (int64_t)32768) >> (uint64_t)8); // L stick, Y axis
|
out_shifted_buf[2] = ((uint64_t)((int64_t)in_device_status->joystick_positions[0][1] + (int64_t)32768) >> (uint64_t)8); // L stick, Y axis
|
||||||
out_shifted_buf[3] = ((uint64_t)((int64_t)in_device_status->joystick_positions[1][0] + (int64_t)32768) >> (uint64_t)8); // R stick, X axis
|
out_shifted_buf[3] = ((uint64_t)((int64_t)in_device_status->joystick_positions[1][0] + (int64_t)32768) >> (uint64_t)8); // R stick, X axis
|
||||||
out_shifted_buf[4] = ((uint64_t)((int64_t)in_device_status->joystick_positions[1][1] + (int64_t)32768) >> (uint64_t)8); // R stick, Y axis
|
out_shifted_buf[4] = ((uint64_t)((int64_t)in_device_status->joystick_positions[1][1] + (int64_t)32768) >> (uint64_t)8); // R stick, Y axis
|
||||||
|
|
||||||
|
if (in_device_status->join_left_analog_and_gyroscope) {
|
||||||
|
int64_t joint_x = ((int64_t)out_shifted_buf[1] - (int64_t)128) + (div_round_closest_i64((int64_t)255 * ((int64_t)32768 + (int64_t)in_device_status->raw_gyro[0]), 0xFFFF) - (int64_t)128);
|
||||||
|
if (joint_x < (int64_t)-128) {
|
||||||
|
joint_x = -128;
|
||||||
|
} else if (joint_x < (int64_t)127) {
|
||||||
|
joint_x = 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t joint_y = ((int64_t)out_shifted_buf[2] - (int64_t)128) + (div_round_closest_i64((int64_t)255 * ((int64_t)32768 + (int64_t)in_device_status->raw_gyro[1]), 0xFFFF) - (int64_t)128);
|
||||||
|
if (joint_y < (int64_t)-128) {
|
||||||
|
joint_y = -128;
|
||||||
|
} else if (joint_x < (int64_t)127) {
|
||||||
|
joint_y = 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
out_shifted_buf[1] = joint_x + (int64_t)128;
|
||||||
|
out_shifted_buf[2] = joint_y + (int64_t)128;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_device_status->join_right_analog_and_gyroscope) {
|
||||||
|
int64_t joint_x = ((int64_t)out_shifted_buf[3] - (int64_t)128) + (div_round_closest_i64((int64_t)255 * ((int64_t)32768 + (int64_t)in_device_status->raw_gyro[0]), 0xFFFF) - (int64_t)128);
|
||||||
|
if (joint_x < (int64_t)-128) {
|
||||||
|
joint_x = -128;
|
||||||
|
} else if (joint_x < (int64_t)127) {
|
||||||
|
joint_x = 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t joint_y = ((int64_t)out_shifted_buf[4] - (int64_t)128) + (div_round_closest_i64((int64_t)255 * ((int64_t)32768 + (int64_t)in_device_status->raw_gyro[1]), 0xFFFF) - (int64_t)128);
|
||||||
|
if (joint_y < (int64_t)-128) {
|
||||||
|
joint_y = -128;
|
||||||
|
} else if (joint_x < (int64_t)127) {
|
||||||
|
joint_y = 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
out_shifted_buf[3] = joint_x + (int64_t)128;
|
||||||
|
out_shifted_buf[4] = joint_y + (int64_t)128;
|
||||||
|
}
|
||||||
|
|
||||||
out_shifted_buf[5] = in_device_status->l2_trigger; // Z
|
out_shifted_buf[5] = in_device_status->l2_trigger; // Z
|
||||||
out_shifted_buf[6] = in_device_status->r2_trigger; // RZ
|
out_shifted_buf[6] = in_device_status->r2_trigger; // RZ
|
||||||
out_shifted_buf[7] = gamepad->seq_num++; // seq_number
|
out_shifted_buf[7] = gamepad->seq_num++; // seq_number
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue