diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-08-11 21:04:54 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-08-11 21:04:54 +0100 |
commit | 43503cfa510a7f7e650efccaac266d7cc6657a5d (patch) | |
tree | f0fc2a9b480f413f8f0bab25bd97170b17a794b8 /src/joy.c | |
parent | cd2296358a03ab9ca4d6c017262735eaa63b5fdb (diff) | |
download | gold-mine-run-1.2.tar.gz gold-mine-run-1.2.zip |
Better koystick support1.2
Diffstat (limited to 'src/joy.c')
-rw-r--r-- | src/joy.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -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; |