From 72d1e4536538aa686b08a3de67f837acbb177df5 Mon Sep 17 00:00:00 2001 From: Simon Larsson Date: Sat, 25 Mar 2023 21:04:08 +0100 Subject: [PATCH] hacks --- Firmware/OpenSteamController/src/trackpad.c | 39 +++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/Firmware/OpenSteamController/src/trackpad.c b/Firmware/OpenSteamController/src/trackpad.c index 0be85a0..dee802f 100644 --- a/Firmware/OpenSteamController/src/trackpad.c +++ b/Firmware/OpenSteamController/src/trackpad.c @@ -1272,7 +1272,7 @@ void trackpadGetLastXY(Trackpad trackpad, uint16_t* xLoc, uint16_t* yLoc) { dividend += factor * adc_vals_y[idx]; divisor += adc_vals_y[idx]; factor += 100; - } + } if (divisor) { y_pos = dividend / divisor; @@ -1280,10 +1280,43 @@ void trackpadGetLastXY(Trackpad trackpad, uint16_t* xLoc, uint16_t* yLoc) { } // Update outputs if finger was down (i.e. x_pos and y_pos are both valid) - if (x_pos > 0 && y_pos > 0) { + if (x_pos > 0 && y_pos > 0) { + + // the entire input is offset by about 15 degrees or so + // here we try to compensate for those invalid values by just + // increasing/decreasing them to make it roughly accurate + bool left = x_pos > 600; + bool right = x_pos < 600; + bool over = y_pos > 300; + + if (left) { + y_pos += (y_pos / 6); + if (y_pos > 600) { + y_pos = 600; + } + } else if (right) { + y_pos -= (y_pos / 5); + if (y_pos < 1) { + y_pos = 0; + } + } + + if (over) { + x_pos -= (x_pos / 6); + if (x_pos < 1) { + x_pos = 0; + } + } + *xLoc = x_pos; *yLoc = y_pos; - } + } else if (y_pos == -1) { + // there's a mysterious deadzone at the top of the pad, + // this edge-case seems to only be hit when that deadzone is hit. + // so; we work around the deadzone by just maxing the Y + *xLoc = x_pos; + *yLoc = TPAD_MAX_Y; + } } /**