Joystick

Struct Joystick 

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

Wrapper around the SDL_Joystick object

Implementations§

Source§

impl Joystick

Source

pub const fn subsystem(&self) -> &JoystickSubsystem

Source

pub fn name(&self) -> String

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

Source

pub fn connected(&self) -> bool

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

Source

pub fn id(&self) -> u32

Source

pub fn guid(&self) -> Guid

Retrieve the joystick’s GUID

Source

pub fn power_info(&self) -> Result<PowerInfo, IntegerOrSdlError>

Retrieve the battery level of this joystick This method doesn’t match the name of the SDL API since we have PowerLevel + percentage in a PowerInfo struct.

Source

pub fn num_axes(&self) -> u32

Retrieve the number of axes for this joystick

Source

pub fn axis(&self, axis: u32) -> Result<i16, IntegerOrSdlError>

Gets the position of the given axis.

The function will fail if the joystick doesn’t have the provided axis.

Source

pub fn num_buttons(&self) -> u32

Retrieve the number of buttons for this joystick

Source

pub fn button(&self, button: u32) -> Result<bool, IntegerOrSdlError>

Return Ok(true) if button is pressed.

The function will fail if the joystick doesn’t have the provided button.

Source

pub fn num_hats(&self) -> u32

Retrieve the number of balls for this joystick

Source

pub fn hat(&self, hat: u32) -> Result<HatState, IntegerOrSdlError>

Return the position of hat for this joystick

Source

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

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.

Returns false if the gamepad doesn’t support rumble.

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 joystick’s triggers.

Source

pub unsafe fn has_led(&self) -> bool

Query whether a joystick has an LED.

Source

pub unsafe fn has_rumble(&self) -> bool

Query whether a joystick has rumble support.

Source

pub unsafe fn has_rumble_triggers(&self) -> bool

Query whether a joystick has rumble support on triggers.

Source

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

Update a joystick’s LED color.

Source

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

Send a joystick specific effect packet.

Trait Implementations§

Source§

impl Drop for Joystick

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.