From 05361d3d37d9d09a8b986a64381d556333f63479 Mon Sep 17 00:00:00 2001 From: twojstaryzdomu <54865449+twojstaryzdomu@users.noreply.github.com> Date: Sat, 2 Mar 2024 03:16:31 +0100 Subject: [PATCH] analogue stick fix for raspberry pi (#463) * Calibrate analogue gamepad sticks on rpi * Allow overriding analogue stick centre on rpi --------- Co-authored-by: twojstaryzdomu --- src/platform/rpi/main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/platform/rpi/main.cpp b/src/platform/rpi/main.cpp index 2f28dc6..1d936a8 100644 --- a/src/platform/rpi/main.cpp +++ b/src/platform/rpi/main.cpp @@ -197,6 +197,7 @@ int inputDevices[MAX_INPUT_DEVICES]; udev *udevObj; udev_monitor *udevMon; int udevMon_fd; +int joy_centre; vec2 joyL, joyR; @@ -347,6 +348,10 @@ bool inputInit() { } udev_enumerate_unref(e); + const char *temp = getenv("JOY_CENTRE"); + if (temp && (joy_centre = atoi(temp))) + LOG("input: joy centred at %d\n", joy_centre); + return true; } @@ -359,11 +364,13 @@ void inputFree() { } #define JOY_DEAD_ZONE_STICK 8192 +#define JOY_CENTRE 32768 float joyAxisValue(int value) { + value -= joy_centre ? joy_centre : JOY_CENTRE; if (value > -JOY_DEAD_ZONE_STICK && value < JOY_DEAD_ZONE_STICK) return 0.0f; - return value / 32767.0f; + return value / 32768.0f; } float joyTrigger(int value) {