fix coin debouncing

This commit is contained in:
beerpsi 2024-01-02 19:11:26 +07:00
parent a1790a9a48
commit 74e8e2a122
2 changed files with 6 additions and 7 deletions

View File

@ -55,9 +55,8 @@ pub const OUTPUT_MEMORY_SIZE: usize = 240;
#[inline(always)] #[inline(always)]
pub fn jvs_poll(input: &[u8]) -> (u8, u8) { pub fn jvs_poll(input: &[u8]) -> (u8, u8) {
// FN1 | FN2 // FN1 | FN2
let opbtn = input[3] >> 3 & 1 let opbtn = input[3] >> 3 & 1 | input[3] >> 1 & 2;
| input[3] >> 1 & 2;
// IR1-6 in order // IR1-6 in order
let beams = input[3] >> 5 & 1 let beams = input[3] >> 5 & 1
| input[3] >> 3 & 2 | input[3] >> 3 & 2

View File

@ -69,7 +69,7 @@ cfg_if::cfg_if! {
use crate::configuration::Configuration; use crate::configuration::Configuration;
static COIN_COUNT: AtomicU16 = AtomicU16::new(0); static COIN_COUNT: AtomicU16 = AtomicU16::new(0);
static COIN_PRESSED: AtomicBool = AtomicBool::new(false); static mut COIN_PRESSED: bool = false;
lazy_static! { lazy_static! {
static ref CONFIGURATION: Configuration = { 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()) if con_impl::is_coin_button_pressed(input_shmem.as_slice())
|| GetAsyncKeyState(CONFIGURATION.coin_key as c_int) != 0 || GetAsyncKeyState(CONFIGURATION.coin_key as c_int) != 0
{ {
let coin_previously_pressed = COIN_PRESSED.fetch_xor(true, Ordering::Relaxed); if !COIN_PRESSED {
if !coin_previously_pressed { COIN_PRESSED = true;
COIN_COUNT.fetch_add(1, Ordering::Relaxed); COIN_COUNT.fetch_add(1, Ordering::Relaxed);
} }
} else { } else {
COIN_PRESSED.store(false, Ordering::Relaxed); COIN_PRESSED = false;
} }
*total = COIN_COUNT.load(Ordering::Relaxed); *total = COIN_COUNT.load(Ordering::Relaxed);