pub struct Joystick { /* private fields */ }
Expand description
Wrapper around the SDL_Joystick
object
Implementations§
source§impl Joystick
impl Joystick
pub fn subsystem(&self) -> &JoystickSubsystem
sourcepub fn name(&self) -> String
pub fn name(&self) -> String
Return the name of the joystick or an empty string if no name is found.
sourcepub fn attached(&self) -> bool
pub fn attached(&self) -> bool
Return true if the joystick has been opened and currently connected.
pub fn instance_id(&self) -> i32
sourcepub fn power_level(&self) -> Result<PowerLevel, IntegerOrSdlError>
pub fn power_level(&self) -> Result<PowerLevel, IntegerOrSdlError>
Retrieve the battery level of this joystick
sourcepub fn axis(&self, axis: u32) -> Result<i16, IntegerOrSdlError>
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.
Retrieve the number of buttons for this joystick
Return Ok(true)
if button
is pressed.
The function will fail if the joystick doesn’t have the provided button.
sourcepub fn ball(&self, ball: u32) -> Result<(i32, i32), IntegerOrSdlError>
pub fn ball(&self, ball: u32) -> Result<(i32, i32), IntegerOrSdlError>
Return a pair (dx, dy)
containing the difference in axis
position since the last poll
sourcepub fn hat(&self, hat: u32) -> Result<HatState, IntegerOrSdlError>
pub fn hat(&self, hat: u32) -> Result<HatState, IntegerOrSdlError>
Return the position of hat
for this joystick
sourcepub fn set_rumble(
&mut self,
low_frequency_rumble: u16,
high_frequency_rumble: u16,
duration_ms: u32,
) -> Result<(), IntegerOrSdlError>
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.