From abc32325de71e100e004533cf6332bca1ce5e77b Mon Sep 17 00:00:00 2001 From: Brendan Robert Date: Wed, 6 Mar 2024 16:47:43 -0600 Subject: [PATCH] add configurable dead-zone and tester program --- .../tools/jace/src/main/java/jace/hardware/Joystick.java | 8 ++++++++ .../src/main/resources/samplePrograms/joystick_test.bas | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 Platform/Apple/tools/jace/src/main/resources/samplePrograms/joystick_test.bas diff --git a/Platform/Apple/tools/jace/src/main/java/jace/hardware/Joystick.java b/Platform/Apple/tools/jace/src/main/java/jace/hardware/Joystick.java index 27587dc1..0388caad 100644 --- a/Platform/Apple/tools/jace/src/main/java/jace/hardware/Joystick.java +++ b/Platform/Apple/tools/jace/src/main/java/jace/hardware/Joystick.java @@ -93,6 +93,8 @@ public class Joystick extends Device { public boolean useDPad = false; @ConfigurableField(name = "Timer resolution", shortName = "timerres", description = "How many ticks until we poll the buttons again?") public static long TIMER_RESOLUTION = TimedDevice.NTSC_1MHZ / 15; // 15FPS resolution reads when joystick is not used + @ConfigurableField(name = "Dead Zone", shortName = "deadZone", description = "Dead zone for joystick (0-1)") + public static float deadZone = 0.1f; Integer controllerNumber = null; @@ -192,6 +194,12 @@ public class Joystick extends Device { y = 0; } } + if (Math.abs(x) < deadZone) { + x = 0; + } + if (Math.abs(y) < deadZone) { + y = 0; + } joyX = (int) (x * 128.0 + 128.0); joyY = (int) (y * 128.0 + 128.0); diff --git a/Platform/Apple/tools/jace/src/main/resources/samplePrograms/joystick_test.bas b/Platform/Apple/tools/jace/src/main/resources/samplePrograms/joystick_test.bas new file mode 100644 index 00000000..b34b913c --- /dev/null +++ b/Platform/Apple/tools/jace/src/main/resources/samplePrograms/joystick_test.bas @@ -0,0 +1,2 @@ +0 REM Joystick test, shows X and Y position of joystick and button state +10 ? pdl(0), pdl(1), peek(49249)>127; " "; peek(49250)>127:goto 10 \ No newline at end of file