Struct Gamepad
pub struct Gamepad<'a> { /* private fields */ }
dep_gilrs
only.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§
§impl<'a> Gamepad<'a>
impl<'a> Gamepad<'a>
pub fn name(&self) -> &str ⓘ
pub fn name(&self) -> &str ⓘ
Returns the mapping name if it exists otherwise returns the os provided name.
pub fn map_name(&self) -> Option<&str> ⓘ
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
.
pub fn uuid(&self) -> [u8; 16]
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.
pub fn vendor_id(&self) -> Option<u16> ⓘ
pub fn vendor_id(&self) -> Option<u16> ⓘ
Returns the vendor ID, as assigned by the USB-IF, when available.
pub fn product_id(&self) -> Option<u16> ⓘ
pub fn product_id(&self) -> Option<u16> ⓘ
Returns the product ID, as assigned by the vendor, when available.
pub fn state(&self) -> &GamepadState
pub fn state(&self) -> &GamepadState
Returns cached gamepad state.
pub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true if gamepad is connected.
pub fn is_pressed(&self, btn: Button) -> bool
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.
pub fn value(&self, axis: Axis) -> f32
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.
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.
pub fn axis_data(&self, axis: Axis) -> Option<&AxisData> ⓘ
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.
pub fn power_info(&self) -> PowerInfo
pub fn power_info(&self) -> PowerInfo
Returns device’s power supply state. See PowerInfo
for details.
pub fn mapping_source(&self) -> MappingSource
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());
}
pub fn is_ff_supported(&self) -> bool
pub fn is_ff_supported(&self) -> bool
Returns true if force feedback is supported by device.
pub fn set_listener_position<Vec3>(&self, position: Vec3) -> Result<(), Error> ⓘ
pub fn set_listener_position<Vec3>(&self, position: Vec3) -> Result<(), Error> ⓘ
Change gamepad position used by force feedback effects.
pub fn axis_or_btn_name(&self, ec: Code) -> Option<AxisOrBtn> ⓘ
pub fn axis_or_btn_name(&self, ec: Code) -> Option<AxisOrBtn> ⓘ
Returns AxisOrBtn
mapped to Code
.
Returns Code
associated with btn
.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more