Skip to main content

xbox_controller_core/
state.rs

1/// Digital button state from one Xbox controller report.
2#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
3pub struct XboxButtonState {
4    pub a: bool,
5    pub b: bool,
6    pub x: bool,
7    pub y: bool,
8    pub dpad_up: bool,
9    pub dpad_down: bool,
10    pub dpad_left: bool,
11    pub dpad_right: bool,
12    pub lb: bool,
13    pub rb: bool,
14    pub view: bool,
15    pub menu: bool,
16    pub xbox: bool,
17    pub left_stick_button: bool,
18    pub right_stick_button: bool,
19    pub share: bool,
20}
21
22/// Stick positions centered around zero.
23#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
24pub struct XboxSticks {
25    pub left_x: i16,
26    pub left_y: i16,
27    pub right_x: i16,
28    pub right_y: i16,
29}
30
31/// Analog trigger values, normally in the range `0..=1023`.
32#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
33pub struct XboxTriggers {
34    pub left: u16,
35    pub right: u16,
36}
37
38/// The controller state represented by one BLE HID input notification.
39#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
40pub struct XboxControllerState {
41    pub buttons: XboxButtonState,
42    pub sticks: XboxSticks,
43    pub triggers: XboxTriggers,
44}