pub struct GamepadReport {
pub x: i8,
pub y: i8,
pub z: i8,
pub rz: i8,
pub hat: u8,
pub buttons: GamepadButtons,
}Expand description
Standard USB HID Gamepad report with 8-bit axes, hat switch, and 16 buttons (7 bytes).
Fields§
§x: i8Left stick horizontal axis (signed, positive = right).
y: i8Left stick vertical axis (signed, positive = down).
z: i8Right stick horizontal axis (signed, positive = right).
rz: i8Right stick vertical axis (signed, positive = down).
hat: u88-direction hat switch (POV D-pad).
Values 1–8 correspond to 45° increments starting from Up (0°):
- 1 = Up (0°)
- 2 = Up-Right (45°)
- 3 = Right (90°)
- 4 = Down-Right (135°)
- 5 = Down (180°)
- 6 = Down-Left (225°)
- 7 = Left (270°)
- 8 = Up-Left (315°)
- 0 = Released / centered (Null state)
Button bitmask (buttons 1–16).
Implementations§
Source§impl GamepadReport
impl GamepadReport
Sourcepub const HAT_CENTER: u8 = 0
pub const HAT_CENTER: u8 = 0
Hat switch released / centered (null state).
Sourcepub const HAT_UP_RIGHT: u8 = 2
pub const HAT_UP_RIGHT: u8 = 2
Hat switch Up-Right (45°).
Sourcepub const HAT_DOWN_RIGHT: u8 = 4
pub const HAT_DOWN_RIGHT: u8 = 4
Hat switch Down-Right (135°).
Sourcepub const HAT_DOWN_LEFT: u8 = 6
pub const HAT_DOWN_LEFT: u8 = 6
Hat switch Down-Left (225°).
Sourcepub const HAT_UP_LEFT: u8 = 8
pub const HAT_UP_LEFT: u8 = 8
Hat switch Up-Left (315°).
Sourcepub const BUTTON_1: GamepadButtons
pub const BUTTON_1: GamepadButtons
Button 1
Sourcepub const BUTTON_2: GamepadButtons
pub const BUTTON_2: GamepadButtons
Button 2
Sourcepub const BUTTON_3: GamepadButtons
pub const BUTTON_3: GamepadButtons
Button 3
Sourcepub const BUTTON_4: GamepadButtons
pub const BUTTON_4: GamepadButtons
Button 4
Sourcepub const BUTTON_5: GamepadButtons
pub const BUTTON_5: GamepadButtons
Button 5
Sourcepub const BUTTON_6: GamepadButtons
pub const BUTTON_6: GamepadButtons
Button 6
Sourcepub const BUTTON_7: GamepadButtons
pub const BUTTON_7: GamepadButtons
Button 7
Sourcepub const BUTTON_8: GamepadButtons
pub const BUTTON_8: GamepadButtons
Button 8
Sourcepub const BUTTON_9: GamepadButtons
pub const BUTTON_9: GamepadButtons
Button 9
Sourcepub const BUTTON_10: GamepadButtons
pub const BUTTON_10: GamepadButtons
Button 10
Sourcepub const BUTTON_11: GamepadButtons
pub const BUTTON_11: GamepadButtons
Button 11
Sourcepub const BUTTON_12: GamepadButtons
pub const BUTTON_12: GamepadButtons
Button 12
Sourcepub const BUTTON_13: GamepadButtons
pub const BUTTON_13: GamepadButtons
Button 13
Sourcepub const BUTTON_14: GamepadButtons
pub const BUTTON_14: GamepadButtons
Button 14
Sourcepub const BUTTON_15: GamepadButtons
pub const BUTTON_15: GamepadButtons
Button 15
Sourcepub const BUTTON_16: GamepadButtons
pub const BUTTON_16: GamepadButtons
Button 16
Sourcepub const BUTTON_A: GamepadButtons = Self::BUTTON_1
pub const BUTTON_A: GamepadButtons = Self::BUTTON_1
Primary action button (A / Cross).
Sourcepub const BUTTON_B: GamepadButtons = Self::BUTTON_2
pub const BUTTON_B: GamepadButtons = Self::BUTTON_2
Secondary action button (B / Circle).
Sourcepub const BUTTON_X: GamepadButtons = Self::BUTTON_3
pub const BUTTON_X: GamepadButtons = Self::BUTTON_3
Tertiary action button (X / Square).
Sourcepub const BUTTON_Y: GamepadButtons = Self::BUTTON_4
pub const BUTTON_Y: GamepadButtons = Self::BUTTON_4
Quaternary action button (Y / Triangle).
Sourcepub const BUTTON_TL: GamepadButtons = Self::BUTTON_5
pub const BUTTON_TL: GamepadButtons = Self::BUTTON_5
Left bumper / shoulder button (L1 / LB).
Sourcepub const BUTTON_TR: GamepadButtons = Self::BUTTON_6
pub const BUTTON_TR: GamepadButtons = Self::BUTTON_6
Right bumper / shoulder button (R1 / RB).
Sourcepub const BUTTON_TL2: GamepadButtons = Self::BUTTON_7
pub const BUTTON_TL2: GamepadButtons = Self::BUTTON_7
Left trigger digital button (L2 / LT).
Sourcepub const BUTTON_TR2: GamepadButtons = Self::BUTTON_8
pub const BUTTON_TR2: GamepadButtons = Self::BUTTON_8
Right trigger digital button (R2 / RT).
Sourcepub const BUTTON_SELECT: GamepadButtons = Self::BUTTON_9
pub const BUTTON_SELECT: GamepadButtons = Self::BUTTON_9
Select / Back / Share button.
Sourcepub const BUTTON_START: GamepadButtons = Self::BUTTON_10
pub const BUTTON_START: GamepadButtons = Self::BUTTON_10
Start / Options button.
Sourcepub const BUTTON_MODE: GamepadButtons = Self::BUTTON_11
pub const BUTTON_MODE: GamepadButtons = Self::BUTTON_11
Mode / Home / Guide button.
Sourcepub const BUTTON_THUMBL: GamepadButtons = Self::BUTTON_12
pub const BUTTON_THUMBL: GamepadButtons = Self::BUTTON_12
Left stick click (L3 / Thumbl).
Sourcepub const BUTTON_THUMBR: GamepadButtons = Self::BUTTON_13
pub const BUTTON_THUMBR: GamepadButtons = Self::BUTTON_13
Right stick click (R3 / Thumbr).
Sourcepub const DESCRIPTOR: &'static [u8]
pub const DESCRIPTOR: &'static [u8]
Standard USB HID Gamepad report descriptor without report ID (7 bytes input report).
Sourcepub fn parse(buf: &[u8]) -> Option<Self>
pub fn parse(buf: &[u8]) -> Option<Self>
Parse a gamepad report from a byte slice.
Returns None if buf is shorter than 7 bytes.
Sourcepub const fn to_bytes(&self) -> [u8; 7]
pub const fn to_bytes(&self) -> [u8; 7]
Serialize the gamepad report into its 7-byte wire format.
Returns true if the specified button is pressed.