readhid/
readhid.rs

1/****************************************************************************
2    Copyright (c) 2015 Osspial All Rights Reserved.
3
4    This file is part of hidapi-rs, based on hidapi_rust by Roland Ruckerbauer.
5****************************************************************************/
6
7//! Opens a Thrustmaster T-Flight HOTAS X HID and reads data from it. This
8//! example will not work unless such an HID is plugged in to your system.
9//! Will update in the future to support all HIDs.
10
11#[cfg(all(feature = "linux-static-rusb", not(target_os = "macos")))]
12extern crate rusb;
13
14extern crate hidapi_rusb;
15use hidapi_rusb::HidApi;
16
17fn main() {
18    let api = HidApi::new().expect("Failed to create API instance");
19
20    let joystick = api.open(1103, 45320).expect("Failed to open device");
21
22    loop {
23        let mut buf = [0u8; 256];
24        let res = joystick.read(&mut buf[..]).unwrap();
25
26        let mut data_string = String::new();
27
28        for u in &buf[..res] {
29            data_string.push_str(&(u.to_string() + "\t"));
30        }
31
32        println!("{}", data_string);
33    }
34}