From 74e8e2a122839c2f066f4a9d387b83942fa9db24 Mon Sep 17 00:00:00 2001 From: beerpsi Date: Tue, 2 Jan 2024 19:11:26 +0700 Subject: [PATCH] fix coin debouncing --- src/backends/tasoller_v1.rs | 5 ++--- src/lib.rs | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/backends/tasoller_v1.rs b/src/backends/tasoller_v1.rs index 737fda3..67d1c9c 100644 --- a/src/backends/tasoller_v1.rs +++ b/src/backends/tasoller_v1.rs @@ -55,9 +55,8 @@ pub const OUTPUT_MEMORY_SIZE: usize = 240; #[inline(always)] pub fn jvs_poll(input: &[u8]) -> (u8, u8) { // FN1 | FN2 - let opbtn = input[3] >> 3 & 1 - | input[3] >> 1 & 2; - + let opbtn = input[3] >> 3 & 1 | input[3] >> 1 & 2; + // IR1-6 in order let beams = input[3] >> 5 & 1 | input[3] >> 3 & 2 diff --git a/src/lib.rs b/src/lib.rs index 83064ac..6adf591 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,7 +69,7 @@ cfg_if::cfg_if! { use crate::configuration::Configuration; static COIN_COUNT: AtomicU16 = AtomicU16::new(0); - static COIN_PRESSED: AtomicBool = AtomicBool::new(false); + static mut COIN_PRESSED: bool = false; lazy_static! { static ref CONFIGURATION: Configuration = { @@ -182,12 +182,12 @@ pub unsafe extern "C" fn chuni_io_jvs_read_coin_counter(total: *mut u16) { if con_impl::is_coin_button_pressed(input_shmem.as_slice()) || GetAsyncKeyState(CONFIGURATION.coin_key as c_int) != 0 { - let coin_previously_pressed = COIN_PRESSED.fetch_xor(true, Ordering::Relaxed); - if !coin_previously_pressed { + if !COIN_PRESSED { + COIN_PRESSED = true; COIN_COUNT.fetch_add(1, Ordering::Relaxed); } } else { - COIN_PRESSED.store(false, Ordering::Relaxed); + COIN_PRESSED = false; } *total = COIN_COUNT.load(Ordering::Relaxed);