From 6091c727763670101c95dc0d8b6aee9cd1ea53fa Mon Sep 17 00:00:00 2001 From: beerpsi Date: Fri, 25 Jul 2025 08:40:44 +0700 Subject: [PATCH] fix laverita v2 support --- .cargo/config.toml | 2 ++ .gitignore | 3 +- build-all.sh | 16 +++++++--- src/backends/laverita_v2.rs | 58 ++++++++++--------------------------- 4 files changed, 31 insertions(+), 48 deletions(-) create mode 100644 .cargo/config.toml mode change 100644 => 100755 build-all.sh diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..33806ae --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "x86_64-pc-windows-msvc" diff --git a/.gitignore b/.gitignore index a803f50..da8f525 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/dist \ No newline at end of file +/dist +.xwin-cache diff --git a/build-all.sh b/build-all.sh old mode 100644 new mode 100755 index d595b0f..ba39b47 --- a/build-all.sh +++ b/build-all.sh @@ -3,14 +3,22 @@ mkdir -p dist/chusan mkdir -p dist/chuni +PLATFORM="$(uname -s)" + +if [ "${PLATFORM:0:5}" != "MINGW" ]; then + CARGO="cargo xwin" +else + CARGO="cargo" +fi + for backend in tasoller_v1 tasoller_v2 laverita_v2 laverita_v3 tasoller_plus do - cargo build --target i686-pc-windows-msvc --release --features chusan,$backend - cargo build --target x86_64-pc-windows-msvc --release --features chusan,$backend - + $CARGO build --target i686-pc-windows-msvc --release --features chusan,$backend + $CARGO build --target x86_64-pc-windows-msvc --release --features chusan,$backend + cp target/i686-pc-windows-msvc/release/chuniio_rs.dll dist/chusan/chuniio_${backend}_x86.dll cp target/x86_64-pc-windows-msvc/release/chuniio_rs.dll dist/chusan/chuniio_${backend}_x64.dll - cargo build --target i686-pc-windows-msvc --release --features $backend + $CARGO build --target i686-pc-windows-msvc --release --features $backend cp target/i686-pc-windows-msvc/release/chuniio_rs.dll dist/chuni/chuniio_${backend}.dll done diff --git a/src/backends/laverita_v2.rs b/src/backends/laverita_v2.rs index 0878f81..b4e739d 100644 --- a/src/backends/laverita_v2.rs +++ b/src/backends/laverita_v2.rs @@ -1,25 +1,6 @@ //! # Yuancon Laverita v2 //! (does anyone still use this?) //! -//! Notes: I'm getting conflicting information on the protocol. -//! CrazyRedMachine is claiming that there is [a leading byte][1], while 4yn's -//! [slidershim][2] as well as their earlier [Yuancon HID test script][3] is -//! claiming the opposite. This implementation is based on CrazyRedMachine, -//! since the chuniio open-sourced by ZhouSensor himself seems to agree. -//! -//! -//! ```c -//! struct outputdata_gaosan -//! { -//! unsigned char Address; -//! unsigned char Touch[62]; -//! }OutputDataGaosan; -//! ``` -//! -//! [1]: https://github.com/CrazyRedMachine/yuancon_laverita_v2-docs/blob/main/pcb_protocol/hid_reports.txt -//! [2]: https://github.com/4yn/slidershim/blob/main/src-slider_io/src/device/hid.rs#L174-L207 -//! [3]: https://gist.github.com/4yn/53a6b6b681e40fd5658bf5b7f9fe9c15 -//! //! USB device: 1973:2001 //! //! USB interface: 0 @@ -27,19 +8,17 @@ //! ## Protocol information //! //! ### IN Interrupt (0x81) -//! - Content length: 35 bytes -//! - Byte 0: ReportID 0x00 -//! - Byte 1: Air sensors, from lowest to highest bit {2, 1, 4, 3, 6, 5} -//! - Byte 2: +//! - Content length: 34 bytes +//! - Byte 0: Air sensors, from lowest to highest bit {2, 1, 4, 3, 6, 5} +//! - Byte 1: //! - Bit 0: Test //! - Bit 1: Service //! - Bit 2: Coin -//! - Bytes 3..35: Slider pressure (bottom -> top, then left -> right) +//! - Bytes 2..34: Slider pressure (bottom -> top, then left -> right) //! //! ### OUT Interrupt (0x02) -//! - Content length: 63 bytes -//! - Byte 0: ReportID 0x00 -//! - Byte 1..63: Slider LED data (right -> left) +//! - Content length: 62 bytes +//! - Byte 0..62: Slider LED data (right -> left) //! - Each LED is controlled by 2 bytes: GGGG GRRR (second byte) | RRRB BBBB (first byte) #[cfg(any(chuni, chusanapp))] @@ -47,8 +26,8 @@ use anyhow::Result; #[cfg(any(chuni, chusanapp))] use rusb::{DeviceHandle, UsbContext}; -use crate::TIMEOUT; use super::ReadType; +use crate::TIMEOUT; pub const DEVICE_VID: u16 = 0x1973; pub const DEVICE_PID: u16 = 0x2001; @@ -60,7 +39,6 @@ pub const OUTPUT_MEMORY_SIZE: usize = std::mem::size_of::(); #[repr(C)] struct LaveritaV2Input { - pub report_id: u8, pub ir: u8, pub buttons: u8, pub slider_pressure: [u8; 32], @@ -68,7 +46,6 @@ struct LaveritaV2Input { #[repr(C)] struct LaveritaV2Output { - pub report_id: u8, pub slider_led: [u8; 62], } @@ -111,7 +88,7 @@ pub fn is_coin_button_pressed(input: &[u8]) -> bool { /// and going from top to bottom, right to left. /// /// ```ignore -/// ^^ Towards screen ^^ +/// ^^ Towards screen ^^ /// ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ /// 30 | 28 | 26 | 24 | 22 | 20 | 18 | 16 | 14 | 12 | 10 | 8 | 6 | 4 | 2 | 0 | /// ----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+ @@ -135,13 +112,7 @@ pub fn read_pressure_data(input: &[u8]) -> [u8; 32] { /// (e.g. set magic bytes). #[cfg(any(chuni, chusanapp))] #[inline(always)] -pub fn init_output_buffer(output: &mut [u8]) { - let output = output.as_mut_ptr() as *mut LaveritaV2Output; - - unsafe { - (*output).report_id = 0; - } -} +pub fn init_output_buffer(_output: &mut [u8]) {} /// Update the RGB lighting on the slider. A slice `rgb` is provided, alternating /// between 16 touch pad pixels and 15 divider pixels, going from right to left. @@ -155,16 +126,17 @@ pub fn set_slider_leds( unsafe { let output = output.as_mut_ptr() as *mut LaveritaV2Output; - for (buf_chunk, state_chunk) in (*output).slider_led + for (buf_chunk, state_chunk) in (*output) + .slider_led .chunks_mut(2) .take(31) - .zip(brg.chunks(3)) + .zip(brg.chunks(3)) { - buf_chunk[0] = (state_chunk[0] << 3 & 0xE0) | (state_chunk[2] >> 3); - buf_chunk[1] = (state_chunk[1] & 0xF8) | (state_chunk[0] >> 5); + buf_chunk[0] = (state_chunk[1] << 3 & 0xE0) | (state_chunk[0] >> 3); + buf_chunk[1] = (state_chunk[2] & 0xF8) | (state_chunk[1] >> 5); } } - + device.write_interrupt(0x02, output, TIMEOUT)?; Ok(())