fix coin debouncing, IR beams, slider RGB

This commit is contained in:
beerpsi 2024-01-02 19:13:59 +07:00
parent cdf7d49fbe
commit da3196fbe6
5 changed files with 25 additions and 22 deletions

4
Cargo.lock generated
View File

@ -13,7 +13,7 @@ dependencies = [
[[package]]
name = "aimeio-yubideck"
version = "0.1.0"
version = "0.1.2"
dependencies = [
"cfg_aliases",
"faster-hex",
@ -89,7 +89,7 @@ checksum = "77e53693616d3075149f4ead59bdeecd204ac6b8192d8969757601b74bddf00f"
[[package]]
name = "chuniio-yubideck"
version = "0.1.0"
version = "0.1.2"
dependencies = [
"anyhow",
"cfg-if 1.0.0",

View File

@ -6,6 +6,7 @@ ChuniIO driver for YubiDeck FW 3.0.
Thanks to:
- [hlcm0](https://github.com/hlcm0/yubideck-io-firmware/blob/main/code/pico_yubideck_emu/report.h) and [4yn](https://github.com/4yn/slidershim/blob/main/src-slider_io/src/device/hid.rs#L257)
for YubiDeck protocol information
- one_3 for testing
## Configuration
segatools.ini
@ -30,9 +31,9 @@ USB device: `1973:2001`, interface 0
- Endpoint IN Interrupt (0x81)
- Data length: 45 bytes
- `data[0]`: bits 0-5: beam 1-6 (1 = blocked)
- `data[0]`: bits 0-5: beam {2, 1, 4, 3, 6, 5}
- `data[1]`: bits 0-2 for the 3 buttons (1 = pressed)
- `data[2..34]`: pressure of touch sensor 1-32 (counting from top left)
- `data[2..34]`: pressure of touch sensor 1-32 (counting from top -> bottom, left -> right)
- `data[34]`: Card type
- 0: No card
- 1: MIFARE Classic
@ -43,9 +44,9 @@ USB device: `1973:2001`, interface 0
- Data length: 61 bytes
- `data[0]`: Packet type
- Packet type 1:
- `data[1..61]`: Slider LED for the first 20 sensors, RGB
- `data[1..61]`: Slider LED for the first 20 sensors, GBR
- Packet type 2:
- `data[1..34]`: Slider LED for the last 11 sensors, RGB
- `data[1..34]`: Slider LED for the last 11 sensors, GBR
- `data[34..37]`: Left air LED, RGB
- `data[37..40]`: Right air LED, RGB
- `data[40..43]`: Card reader LED, RGB

View File

@ -1,6 +1,6 @@
[package]
name = "aimeio-yubideck"
version = "0.1.0"
version = "0.1.2"
edition = "2021"
[lib]

View File

@ -1,6 +1,6 @@
[package]
name = "chuniio-yubideck"
version = "0.1.0"
version = "0.1.2"
edition = "2021"
[lib]

View File

@ -6,7 +6,7 @@ use std::{
ffi::c_void,
rc::Rc,
sync::{
atomic::{AtomicBool, Ordering},
atomic::Ordering,
Mutex,
},
};
@ -28,7 +28,7 @@ static mut OUTPUT_SHMEM: Option<Rc<Mutex<Shmem>>> = None;
cfg_if::cfg_if! {
if #[cfg(any(chuni, chusanapp))] {
use std::{
sync::OnceLock,
sync::{OnceLock, atomic::AtomicBool},
thread::{self, JoinHandle},
time::Duration,
};
@ -57,7 +57,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 = {
@ -160,7 +160,9 @@ pub unsafe extern "C" fn chuni_io_jvs_poll(opbtn: *mut u8, beams: *mut u8) {
}
*opbtn = buttons;
*beams = ir_value;
// Swap adjacent bit pairs
*beams = ((ir_value & 0xAA) >> 1) | ((ir_value & 0x55) << 1);
}
#[no_mangle]
@ -174,19 +176,19 @@ pub unsafe extern "C" fn chuni_io_jvs_read_coin_counter(total: *mut u16) {
return;
}
let Some(input_shmem) = (unsafe { &INPUT_SHMEM }) else {
let Some(input_shmem) = &INPUT_SHMEM else {
return;
};
let input = unsafe { input_shmem.as_slice() };
let coin_pressed = (input[1] & 4) != 0;
if coin_pressed || unsafe { 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);
@ -296,18 +298,18 @@ pub unsafe extern "C" fn chuni_io_slider_set_leds(rgb: *const u8) {
.chunks_mut(3)
.zip(ground.chunks(3).take(20))
{
buf_chunk[0] = state_chunk[0];
buf_chunk[1] = state_chunk[1];
buf_chunk[2] = state_chunk[2];
buf_chunk[0] = state_chunk[1];
buf_chunk[1] = state_chunk[2];
buf_chunk[2] = state_chunk[0];
}
for (buf_chunk, state_chunk) in buf[62..95]
.chunks_mut(3)
.zip(ground.chunks(3).skip(20).take(11))
{
buf_chunk[0] = state_chunk[0];
buf_chunk[1] = state_chunk[1];
buf_chunk[2] = state_chunk[2];
buf_chunk[0] = state_chunk[1];
buf_chunk[1] = state_chunk[2];
buf_chunk[2] = state_chunk[0];
}
if let Err(e) = device.write_interrupt(0x02, &buf[0..61], TIMEOUT) {