diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index aaa4051..82a29f4 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -621,7 +621,7 @@ dependencies = [ [[package]] name = "ds" version = "1.3.0" -source = "git+https://github.com/spacey-sooty/ds-rs.git?branch=updatedeps#bcbcdf7b2ccf220eb6c54455428ceeb0df99ce7b" +source = "git+https://github.com/spacey-sooty/ds-rs.git?branch=serialize-joystickval#9a84e666494173ec24d6bc444333d029d04dcb84" dependencies = [ "bitflags 2.6.0", "byteorder", @@ -633,6 +633,7 @@ dependencies = [ "futures-channel", "futures-util", "rand 0.8.5", + "serde", "smallvec", "tokio", "tokio-stream", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 8c6b8fb..c5f6b08 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -13,7 +13,7 @@ tauri-build = { version = "1", features = [] } [dependencies] tauri = { version = "1", features = ["shell-open"] } serde = { version = "1", features = ["derive"] } -ds = { git = "https://github.com/spacey-sooty/ds-rs.git", branch = "updatedeps" } +ds = { git = "https://github.com/spacey-sooty/ds-rs.git", branch = "serialize-joystickval" } gilrs = { version = "0.10.9", features = ["serde", "serde-serialize"] } tokio = "1.40.0" once_cell = "1.19.0" diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 7a9786a..27ce19f 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -130,6 +130,41 @@ fn send_packet_no_last( ds.set_mode(packet.mode.0); } +#[tauri::command] +async fn last_packet(last_packet: State<'_, Lazy>>) -> Result { + Ok(last_packet.read().await.clone()) // FIXME slow +} + +#[tauri::command] +async fn battery_voltage(state: State<'_, Lazy>>) -> Result { + Ok(state.read().await.ds.as_ref().unwrap().battery_voltage()) +} + +#[tauri::command] +fn joystick_values() -> Vec> { + let gilrs = Gilrs::new().expect("Should be able to load Gilrs."); + let mut out: Vec> = vec![]; + for (_id, gamepad) in gilrs.gamepads() { + let mut values: Vec = vec![]; + for i in BUTTONS { + values.push(JoystickValue::Button { + id: i as u8, + pressed: gamepad.is_pressed(i), + }) + } + + for i in AXIS { + values.push(JoystickValue::Axis { + id: i as u8, + value: gamepad.value(i), + }) + } + + out.push(values); + } + out +} + #[tauri::command] async fn send_packet( last_packet: State<'_, Lazy>>, @@ -314,7 +349,10 @@ fn main() { restart_code, estop, enable, - disable + disable, + last_packet, + battery_voltage, + joystick_values, ]) .run(tauri::generate_context!()) .expect("error while running tauri application");