Struct gilrs::Gamepad [−][src]
pub struct Gamepad { /* fields omitted */ }
Represents game controller.
Using this struct you can access cached gamepad state, information about gamepad such as name or UUID and manage force feedback effects.
Methods
impl Gamepad
[src]
impl Gamepad
pub fn name(&self) -> &str
[src]
pub fn name(&self) -> &str
Returns the mapping name if it exists otherwise returns the os provided name. Warning: May change from os provided name to mapping name after the first call of event_next.
pub fn map_name(&self) -> Option<&str>
[src]
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
.
Warning: Mappings are set after event Connected
is processed therefore this function will
always return None
before first calls to Gilrs::next_event()
.
pub fn os_name(&self) -> &str
[src]
pub fn os_name(&self) -> &str
Returns the name of the gamepad supplied by the OS.
pub fn uuid(&self) -> Uuid
[src]
pub fn uuid(&self) -> Uuid
Returns gamepad's UUID.
pub fn state(&self) -> &GamepadState
[src]
pub fn state(&self) -> &GamepadState
Returns cached gamepad state.
pub fn status(&self) -> Status
[src]
pub fn status(&self) -> Status
Returns current gamepad's status, which can be Connected
, Disconnected
or NotObserved
.
Only connected gamepads generate events. Disconnected gamepads retain their name and UUID.
Cached state of disconnected and not observed gamepads is 0 (false for buttons and 0.0 for
axis) and all actions preformed on such gamepad are no-op.
pub fn is_connected(&self) -> bool
[src]
pub fn is_connected(&self) -> bool
Returns true if gamepad is connected.
pub fn is_pressed(&self, btn: Button) -> bool
[src]
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
[src]
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>
[src]
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
[src]
pub fn power_info(&self) -> PowerInfo
Returns device's power supply state. See PowerInfo
for details.
pub fn mapping_source(&self) -> MappingSource
[src]
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 set_mapping<'a, O: Into<Option<&'a str>>>(
&mut self,
mapping: &MappingData,
name: O
) -> Result<String, MappingError>
[src]
pub fn set_mapping<'a, O: Into<Option<&'a str>>>(
&mut self,
mapping: &MappingData,
name: O
) -> Result<String, MappingError>
Sets gamepad's mapping and returns SDL2 representation of them. Returned mappings may not be
compatible with SDL2 - if it is important, use
set_mapping_strict()
.
The name
argument can be a string slice with custom gamepad name or None
. If None
,
gamepad name reported by driver will be used.
Errors
This function return error if name
contains comma, mapping
have axis and button entry
for same element (for example Axis::LetfTrigger
and Button::LeftTrigger
) or gamepad does
not have any element with EvCode
used in mapping. Button::Unknown
and
Axis::Unknown
are not allowd as keys to mapping
– in this case,
MappingError::UnknownElement
is returned.
Error is also returned if this function is not implemented or gamepad is not connected.
Example
use gilrs::{Mapping, Button}; let mut data = Mapping::new(); // … // or `match gilrs[0].set_mapping(&data, None) {` match gilrs[0].set_mapping(&data, "Custom name") { Ok(sdl) => println!("SDL2 mapping: {}", sdl), Err(e) => println!("Failed to set mapping: {}", e), };
See also examples/mapping.rs
.
pub fn set_mapping_strict<'a, O: Into<Option<&'a str>>>(
&mut self,
mapping: &MappingData,
name: O
) -> Result<String, MappingError>
[src]
pub fn set_mapping_strict<'a, O: Into<Option<&'a str>>>(
&mut self,
mapping: &MappingData,
name: O
) -> Result<String, MappingError>
Similar to set_mapping()
but returned string should be compatible
with SDL2.
Errors
Returns MappingError::NotSdl2Compatible
if mapping
have an entry for Button::{C, Z}
or Axis::{LeftZ, RightZ}
.
pub fn is_ff_supported(&self) -> bool
[src]
pub fn is_ff_supported(&self) -> bool
Returns true if force feedback is supported by device.
pub fn set_listener_position<Vec3: Into<[f32; 3]>>(
&self,
position: Vec3
) -> Result<(), FfError>
[src]
pub fn set_listener_position<Vec3: Into<[f32; 3]>>(
&self,
position: Vec3
) -> Result<(), FfError>
Change gamepad position used by force feedback effects.
pub fn axis_or_btn_name(&self, ec: Code) -> Option<AxisOrBtn>
[src]
pub fn axis_or_btn_name(&self, ec: Code) -> Option<AxisOrBtn>
Returns AxisOrBtn
mapped to Code
.
Returns Code
associated with btn
.
pub fn axis_code(&self, axis: Axis) -> Option<Code>
[src]
pub fn axis_code(&self, axis: Axis) -> Option<Code>
Returns Code
associated with axis
.
pub fn deadzone(&self, axis: Code) -> Option<f32>
[src]
pub fn deadzone(&self, axis: Code) -> Option<f32>
Returns area in which axis events should be ignored.
pub fn id(&self) -> usize
[src]
pub fn id(&self) -> usize
Returns ID of gamepad.