swap y and z, improve gyro-to-joystick
This commit is contained in:
parent
ec2d777245
commit
ae3fac6301
9 changed files with 43 additions and 38 deletions
|
|
@ -33,6 +33,7 @@ int main(int argc, char ** argv) {
|
|||
.gamepad_rumble_control = true,
|
||||
.controller_bluetooth = false,
|
||||
.dualsense_edge = false,
|
||||
.swap_y_z = false,
|
||||
};
|
||||
|
||||
load_out_config(&out_settings, configuration_file);
|
||||
|
|
|
|||
|
|
@ -9,3 +9,4 @@ m1m2_mode = 1;
|
|||
touchbar = true;
|
||||
controller_bluetooth = true;
|
||||
dualsense_edge = false;
|
||||
swap_y_z = true;
|
||||
|
|
@ -187,15 +187,15 @@ static void handle_incoming_message_gamepad_set(
|
|||
case GAMEPAD_GYROSCOPE: {
|
||||
inout_gamepad->last_gyro_motion_timestamp_ns = msg_payload->status.gyro.sample_timestamp_ns;
|
||||
inout_gamepad->raw_gyro[0] = msg_payload->status.gyro.x;
|
||||
inout_gamepad->raw_gyro[1] = msg_payload->status.gyro.y;
|
||||
inout_gamepad->raw_gyro[2] = msg_payload->status.gyro.z;
|
||||
inout_gamepad->raw_gyro[1] = in_settings->swap_y_z ? msg_payload->status.gyro.z : msg_payload->status.gyro.y;
|
||||
inout_gamepad->raw_gyro[2] = in_settings->swap_y_z ? msg_payload->status.gyro.y : msg_payload->status.gyro.z;
|
||||
break;
|
||||
}
|
||||
case GAMEPAD_ACCELEROMETER: {
|
||||
inout_gamepad->last_accel_motion_timestamp_ns = msg_payload->status.accel.sample_timestamp_ns;
|
||||
inout_gamepad->raw_accel[0] = msg_payload->status.accel.x;
|
||||
inout_gamepad->raw_accel[1] = msg_payload->status.accel.y;
|
||||
inout_gamepad->raw_accel[2] = msg_payload->status.accel.z;
|
||||
inout_gamepad->raw_accel[1] = in_settings->swap_y_z ? msg_payload->status.accel.z : msg_payload->status.accel.y;
|
||||
inout_gamepad->raw_accel[2] = in_settings->swap_y_z ? msg_payload->status.accel.y : msg_payload->status.accel.z;
|
||||
break;
|
||||
}
|
||||
case GAMEPAD_TOUCHPAD_TOUCH_ACTIVE: {
|
||||
|
|
|
|||
|
|
@ -11,3 +11,15 @@ int64_t div_round_closest_i64(int64_t x, int64_t divisor) {
|
|||
const int64_t __d = divisor;
|
||||
return ((__x) > 0) == ((__d) > 0) ? (((__x) + ((__d) / 2)) / (__d)) : (((__x) - ((__d) / 2)) / (__d));
|
||||
}
|
||||
|
||||
int64_t min_max_clamp(int64_t value, int64_t min, int64_t max) {
|
||||
if (value <= min) {
|
||||
return min;
|
||||
}
|
||||
|
||||
if (value >= max) {
|
||||
return max;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,3 +63,5 @@
|
|||
int32_t div_round_closest(int32_t x, int32_t divisor);
|
||||
|
||||
int64_t div_round_closest_i64(int64_t x, int64_t divisor);
|
||||
|
||||
int64_t min_max_clamp(int64_t value, int64_t min, int64_t max);
|
||||
|
|
@ -113,6 +113,13 @@ void load_out_config(dev_out_settings_t *const out_conf, const char* const filep
|
|||
fprintf(stderr, "dualsense_edge (bool) configuration not found. Default value will be used.\n");
|
||||
}
|
||||
|
||||
int swap_y_z;
|
||||
if (config_lookup_bool(&cfg, "swap_y_z", &swap_y_z) != CONFIG_FALSE) {
|
||||
out_conf->swap_y_z = swap_y_z;
|
||||
} else {
|
||||
fprintf(stderr, "swap_y_z (bool) configuration not found. Default value will be used.\n");
|
||||
}
|
||||
|
||||
config_destroy(&cfg);
|
||||
|
||||
load_out_config_err:
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ typedef struct dev_out_settings {
|
|||
bool gamepad_rumble_control;
|
||||
bool controller_bluetooth;
|
||||
bool dualsense_edge;
|
||||
bool swap_y_z;
|
||||
} dev_out_settings_t;
|
||||
|
||||
void load_out_config(dev_out_settings_t *const out_conf, const char* const filepath);
|
||||
|
|
@ -19,6 +19,7 @@ int main(int argc, char ** argv) {
|
|||
.gamepad_rumble_control = true,
|
||||
.controller_bluetooth = false,
|
||||
.dualsense_edge = false,
|
||||
.swap_y_z = false,
|
||||
};
|
||||
|
||||
load_out_config(&out_settings, configuration_file);
|
||||
|
|
|
|||
44
virt_ds5.c
44
virt_ds5.c
|
|
@ -1445,45 +1445,25 @@ void virt_dualsense_compose(virt_dualsense_t *const gamepad, gamepad_status_t *c
|
|||
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) {
|
||||
const int64_t joint_x = /*(int64_t)in_device_status->joystick_positions[0][0]*/ (int64_t)127 + ((int64_t)g_x / (int64_t)4);
|
||||
const int64_t joint_y = /*(int64_t)in_device_status->joystick_positions[0][1]*/ (int64_t)127 + ((int64_t)g_y / (int64_t)4);
|
||||
const int64_t contrib_x = (int64_t)127 + ((int64_t)g_x / (int64_t)4);
|
||||
const int64_t contrib_y = (int64_t)127 + ((int64_t)g_y / (int64_t)4);
|
||||
|
||||
if (joint_x <= (int64_t)0) {
|
||||
out_shifted_buf[1] = 0x00;
|
||||
} else if (joint_x >= (int64_t)255) {
|
||||
out_shifted_buf[1] = 0xFF;
|
||||
} else {
|
||||
out_shifted_buf[1] = joint_x;
|
||||
}
|
||||
const uint8_t analog_x_contrib = min_max_clamp(contrib_x, 0, 255);
|
||||
const uint8_t analog_y_contrib = min_max_clamp(contrib_y, 0, 255);
|
||||
|
||||
if (joint_y <= (int64_t)0) {
|
||||
out_shifted_buf[2] = 0x00;
|
||||
} else if (joint_y >= (int64_t)255) {
|
||||
out_shifted_buf[2] = 0xFF;
|
||||
} else {
|
||||
out_shifted_buf[2] = joint_y;
|
||||
}
|
||||
out_shifted_buf[1] = min_max_clamp((int64_t)out_shifted_buf[1] + (int64_t)analog_x_contrib, 0, 255);
|
||||
out_shifted_buf[2] = min_max_clamp((int64_t)out_shifted_buf[2] + (int64_t)analog_y_contrib, 0, 255);
|
||||
}
|
||||
|
||||
if (in_device_status->join_right_analog_and_gyroscope) {
|
||||
const int64_t joint_x = /*(int64_t)in_device_status->joystick_positions[1][0]*/ (int64_t)127 + ((int64_t)g_x / (int64_t)4);
|
||||
const int64_t joint_y = /*(int64_t)in_device_status->joystick_positions[1][1]*/ (int64_t)127 + ((int64_t)g_y / (int64_t)4);
|
||||
const int64_t contrib_x = (int64_t)127 + ((int64_t)g_x / (int64_t)4);
|
||||
const int64_t contrib_y = (int64_t)127 + ((int64_t)g_y / (int64_t)4);
|
||||
|
||||
if (joint_x <= (int64_t)0) {
|
||||
out_shifted_buf[3] = 0x00;
|
||||
} else if (joint_x >= (int64_t)255) {
|
||||
out_shifted_buf[3] = 0xFF;
|
||||
} else {
|
||||
out_shifted_buf[3] = joint_x;
|
||||
}
|
||||
const uint8_t analog_x_contrib = min_max_clamp(contrib_x, 0, 255);
|
||||
const uint8_t analog_y_contrib = min_max_clamp(contrib_y, 0, 255);
|
||||
|
||||
if (joint_y <= (int64_t)0) {
|
||||
out_shifted_buf[4] = 0x00;
|
||||
} else if (joint_y >= (int64_t)0) {
|
||||
out_shifted_buf[4] = 0xFF;
|
||||
} else {
|
||||
out_shifted_buf[4] = joint_y;
|
||||
}
|
||||
out_shifted_buf[3] = min_max_clamp((int64_t)out_shifted_buf[3] + (int64_t)analog_x_contrib, 0, 255);
|
||||
out_shifted_buf[4] = min_max_clamp((int64_t)out_shifted_buf[4] + (int64_t)analog_y_contrib, 0, 255);
|
||||
}
|
||||
|
||||
out_shifted_buf[5] = in_device_status->l2_trigger; // Z
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue