Struct Gamepad

Source
pub struct Gamepad { /* private fields */ }
Expand description

Wrapper around the SDL_Gamepad object

Implementations§

Source§

impl Gamepad

Source

pub fn subsystem(&self) -> &GamepadSubsystem

Source

pub fn name(&self) -> Option<String>

Return the name of the controller or an empty string if no name is found.

Source

pub fn path(&self) -> Option<String>

Return the implementation-dependant path for an opened gamepad.

Source

pub fn type(&self) -> GamepadType

Return the type of an opened gamepad.

Source

pub fn real_type(&self) -> GamepadType

Return the type of an opened gamepad, ignoring any mapping override.

Source

pub fn player_index(&self) -> Option<u16>

Return the player index of an opened gamepad.

Source

pub fn set_player_index(&self, player_index: u16) -> Result<(), Error>

Set the player index of an opened gamepad.

Source

pub fn unset_player_index(&self) -> Result<(), Error>

Unset the player index of an opened gamepad.

Source

pub fn vendor_id(&self) -> Option<u16>

Return the USB vendor ID of an opened gamepad, if available.

Source

pub fn product_id(&self) -> Option<u16>

Return the USB product ID of an opened gamepad, if available.

Source

pub fn product_version(&self) -> Option<u16>

Return the product version of an opened gamepad, if available.

Source

pub fn firmware_version(&self) -> Option<u16>

Return the firmware version of an opened gamepad, if available.

Source

pub fn serial_number(&self) -> Option<String>

Return the serial number of an opened gamepad, if available.

Source

pub fn connection_state(&self) -> Result<ConnectionState, Error>

Return the connection state of a gamepad

Source

pub fn power_info(&self) -> PowerInfo

Return the battery state of a gamepad

Source

pub fn mapping(&self) -> Option<String>

Return a String describing the controller’s button and axis mappings

Source

pub fn set_mapping(&mut self, mapping: &str) -> Result<(), AddMappingError>

Source

pub fn connected(&self) -> bool

Return true if the controller has been opened and currently connected.

Source

pub fn id(&self) -> Result<JoystickId, Error>

Return the joystick id of an opened gamepad.

Source

pub fn has_axis(&self, axis: Axis) -> bool

Return whether the gamepad has a given axis.

Source

pub fn axis(&self, axis: Axis) -> i16

Get the position of the given axis

Source

pub fn has_button(&self, button: Button) -> bool

Return whether the gamepad has a given button.

Source

pub fn button(&self, button: Button) -> bool

Returns true if button is pressed.

Source

pub fn button_label_for_gamepad_type(&self, button: Button) -> ButtonLabel

Return the label of a button on this gamepad

Source

pub fn touchpads_count(&self) -> u16

Return the number of touchpads on this gamepad

Source

pub fn supported_touchpad_fingers(&self, touchpad: u16) -> u16

Return the number of supported simultaneous fingers on a touchpad on this gamepad

Source

pub fn set_rumble( &mut self, low_frequency_rumble: u16, high_frequency_rumble: u16, duration_ms: u32, ) -> Result<(), IntegerOrSdlError>

Set the rumble motors to their specified intensities, if supported. Automatically resets back to zero after duration_ms milliseconds have passed.

§Notes

The value range for the intensities is 0 to 0xFFFF.

Do not use std::u32::MAX or similar for duration_ms if you want the rumble effect to keep playing for a long time, as this results in the effect ending immediately after starting due to an overflow. Use some smaller, “huge enough” number instead.

Source

pub fn set_rumble_triggers( &mut self, left_rumble: u16, right_rumble: u16, duration_ms: u32, ) -> Result<(), IntegerOrSdlError>

Start a rumble effect in the game controller’s triggers.

Source

pub unsafe fn has_led(&self) -> bool

Query whether a game controller has a RGB LED.

Source

pub unsafe fn has_rumble(&self) -> bool

Query whether a game controller has rumble support.

Source

pub unsafe fn has_rumble_triggers(&self) -> bool

Query whether a game controller has rumble support on triggers.

Source

pub fn set_led( &mut self, red: u8, green: u8, blue: u8, ) -> Result<(), IntegerOrSdlError>

Update a game controller’s LED color.

Source

pub fn send_effect(&mut self, data: &[u8]) -> Result<(), Error>

Send a controller specific effect packet.

Trait Implementations§

Source§

impl Drop for Gamepad

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.