pub struct Gamepad<'a> {
data: &'a GamepadData,
inner: &'a Gamepad,
}
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.
Fields§
§data: &'a GamepadData
§inner: &'a Gamepad
Implementations§
source§impl<'a> Gamepad<'a>
impl<'a> Gamepad<'a>
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Returns the mapping name if it exists otherwise returns the os provided name.
sourcepub 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
.
sourcepub 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.
sourcepub 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.
sourcepub fn product_id(&self) -> Option<u16>
pub fn product_id(&self) -> Option<u16>
Returns the product ID, as assigned by the vendor, when available.
sourcepub fn state(&self) -> &GamepadState
pub fn state(&self) -> &GamepadState
Returns cached gamepad state.
sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns true if gamepad is connected.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub fn power_info(&self) -> PowerInfo
pub fn power_info(&self) -> PowerInfo
Returns device’s power supply state. See PowerInfo
for details.
sourcepub 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());
}
sourcepub fn is_ff_supported(&self) -> bool
pub fn is_ff_supported(&self) -> bool
Returns true if force feedback is supported by device.
sourcepub fn set_listener_position<Vec3: Into<[f32; 3]>>(
&self,
position: Vec3,
) -> Result<(), FfError>
pub fn set_listener_position<Vec3: Into<[f32; 3]>>( &self, position: Vec3, ) -> Result<(), FfError>
Change gamepad position used by force feedback effects.
sourcepub 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
.
sourcepub fn deadzone(&self, axis: Code) -> Option<f32>
pub fn deadzone(&self, axis: Code) -> Option<f32>
Returns area in which axis events should be ignored.