Struct gilrs::Gamepad

source ·
pub struct Gamepad<'a> { /* private fields */ }
Expand description

Represents handle to game controller.

Using this struct you can access cached gamepad state, information about gamepad such as name or UUID and manage force feedback effects.

Implementations§

source§

impl<'a> Gamepad<'a>

source

pub fn name(&self) -> &str

Returns the mapping name if it exists otherwise returns the os provided name.

source

pub fn map_name(&self) -> Option<&str>

if mapping_source() is SdlMappings returns the name of the mapping used by the gamepad. Otherwise returns None.

source

pub fn os_name(&self) -> &str

Returns the name of the gamepad supplied by the OS.

source

pub fn uuid(&self) -> [u8; 16]

Returns gamepad’s UUID.

It is recommended to process with the UUID crate. Use Uuid::from_bytes method to create a Uuid from the returned bytes.

source

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

Returns the vendor ID, as assigned by the USB-IF, when available.

source

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

Returns the product ID, as assigned by the vendor, when available.

source

pub fn state(&self) -> &GamepadState

Returns cached gamepad state.

source

pub fn is_connected(&self) -> bool

Returns true if gamepad is connected.

source

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

Examines cached gamepad state to check if given button is pressed. Panics if btn is Unknown.

If you know Code of the element that you want to examine, it’s recommended to use methods directly on State, because this version have to check which Code is mapped to element of gamepad.

source

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

Examines cached gamepad state to check axis’s value. Panics if axis is Unknown.

If you know Code of the element that you want to examine, it’s recommended to use methods directly on State, because this version have to check which Code is mapped to element of gamepad.

source

pub fn button_data(&self, btn: Button) -> Option<&ButtonData>

Returns button state and when it changed.

If you know Code of the element that you want to examine, it’s recommended to use methods directly on State, because this version have to check which Code is mapped to element of gamepad.

source

pub fn axis_data(&self, axis: Axis) -> Option<&AxisData>

Returns axis state and when it changed.

If you know Code of the element that you want to examine, it’s recommended to use methods directly on State, because this version have to check which Code is mapped to element of gamepad.

source

pub fn power_info(&self) -> PowerInfo

Returns device’s power supply state. See PowerInfo for details.

source

pub fn mapping_source(&self) -> MappingSource

Returns source of gamepad mapping. Can be used to filter gamepads which do not provide unified controller layout.

use gilrs::MappingSource;

for (_, gamepad) in gilrs.gamepads().filter(
    |gp| gp.1.mapping_source() != MappingSource::None)
{
    println!("{} is ready to use!", gamepad.name());
}
source

pub fn is_ff_supported(&self) -> bool

Returns true if force feedback is supported by device.

source

pub fn set_listener_position<Vec3: Into<[f32; 3]>>( &self, position: Vec3 ) -> Result<(), FfError>

Change gamepad position used by force feedback effects.

source

pub fn axis_or_btn_name(&self, ec: Code) -> Option<AxisOrBtn>

Returns AxisOrBtn mapped to Code.

source

pub fn button_code(&self, btn: Button) -> Option<Code>

Returns Code associated with btn.

source

pub fn axis_code(&self, axis: Axis) -> Option<Code>

Returns Code associated with axis.

source

pub fn deadzone(&self, axis: Code) -> Option<f32>

Returns area in which axis events should be ignored.

source

pub fn id(&self) -> GamepadId

Returns ID of gamepad.

Trait Implementations§

source§

impl<'a> Clone for Gamepad<'a>

source§

fn clone(&self) -> Gamepad<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for Gamepad<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Copy for Gamepad<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Gamepad<'a>

§

impl<'a> RefUnwindSafe for Gamepad<'a>

§

impl<'a> Send for Gamepad<'a>

§

impl<'a> Sync for Gamepad<'a>

§

impl<'a> Unpin for Gamepad<'a>

§

impl<'a> UnwindSafe for Gamepad<'a>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.