From 75c19eace117b1d5df5e965e21c10274413abad1 Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 15 Jan 2024 19:24:41 +0100 Subject: [PATCH] Allow inverting x axis --- allynone.c | 1 + config.cfg.default | 1 + dev_out.c | 4 ++-- settings.c | 7 +++++++ settings.h | 1 + stray_ally.c | 1 + 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/allynone.c b/allynone.c index 991e3a8..c174f45 100644 --- a/allynone.c +++ b/allynone.c @@ -39,6 +39,7 @@ int main(int argc, char ** argv) { .controller_bluetooth = false, .dualsense_edge = false, .swap_y_z = false, + .invert_x = false, .gyro_to_analog_activation_treshold = 16, .gyro_to_analog_mapping = 4, }; diff --git a/config.cfg.default b/config.cfg.default index 282f30b..9a8a917 100644 --- a/config.cfg.default +++ b/config.cfg.default @@ -12,6 +12,7 @@ touchbar = true; controller_bluetooth = true; dualsense_edge = false; swap_y_z = true; +invert_x = false; enable_thermal_profiles_switching = true; default_thermal_profile = -1; enable_leds_commands = true; diff --git a/dev_out.c b/dev_out.c index c940d87..b6409b4 100644 --- a/dev_out.c +++ b/dev_out.c @@ -186,14 +186,14 @@ 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[0] = in_settings->invert_x ? (int16_t)(-1) * msg_payload->status.gyro.x : msg_payload->status.gyro.x; 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[0] = in_settings->invert_x ? (int16_t)(-1) * msg_payload->status.accel.x : msg_payload->status.accel.x; 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; diff --git a/settings.c b/settings.c index 77b2784..8db164b 100644 --- a/settings.c +++ b/settings.c @@ -155,6 +155,13 @@ void load_out_config(dev_out_settings_t *const out_conf, const char* const filep fprintf(stderr, "swap_y_z (bool) configuration not found. Default value will be used.\n"); } + int invert_x; + if (config_lookup_bool(&cfg, "invert_x", &invert_x) != CONFIG_FALSE) { + out_conf->invert_x = invert_x; + } else { + fprintf(stderr, "invert_x (bool) configuration not found. Default value will be used.\n"); + } + int gyro_to_analog_activation_treshold; if (config_lookup_int(&cfg, "gyro_to_analog_activation_treshold", &gyro_to_analog_activation_treshold) != CONFIG_FALSE) { out_conf->gyro_to_analog_activation_treshold = gyro_to_analog_activation_treshold; diff --git a/settings.h b/settings.h index 0d66409..867a831 100644 --- a/settings.h +++ b/settings.h @@ -25,6 +25,7 @@ typedef struct dev_out_settings { bool controller_bluetooth; bool dualsense_edge; bool swap_y_z; + bool invert_x; int gyro_to_analog_activation_treshold; int gyro_to_analog_mapping; } dev_out_settings_t; diff --git a/stray_ally.c b/stray_ally.c index a8b288d..b156adb 100644 --- a/stray_ally.c +++ b/stray_ally.c @@ -20,6 +20,7 @@ int main(int argc, char ** argv) { .controller_bluetooth = false, .dualsense_edge = false, .swap_y_z = false, + .invert_x = false, .gyro_to_analog_activation_treshold = 16, .gyro_to_analog_mapping = 4, };