2 releases
0.1.1 | Aug 19, 2020 |
---|---|
0.1.0 | Aug 19, 2020 |
#879 in Hardware support
8KB
162 lines
Getting Started| Documentation | | Blog
dual-shock4-controller
Sony DualShock 4 Controller for Rust
Dependencies
Add this to your Cargo.toml
:
dual-shock4-controller = "0.1.0"
How To Use
use dual_shock4_controller::joystick::{DeviceInfo,Joystick};
let joystick = Joystick::new();
let device_info = DeviceInfo{vid:0x054c,pid:0x05c4};//HID\VID_054C&PID_05C4\7&3869AC07&0&0000
let device = joystick.connect(device_info).expect("can't find device!");//
loop {
let mut buf = [0u8;64];
device.read_timeout(&mut buf[..], 1000).unwrap();
let gamepad = joystick.get_gamepad().get_state(&buf);
if gamepad.x_button.pressed {
println!("× button is pressed");
break;
}
}
License
This repository is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution Licensing
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies
~0.4–0.8MB
~15K SLoC