From 43503cfa510a7f7e650efccaac266d7cc6657a5d Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 11 Aug 2023 21:04:54 +0100 Subject: Better koystick support --- src/joy.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/joy.c') diff --git a/src/joy.c b/src/joy.c index cda2fcf..4910f16 100644 --- a/src/joy.c +++ b/src/joy.c @@ -66,6 +66,10 @@ uint8_t joy_detect() printf("Joystick detected!\n"); + uint16_t cx, cy; + printf("Please center the joystick and press BUTTON 1 (ESC to abort)\n"); + if (!calibrate(&cy, &cx)) + return 0; printf("Please move UP + LEFT and press BUTTON 1 (ESC to abort)\n"); if (!calibrate(&j_up, &j_left)) return 0; @@ -78,10 +82,10 @@ uint8_t joy_detect() j_up, j_down, j_left, j_right); #endif - j_up += j_up >> 4; - j_down -= j_down >> 4; - j_left += j_left >> 4; - j_right -= j_right >> 4; + j_up = cy - ((cy - j_up) / 2); + j_down = cy + ((j_down - cy) / 2); + j_left = cx - ((cx - j_left) / 2); + j_right = cx + ((j_right - cx) / 2); #ifdef DEBUG printf(" Adjusted: up=%04d, down=%04d, left=%04d, right=%04d\n", @@ -108,15 +112,15 @@ uint8_t joy_read() r |= CTL_FIRE2; v = read_axis(AXISY); - if (v <= j_up) + if (v < j_up) r |= CTL_UP; - if (v >= j_down) + if (v > j_down) r |= CTL_DOWN; v = read_axis(AXISX); - if (v <= j_left) + if (v < j_left) r |= CTL_LEFT; - if (v >= j_right) + if (v > j_right) r |= CTL_RIGHT; return r; -- cgit v1.2.3