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]

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.

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().

Returns the name of the gamepad supplied by the OS.

Returns gamepad's UUID.

Returns cached gamepad state.

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.

Returns true if gamepad is connected.

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.

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.

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.

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

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());
}

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.

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}.

Returns true if force feedback is supported by device.

Change gamepad position used by force feedback effects.

Returns AxisOrBtn mapped to Code.

Returns Code associated with btn.

Returns Code associated with axis.

Returns area in which axis events should be ignored.

Returns ID of gamepad.

Trait Implementations

impl Debug for Gamepad
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Gamepad

impl !Sync for Gamepad