Skip to content

Commit 9b4281d

Browse files
authored
fix(FlyDigi Vader 4 Pro): Finish gyro and improve poll rate
1 parent 6927752 commit 9b4281d

File tree

5 files changed

+64
-148
lines changed

5 files changed

+64
-148
lines changed

src/drivers/flydigi_vader_4_pro/driver.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use std::{error::Error, ffi::CString};
1+
use std::{error::Error, f32::consts::PI, ffi::CString};
22

33
use hidapi::HidDevice;
4-
use packed_struct::PackedStruct;
4+
use packed_struct::{types::SizedInteger, PackedStruct};
55

66
use crate::{drivers::flydigi_vader_4_pro::hid_report::Direction, udev::device::UdevDevice};
77

88
use super::{
99
event::{
10-
BinaryInput, ButtonEvent, Event, JoystickEvent, JoystickInput, TriggerEvent, TriggerInput,
10+
BinaryInput, ButtonEvent, Event, InertialEvent, InertialInput, JoystickEvent,
11+
JoystickInput, TriggerEvent, TriggerInput,
1112
},
1213
hid_report::PackedInputDataReport,
1314
};
@@ -16,7 +17,7 @@ use super::{
1617
pub const REPORT_ID: u8 = 0x04;
1718

1819
// Input report size
19-
const PACKET_SIZE: usize = 31;
20+
const PACKET_SIZE: usize = 32;
2021

2122
// HID buffer read timeout
2223
const HID_TIMEOUT: i32 = 10;
@@ -280,21 +281,20 @@ impl Driver {
280281
})));
281282
}
282283

283-
// // Accelerometer events
284-
// events.push(Event::Inertia(InertialEvent::Accelerometer(
285-
// InertialInput {
286-
// x: -state.accel_x.to_primitive(),
287-
// y: state.accel_y.to_primitive(),
288-
// z: -state.accel_z.to_primitive(),
289-
// },
290-
// )));
291-
// events.push(Event::Inertia(InertialEvent::Gyro(InertialInput {
292-
// x: -state.gyro_x.to_primitive(),
293-
// y: state.gyro_y.to_primitive(),
294-
// z: -state.gyro_z.to_primitive(),
295-
// })));
296-
297-
//log::trace!("Got events: {events:?}");
284+
// Accelerometer events
285+
events.push(Event::Inertia(InertialEvent::Accelerometer(
286+
InertialInput {
287+
x: -state.accel_x.to_primitive(),
288+
y: state.accel_y.to_primitive(),
289+
z: state.accel_z.to_primitive(),
290+
},
291+
)));
292+
// Gyro events. They need to be rotated in order for them to be read properly
293+
events.push(Event::Inertia(InertialEvent::Gyro(InertialInput {
294+
x: -(state.gyro_x.to_primitive() as i32 * 1143239 / i16::MAX as i32) as i16,
295+
y: -(state.get_y() as i32 * 1143239 / i16::MAX as i32) as i16,
296+
z: -(state.gyro_z.to_primitive() as i32 * 17873 / i16::MAX as i32) as i16,
297+
})));
298298
events
299299
}
300300
}

src/drivers/flydigi_vader_4_pro/event.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[derive(Clone, Debug)]
33
pub enum Event {
44
Button(ButtonEvent),
5-
// Inertia(InertialEvent),
5+
Inertia(InertialEvent),
66
Joystick(JoystickEvent),
77
Trigger(TriggerEvent),
88
}
@@ -66,9 +66,8 @@ pub enum ButtonEvent {
6666
DPadLeft(BinaryInput),
6767
}
6868

69-
/*
7069
/// [InertialInput] represents the state of the IMU (x, y, z) values
71-
#[derive(Clone, Debug)]
70+
#[derive(Clone, Debug)]
7271
pub struct InertialInput {
7372
pub x: i16,
7473
pub y: i16,
@@ -81,7 +80,6 @@ pub enum InertialEvent {
8180
Accelerometer(InertialInput),
8281
Gyro(InertialInput),
8382
}
84-
*/
8583

8684
/// [JoystickInput] is a double (x, y) axis
8785
#[derive(Clone, Debug)]

src/drivers/flydigi_vader_4_pro/hid_report.rs

Lines changed: 40 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -16,121 +16,9 @@ pub enum Direction {
1616
None = 0,
1717
}
1818

19-
/* No Input
20-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0 , 1 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
21-
E: 000656.420862 32 04 fe 66 00 00 00 00 00 00 00 00 00 00 ff ff 00 01 7f 00 7f 00 7f 7f 00 00 00 00 00 00 00 00 00
22-
Axes
23-
Left Stick Right
24-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0 , 1 , -1 , 0 , -104 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0
25-
E: 000109.259324 32 04 fe 66 00 00 00 00 00 00 00 00 00 00 ff ff 00 01 ff 00 98 00 7f 7f 00 00 00 00 00 00 ff ff 00
26-
Left Stick Left
27-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 1 , 0 , -1 , 0 , 0 , 0 , -111 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
28-
E: 000052.417154 32 04 fe 66 00 00 00 00 00 00 00 00 ff ff 01 00 ff 00 00 00 91 00 7f 7f 00 00 00 00 00 00 01 00 00
29-
Left Stick Up
30-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0 , 0 , 0 , 1 , 126 , 0 , 0 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0
31-
E: 000008.126338 32 04 fe 66 00 00 00 00 00 00 00 00 ff ff 00 00 00 01 7e 00 00 00 7f 7f 00 00 00 00 00 00 ff ff 00
32-
Left Stick Down
33-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , -1 , 1 , 1 , 114 , 0 , -1 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
34-
E: 000003.707317 32 04 fe 66 00 00 00 00 00 00 00 00 ff ff ff ff 01 01 72 00 ff 00 7f 7f 00 00 00 00 00 00 01 00 00
35-
Right Stick Right
36-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0 , 1 , 127 , 0 , 127 , 0 , -1 , -114 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0
37-
E: 000005.187013 32 04 fe 66 00 00 00 00 00 00 00 00 00 00 ff ff 00 01 7f 00 7f 00 ff 8e 00 00 00 00 00 00 ff ff 00
38-
Right Stick Left
39-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0 , 1 , 127 , 0 , 127 , 0 , 0 , 110 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
40-
E: 000003.744066 32 04 fe 66 00 00 00 00 00 00 00 00 00 00 ff ff 00 01 7f 00 7f 00 00 6e 00 00 00 00 00 00 01 00 00
41-
Right Stick Up
42-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , -121 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
43-
E: 000002.917458 32 04 fe 66 00 00 00 00 00 00 00 00 00 00 00 00 ff 00 7f 00 7f 00 87 00 00 00 00 00 00 00 00 00 00
44-
Right Stick Down
45-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , 0 , 127 , 0 , 127 , 0 , 116 , -1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
46-
E: 000002.757633 32 04 fe 66 00 00 00 00 00 00 00 00 00 00 ff ff ff 00 7f 00 7f 00 74 ff 00 00 00 00 00 00 01 00 00
47-
Left Trigger
48-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 16 , -1 , -1 , 0 , 0 , 0 , 1 , 126 , 0 , 127 , 0 , 127 , 127 , -1 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
49-
E: 000009.594140 32 04 fe 66 00 00 00 00 00 00 00 10 ff ff 00 00 00 01 7e 00 7f 00 7f 7f ff 00 00 00 00 00 01 00 00
50-
Right Trigger
51-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 32 , -1 , -1 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , -1 , 0 , 0 , 0 , 0 , 2 , 0 , 0
52-
E: 000003.136588 32 04 fe 66 00 00 00 00 00 00 00 20 ff ff 00 00 ff 00 7f 00 7f 00 7f 7f 00 ff 00 00 00 00 02 00 00
53-
Buttons
54-
South
55-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 16 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0
56-
E: 000006.258012 32 04 fe 66 00 00 00 00 00 00 10 00 00 00 00 00 00 01 7f 00 7f 00 7f 7f 00 00 00 00 00 00 02 00 00
57-
East
58-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 32 , 0 , 0 , 0 , 1 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
59-
E: 000002.349215 32 04 fe 66 00 00 00 00 00 00 20 00 00 00 01 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 01 00 00
60-
West
61-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , -128 , 0 , -1 , -1 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
62-
E: 000001.954331 32 04 fe 66 00 00 00 00 00 00 80 00 ff ff 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 00 00 00
63-
North
64-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
65-
E: 000004.489848 32 04 fe 66 00 00 00 00 00 00 00 01 00 00 01 00 00 01 7f 00 7f 00 7f 7f 00 00 00 00 00 00 00 00 00
66-
Start
67-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , -1 , -1 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
68-
E: 000001.711024 32 04 fe 66 00 00 00 00 00 00 00 02 ff ff 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 01 00 00
69-
Select
70-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 64 , 0 , -1 , -1 , 1 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , -2 , -1 , 0
71-
E: 000002.145533 32 04 fe 66 00 00 00 00 00 00 40 00 ff ff 01 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 fe ff 00
72-
Home
73-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 8 , 0 , 0 , -1 , -1 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0
74-
E: 000010.383148 32 04 fe 66 00 00 00 00 00 08 00 00 ff ff 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 02 00 00
75-
Fn
76-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
77-
E: 000002.236405 32 04 fe 66 00 00 00 00 00 01 00 00 00 00 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 00 00 00
78-
DPadUp
79-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , -1 , -1 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
80-
E: 000002.584032 32 04 fe 66 00 00 00 00 00 00 01 00 ff ff 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 00 00 00
81-
DPadLeft
82-
# ReportID: 4 / 0xffa00003: -2 , 102 , -128 , 0 , 0 , 0 , 0 , 0 , 8 , 0 , -1 , -1 , 0 , 0 , 0 , 1 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
83-
E: 000003.504922 32 04 fe 66 80 00 00 00 00 00 08 00 ff ff 00 00 00 01 7f 00 7f 00 7f 7f 00 00 00 00 00 00 00 00 00
84-
DPadRight
85-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , -1 , -1 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0
86-
E: 000003.211043 32 04 fe 66 00 00 00 00 00 00 02 00 ff ff 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 ff ff 00
87-
DPadDown
88-
# ReportID: 4 / 0xffa00003: -2 , 102 , -128 , 0 , 0 , 0 , 0 , 0 , 4 , 0 , -1 , -1 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0
89-
E: 000002.955382 32 04 fe 66 80 00 00 00 00 00 04 00 ff ff 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 ff ff 00
90-
Left Bumper
91-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 4 , 0 , 0 , 0 , 0 , 0 , 1 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0
92-
E: 000002.911595 32 04 fe 66 00 00 00 00 00 00 00 04 00 00 00 00 00 01 7f 00 7f 00 7f 7f 00 00 00 00 00 00 ff ff 0
93-
Right Bumper
94-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 8 , -1 , -1 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0
95-
E: 000002.106028 32 04 fe 66 00 00 00 00 00 00 00 08 ff ff 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 02 00 00
96-
Left Stick Click
97-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 64 , -2 , -1 , 2 , 0 , -1 , 0 , -114 , 0 , 121 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0
98-
E: 000004.851067 32 04 fe 66 00 00 00 00 00 00 00 40 fe ff 02 00 ff 00 8e 00 79 00 7f 7f 00 00 00 00 00 00 02 00 00
99-
Right Stick Click
100-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -128 , 0 , 0 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 121 , -122 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
101-
E: 000004.682061 32 04 fe 66 00 00 00 00 00 00 00 80 00 00 00 00 ff 00 7f 00 7f 00 79 86 00 00 00 00 00 00 00 00 00
102-
C
103-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
104-
E: 000002.379578 32 04 fe 66 00 00 00 00 01 00 00 00 00 00 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 00 00 00
105-
Z
106-
# ReportID: 4 / 0xffa00003: -2 , 102 , -128 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
107-
E: 000005.520075 32 04 fe 66 80 00 00 00 02 00 00 00 00 00 00 00 ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 01 00 00
108-
Left Paddle 1
109-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , 0
110-
E: 000034.390789 32 04 fe 66 00 00 00 00 08 00 00 00 00 00 00 00 00 01 7f 00 7f 00 7f 7f 00 00 00 00 00 00 ff ff 00
111-
Left Paddle 2
112-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 32 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0
113-
E: 000002.776952 32 04 fe 66 00 00 00 00 20 00 00 00 00 00 00 00 00 01 7f 00 7f 00 7f 7f 00 00 00 00 00 00 02 00 00
114-
Right Paddle 1
115-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 4 , 0 , 0 , 0 , 0 , 0 , -1 , -1 , -1 , 0 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0
116-
E: 000003.023968 32 04 fe 66 00 00 00 00 04 00 00 00 00 00 ff ff ff 00 7f 00 7f 00 7f 7f 00 00 00 00 00 00 00 00 00
117-
Right Paddle 2
118-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 0 , 0 , 0 , 16 , 0 , 0 , 0 , -1 , -1 , 0 , 0 , 0 , 1 , 127 , 0 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0
119-
E: 000004.290462 32 04 fe 66 00 00 00 00 10 00 00 00 ff ff 00 00 00 01 7f 00 7f 00 7f 7f 00 00 00 00 00 00 01 00 00
120-
Motion
121-
Trying Roll
122-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , -79 , 95 , 0 , 0 , 0 , 0 , 0 , 60 , -1 , -69 , -1 , 11 , 0 , 127 , -79 , 127 , -1 , 127 , 127 , 0 , 0 , 0 , 5 , 0 , 0 , -22 , -15 , 0
123-
E: 000008.921107 32 04 fe 66 00 b1 5f 00 00 00 00 00 3c ff bb ff 0b 00 7f b1 7f ff 7f 7f 00 00 00 05 00 00 ea f1 00
124-
Trying Pitch
125-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , -24 , -49 , 6 , 0 , 0 , 0 , 0 , -37 , -1 , 10 , 1 , -29 , 0 , 127 , -24 , 127 , -1 , 127 , 127 , 0 , 0 , 0 , 108 , 0 , 0 , 99 , 13 , 0
126-
E: 000003.607853 32 04 fe 66 00 e8 cf 06 00 00 00 00 db ff 0a 01 e3 00 7f e8 7f ff 7f 7f 00 00 00 6c 00 00 63 0d 00
127-
Trying Yaw
128-
# ReportID: 4 / 0xffa00003: -2 , 102 , 0 , 79 , 0 , -9 , 0 , 0 , 0 , 0 , 23 , 1 , -37 , -2 , -80 , 0 , 127 , 79 , 127 , 0 , 127 , 127 , 0 , 0 , 0 , 112 , -1 , 0 , 31 , 122 , 0
129-
E: 000004.710162 32 04 fe 66 00 4f 00 f7 00 00 00 00 17 01 db fe b0 00 7f 4f 7f 00 7f 7f 00 00 00 70 ff 00 1f 7a 00 */
130-
13119
/// report for dinput via dongle
13220
#[derive(PackedStruct, Debug, Copy, Clone, PartialEq)]
133-
#[packed_struct(bit_numbering = "msb0", size_bytes = "31")]
21+
#[packed_struct(bit_numbering = "msb0", size_bytes = "32")]
13422
pub struct PackedInputDataReport {
13523
// byte 0
13624
#[packed_field(bytes = "0", endian = "lsb")]
@@ -186,14 +74,30 @@ pub struct PackedInputDataReport {
18674
#[packed_field(bits = "80")]
18775
pub rsclick: bool,
18876

77+
// bytes 11-16 // Accelerometer X Y Z
78+
#[packed_field(bytes = "11..=12", endian = "lsb")]
79+
pub accel_x: Integer<i16, packed_bits::Bits<16>>,
80+
#[packed_field(bytes = "13..-14", endian = "lsb")]
81+
pub accel_y: Integer<i16, packed_bits::Bits<16>>,
82+
#[packed_field(bytes = "15..=16", endian = "lsb")]
83+
pub accel_z: Integer<i16, packed_bits::Bits<16>>,
84+
18985
// byte 17
19086
#[packed_field(bytes = "17", endian = "lsb")]
19187
pub joystick_l_x: u8,
19288

89+
// byte 18 // Half of Gyro Y
90+
#[packed_field(bytes = "18", endian = "lsb")]
91+
pub gyro_y_lo: u8,
92+
19393
// byte 19
19494
#[packed_field(bytes = "19", endian = "lsb")]
19595
pub joystick_l_y: u8,
19696

97+
// Byte 20 // Half of Gyro Y
98+
#[packed_field(bytes = "20", endian = "lsb")]
99+
pub gyro_y_hi: u8,
100+
197101
// byte 21-24
198102
#[packed_field(bytes = "21", endian = "lsb")]
199103
pub joystick_r_x: u8,
@@ -203,6 +107,22 @@ pub struct PackedInputDataReport {
203107
pub lt_analog: u8,
204108
#[packed_field(bytes = "24", endian = "lsb")]
205109
pub rt_analog: u8,
110+
111+
// bytes 26-27 // Gyro X
112+
#[packed_field(bytes = "26..=27", endian = "lsb")]
113+
pub gyro_x: Integer<i16, packed_bits::Bits<16>>,
114+
115+
// bytes 29-30 // Gyro Z
116+
#[packed_field(bytes = "29..=30", endian = "lsb")]
117+
pub gyro_z: Integer<i16, packed_bits::Bits<16>>,
118+
}
119+
120+
impl PackedInputDataReport {
121+
pub fn get_y(&self) -> i16 {
122+
let gyro_y_lo = self.gyro_y_lo as i16;
123+
let gyro_y_hi = (self.gyro_y_hi as i16).rotate_left(8);
124+
gyro_y_hi | gyro_y_lo
125+
}
206126
}
207127

208128
impl Default for PackedInputDataReport {
@@ -236,15 +156,13 @@ impl Default for PackedInputDataReport {
236156
steam: false,
237157
rt_analog: 0,
238158
lt_analog: 0,
239-
// tick: Integer::from_primitive(0),
240-
// gyro_z: Integer::from_primitive(0),
241-
// gyro_y: Integer::from_primitive(0),
242-
// gyro_x: Integer::from_primitive(0),
243-
// accel_z: Integer::from_primitive(0),
244-
// accel_y: Integer::from_primitive(0),
245-
// accel_x: Integer::from_primitive(0),
246-
// charging: false,
247-
// charge_percent: Integer::from_primitive(0),
159+
gyro_y_lo: Default::default(),
160+
gyro_y_hi: Default::default(),
161+
gyro_x: Integer::from_primitive(0),
162+
gyro_z: Integer::from_primitive(0),
163+
accel_z: Integer::from_primitive(0),
164+
accel_y: Integer::from_primitive(0),
165+
accel_x: Integer::from_primitive(0),
248166
}
249167
}
250168
}

src/input/source/hidraw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl HidRawDevice {
423423
DriverType::Vader4Pro => {
424424
let device = Vader4Pro::new(device_info.clone())?;
425425
let options = SourceDriverOptions {
426-
poll_rate: Duration::from_millis(1),
426+
poll_rate: Duration::from_millis(0),
427427
buffer_size: 1024,
428428
};
429429
let source_device = SourceDriver::new_with_options(

0 commit comments

Comments
 (0)