viiper_client/devices/dualshock4/
input.rs1use crate::wire::DeviceInput;
4
5#[derive(Debug, Clone, Default)]
6pub struct Dualshock4Input {
7 pub stick_lx: i8,
8 pub stick_ly: i8,
9 pub stick_rx: i8,
10 pub stick_ry: i8,
11 pub buttons: u16,
12 pub dpad: u8,
13 pub trigger_l2: u8,
14 pub trigger_r2: u8,
15 pub touch1x: u16,
16 pub touch1y: u16,
17 pub touch1_active: u8,
18 pub touch2x: u16,
19 pub touch2y: u16,
20 pub touch2_active: u8,
21 pub gyro_x: i16,
22 pub gyro_y: i16,
23 pub gyro_z: i16,
24 pub accel_x: i16,
25 pub accel_y: i16,
26 pub accel_z: i16,
27}
28
29impl DeviceInput for Dualshock4Input {
30 fn to_bytes(&self) -> Vec<u8> {
31 let mut buf = Vec::new();
32 buf.extend_from_slice(&self.stick_lx.to_le_bytes());
33 buf.extend_from_slice(&self.stick_ly.to_le_bytes());
34 buf.extend_from_slice(&self.stick_rx.to_le_bytes());
35 buf.extend_from_slice(&self.stick_ry.to_le_bytes());
36 buf.extend_from_slice(&self.buttons.to_le_bytes());
37 buf.extend_from_slice(&self.dpad.to_le_bytes());
38 buf.extend_from_slice(&self.trigger_l2.to_le_bytes());
39 buf.extend_from_slice(&self.trigger_r2.to_le_bytes());
40 buf.extend_from_slice(&self.touch1x.to_le_bytes());
41 buf.extend_from_slice(&self.touch1y.to_le_bytes());
42 buf.extend_from_slice(&self.touch1_active.to_le_bytes());
43 buf.extend_from_slice(&self.touch2x.to_le_bytes());
44 buf.extend_from_slice(&self.touch2y.to_le_bytes());
45 buf.extend_from_slice(&self.touch2_active.to_le_bytes());
46 buf.extend_from_slice(&self.gyro_x.to_le_bytes());
47 buf.extend_from_slice(&self.gyro_y.to_le_bytes());
48 buf.extend_from_slice(&self.gyro_z.to_le_bytes());
49 buf.extend_from_slice(&self.accel_x.to_le_bytes());
50 buf.extend_from_slice(&self.accel_y.to_le_bytes());
51 buf.extend_from_slice(&self.accel_z.to_le_bytes());
52 buf
53 }
54}