### Filter Gamepads by Mapping Source Source: https://docs.rs/gilrs/latest/gilrs/struct.Gamepad.html Example demonstrating how to filter gamepads that provide a unified controller layout using mapping_source. ```rust use gilrs::MappingSource; for (_, gamepad) in gilrs.gamepads().filter( |gp| gp.1.mapping_source() != MappingSource::None) { println!("{} is ready to use!", gamepad.name()); } ``` -------------------------------- ### Check Battery Level Source: https://docs.rs/gilrs/latest/gilrs/enum.PowerInfo.html Example of matching on the power info of a gamepad to detect low battery levels. ```rust use gilrs_core::PowerInfo; match gilrs.gamepad(0).map(|g| g.power_info()) { Some(PowerInfo::Discharging(lvl)) if lvl <= 10 => println!("Low battery level, you should \ plug your gamepad"), _ => (), }; ``` -------------------------------- ### Get input value Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search=u32+-%3E+bool Retrieves the current value of an axis or button, returning 0.0 if no information is available. ```rust pub fn value(&self, el: Code) -> f32 ``` -------------------------------- ### Gilrs::new Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Initializes a new instance of the Gilrs gamepad manager. ```APIDOC ## Gilrs::new ### Description Creates a new instance of the Gilrs struct to manage gamepads. ### Signature `pub fn new() -> Result` ``` -------------------------------- ### Initialize and process gamepad events in Rust Source: https://docs.rs/gilrs/latest/gilrs/index.html Demonstrates initializing the GilRs context, iterating over connected gamepads, and processing input events in a loop. ```rust use gilrs::{Gilrs, Button, Event}; let mut gilrs = Gilrs::new().unwrap(); // Iterate over all connected gamepads for (_id, gamepad) in gilrs.gamepads() { println!("{} is {:?}", gamepad.name(), gamepad.power_info()); } let mut active_gamepad = None; loop { // Examine new events while let Some(Event { id, event, time, .. }) = gilrs.next_event() { println!("{:?} New event from {}: {:?}", time, id, event); active_gamepad = Some(id); } // You can also use cached gamepad state if let Some(gamepad) = active_gamepad.map(|id| gilrs.gamepad(id)) { if gamepad.is_pressed(Button::South) { println!("Button South is pressed (XBox - A, PS - X)"); } } } ``` -------------------------------- ### Create and play a force feedback effect Source: https://docs.rs/gilrs/latest/gilrs/ff/index.html Demonstrates how to initialize Gilrs, identify supported gamepads, build a complex effect with strong and weak vibrations, and trigger playback. ```rust use gilrs::Gilrs; use gilrs::ff::{EffectBuilder, Replay, BaseEffect, BaseEffectType, Ticks}; let mut gilrs = Gilrs::new().unwrap(); let support_ff = gilrs .gamepads() .filter_map(|(id, gp)| if gp.is_ff_supported() { Some(id) } else { None }) .collect::>(); let duration = Ticks::from_ms(150); let effect = EffectBuilder::new() .add_effect(BaseEffect { kind: BaseEffectType::Strong { magnitude: 60_000 }, scheduling: Replay { play_for: duration, with_delay: duration * 3, ..Default::default() }, envelope: Default::default(), }) .add_effect(BaseEffect { kind: BaseEffectType::Weak { magnitude: 60_000 }, scheduling: Replay { after: duration * 2, play_for: duration, with_delay: duration * 3 }, ..Default::default() }) .gamepads(&support_ff) .finish(&mut gilrs).unwrap(); effect.play().unwrap(); ``` -------------------------------- ### pub fn new() -> Result Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Creates a new instance of Gilrs with default settings. ```APIDOC ## pub fn new() -> Result ### Description Creates a new Gilrs instance with default settings. Refer to `GilrsBuilder` for advanced configuration options. ``` -------------------------------- ### Event::new Source: https://docs.rs/gilrs/latest/gilrs/ev/struct.Event.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new gamepad event with the current system time. ```APIDOC ## pub fn new(id: GamepadId, event: EventType) -> Self ### Description Creates a new event with the current system time. ### Parameters - **id** (GamepadId) - The ID of the gamepad. - **event** (EventType) - The event data. ### Returns - **Self** - A new Event instance. ``` -------------------------------- ### Gilrs::new Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new instance of Gilrs with default settings. ```APIDOC ## pub fn new() -> Result ### Description Creates a new Gilrs instance with default settings. See `GilrsBuilder` for more details. ### Returns - **Result** - A new Gilrs instance or an error if initialization fails. ``` -------------------------------- ### Initialize and use the Gilrs event loop Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Demonstrates how to initialize the Gilrs instance and process events such as button presses and disconnections within a loop. ```rust use gilrs::{Gilrs, Event, EventType, Button}; let mut gilrs = Gilrs::new().unwrap(); // Event loop loop { while let Some(event) = gilrs.next_event() { match event { Event { id, event: EventType::ButtonPressed(Button::South, _), .. } => { println!("Player {}: jump!", id) } Event { id, event: EventType::Disconnected, .. } => { println!("We lost player {}", id) } _ => (), }; } } ``` -------------------------------- ### Gilrs Event Loop Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html?search=std%3A%3Avec Demonstrates how to initialize Gilrs and process gamepad events using the next_event() method. ```APIDOC ## Gilrs::next_event() ### Description Retrieves the next event from the internal event queue. This is used to handle actions such as button presses or controller connection changes. ### Usage ```rust use gilrs::{Gilrs, Event, EventType, Button}; let mut gilrs = Gilrs::new().unwrap(); // Event loop loop { while let Some(event) = gilrs.next_event() { // Process event } } ``` ``` -------------------------------- ### Mapping::new Source: https://docs.rs/gilrs/latest/gilrs/struct.Mapping.html Creates a new, empty Mapping instance. ```APIDOC ### pub fn new() -> Self Creates a new `Mapping` instance. ``` -------------------------------- ### EffectBuilder::new Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.EffectBuilder.html Creates a new instance of EffectBuilder with default settings. ```APIDOC ## pub fn new() -> Self ### Description Creates a new builder with default settings: no gamepads, no base effects, infinite repeat, no distance model, position at (0.0, 0.0, 0.0), and gain of 1.0. ``` -------------------------------- ### Mapping::new Source: https://docs.rs/gilrs/latest/gilrs/struct.Mapping.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new instance of Mapping. ```APIDOC ## pub fn new() -> Self ### Description Creates a new, empty Mapping instance. ### Returns - **Self** - A new Mapping object. ``` -------------------------------- ### Create and compare Ticks Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Ticks.html?search= Demonstrates creating Ticks from milliseconds or a Duration object. ```rust use gilrs::ff::Ticks; use std::time::Duration; let t1 = Ticks::from_ms(110); let t2 = Ticks::from(Duration::from_millis(130)); /// `Ticks` is not precise. assert_eq!(t1, t2); ``` -------------------------------- ### pub fn set_mapping<'b, O: Into>>(&mut self, gamepad_id: usize, mapping: &MappingData, name: O) -> Result Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Configures a custom mapping for a gamepad. ```APIDOC ## pub fn set_mapping ### Description Sets the mapping for a specific gamepad and returns the SDL2 representation of the mapping. The `name` parameter allows for an optional custom name for the device. ``` -------------------------------- ### Iterate Over Connected Gamepads Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Shows how to iterate through all currently connected gamepads to access their IDs and names. ```rust for (id, gamepad) in gilrs.gamepads() { assert!(gamepad.is_connected()); println!("Gamepad with id {} and name {} is connected", id, gamepad.name()); } ``` -------------------------------- ### Gamepad Methods Source: https://docs.rs/gilrs/latest/gilrs/struct.Gamepad.html Methods available on the Gamepad struct for interacting with game controllers. ```APIDOC ## Gamepad Methods ### name() Returns the mapping name if it exists, otherwise returns the OS-provided name. ### map_name() Returns the name of the mapping used by the gamepad if the mapping source is SdlMappings, otherwise returns None. ### os_name() Returns the name of the gamepad supplied by the OS. ### uuid() Returns the gamepad's 16-byte UUID. ### vendor_id() Returns the USB-IF assigned vendor ID, if available. ### product_id() Returns the vendor-assigned product ID, if available. ### state() Returns the cached GamepadState. ### is_connected() Returns true if the gamepad is currently connected. ### is_pressed(btn: Button) Checks if a specific button is pressed. Panics if the button is Unknown. ### value(axis: Axis) Returns the current value of an axis. Panics if the axis is Unknown. ### button_data(btn: Button) Returns the button state and the timestamp of its last change. ### axis_data(axis: Axis) Returns the axis state and the timestamp of its last change. ### power_info() Returns the device's power supply state. ### mapping_source() Returns the source of the gamepad mapping. ### is_ff_supported() Returns true if the device supports force feedback. ### set_listener_position(position: Vec3) Sets the gamepad position for force feedback effects. ### axis_or_btn_name(ec: Code) Returns the AxisOrBtn mapped to the given Code. ### button_code(btn: Button) Returns the Code associated with a specific Button. ### axis_code(axis: Axis) Returns the Code associated with a specific Axis. ### deadzone(axis: Code) Returns the deadzone area for a specific axis. ### id() Returns the unique GamepadId. ``` -------------------------------- ### pub fn gamepad(&self, id: GamepadId) -> Gamepad<'_> Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Returns a handle to a gamepad by its ID, regardless of connection status. ```APIDOC ## pub fn gamepad(&self, id: GamepadId) -> Gamepad<'_> ### Description Returns a handle to the gamepad associated with the provided ID. Unlike `connected_gamepad`, this method returns a handle even if the gamepad is currently disconnected. ``` -------------------------------- ### Effect Configuration Methods Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Effect.html?search=u32+-%3E+bool Methods for configuring the behavior and physical properties of the force feedback effect. ```rust pub fn set_repeat(&self, repeat: Repeat) -> Result<(), Error> ``` ```rust pub fn set_distance_model(&self, model: DistanceModel) -> Result<(), Error> ``` ```rust pub fn set_position>( &self, position: Vec3f, ) -> Result<(), Error> ``` ```rust pub fn set_gain(&self, gain: f32) -> Result<(), Error> ``` -------------------------------- ### pub fn second_axis(self) -> Option Source: https://docs.rs/gilrs/latest/gilrs/ev/enum.Axis.html?search=std%3A%3Avec Retrieves the corresponding axis from the same gamepad element, if one exists. ```APIDOC ## pub fn second_axis(self) -> Option ### Description Returns the other axis from the same element of the gamepad, if any. For example, `LeftStickX` returns `Some(LeftStickY)`. ### Returns - **Option** - The paired axis if it exists, otherwise `None`. ``` -------------------------------- ### Gilrs Counter and State Management Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html?search=std%3A%3Avec Explains how to use the internal counter to track when gamepad state changes occurred during the update loop. ```APIDOC ## Gilrs::inc() ### Description Increments the internal counter by one. This should be called at the end of each iteration of the update loop to track when specific events occurred relative to the processing loop. ## Gilrs::counter() ### Description Returns the current value of the internal counter. This can be compared against the counter value of a button or axis state to determine if an event happened in the current iteration. ``` -------------------------------- ### Process Gamepad Events Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Demonstrates how to poll for events and check the state of specific buttons on a gamepad. ```rust use gilrs::{Button, EventType}; loop { while let Some(ev) = gilrs.next_event() { // unwrap() should never panic because we use id from event let is_up_pressed = gilrs.gamepad(ev.id).is_pressed(Button::DPadUp); match ev.event { EventType::ButtonPressed(Button::South, _) if is_up_pressed => { // do something… } _ => (), } } } ``` -------------------------------- ### pub fn second_axis(self) -> Option Source: https://docs.rs/gilrs/latest/gilrs/ev/enum.Axis.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the complementary axis for the same gamepad element, if one exists. ```APIDOC ## pub fn second_axis(self) -> Option ### Description Returns the other axis from the same element of the gamepad, if any. For example, `LeftStickX` returns `Some(LeftStickY)`. ### Returns - **Option** - The corresponding axis if it exists, otherwise `None`. ``` -------------------------------- ### Repeat::new Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/struct.Repeat.html?search=std%3A%3Avec Creates a new Repeat filter instance with default timing settings (500ms delay before repeating, 30ms interval between repeats). ```APIDOC ## fn new() -> Self ### Description Creates a new `Repeat` filter with `after` set to 500ms and `every` set to 30ms. ### Returns - **Self** - A new instance of the `Repeat` struct. ``` -------------------------------- ### Set Custom Gamepad Mapping Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Configures a custom mapping for a gamepad and handles potential mapping errors. ```rust use gilrs::{Mapping, Button}; let mut data = Mapping::new(); // … // or `match gilrs.set_mapping(0, &data, None) {` match gilrs.set_mapping(0, &data, "Custom name") { Ok(sdl) => println!("SDL2 mapping: {}", sdl), Err(e) => println!("Failed to set mapping: {}", e), }; ``` -------------------------------- ### pub fn next_event(&mut self) -> Option Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Retrieves the next pending event without blocking the current thread. ```APIDOC ## pub fn next_event(&mut self) -> Option ### Description Returns the next pending event from the queue. Returns `None` if no events are pending. This method is non-blocking and safe to use in async contexts. ``` -------------------------------- ### GilrsBuilder Methods Source: https://docs.rs/gilrs/latest/gilrs/struct.GilrsBuilder.html Methods available on the GilrsBuilder struct for configuring gamepad behavior. ```APIDOC ## pub fn new() -> Self Creates a new builder with default settings. ## pub fn with_default_filters(self, default_filters: bool) -> Self Configures whether to use default axis/dpad/deadzone filters. Defaults to true. ## pub fn with_force_feedback(self, enable_ff: bool) -> Self Enables or disables force feedback support. Defaults to true. ## pub fn add_mappings(self, mappings: &str) -> Self Adds custom SDL mappings. ## pub fn add_env_mappings(self, env_mappings: bool) -> Self Configures whether to load mappings from the SDL_GAMECONTROLLERCONFIG environment variable. Defaults to true. ## pub fn add_included_mappings(self, included_mappings: bool) -> Self Configures whether to include default SDL mappings. Defaults to true. ## pub fn set_axis_to_btn(self, pressed: f32, released: f32) -> Self Sets the threshold values for axis-to-button event emission. Requires pressed > released and values within [0.0, 1.0]. ## pub fn set_update_state(self, enabled: bool) -> Self Enables or disables automatic state updates. ## pub fn build(self) -> Result Consumes the builder and returns the initialized Gilrs instance. ``` -------------------------------- ### Repeat::new Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/struct.Repeat.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new Repeat filter instance with default settings: 500ms delay before repeating and 30ms interval between repeats. ```APIDOC ## pub fn new() -> Self ### Description Creates a new `Repeat` filter with `after` set to 500ms and `every` set to 30ms. ### Returns - **Self** - A new instance of the Repeat filter. ``` -------------------------------- ### Effect Playback and Management Methods Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Effect.html?search=u32+-%3E+bool Methods for controlling the playback state and gamepad associations of a force feedback effect. ```rust pub fn play(&self) -> Result<(), Error> ``` ```rust pub fn stop(&self) -> Result<(), Error> ``` ```rust pub fn set_gamepads( &self, ids: &[GamepadId], gilrs: &Gilrs, ) -> Result<(), Error> ``` ```rust pub fn add_gamepad(&self, gamepad: &Gamepad<'_>) -> Result<(), Error> ``` -------------------------------- ### Chain multiple event filters in Rust Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/index.html Demonstrates how to apply Jitter, deadzone, and Repeat filters to an event loop using the filter_ev method. ```rust use gilrs::{GilrsBuilder, Filter}; use gilrs::ev::filter::{Jitter, Repeat, deadzone}; let mut gilrs = GilrsBuilder::new().with_default_filters(false).build().unwrap(); let jitter = Jitter { threshold: 0.02 }; let repeat = Repeat::new(); // Event loop loop { while let Some(event) = gilrs .next_event() .filter_ev(&jitter, &mut gilrs) .filter_ev(&deadzone, &mut gilrs) .filter_ev(&repeat, &mut gilrs) { gilrs.update(&event); println!("{:?}", event); } } ``` -------------------------------- ### Repeat::new Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/struct.Repeat.html?search=u32+-%3E+bool Creates a new Repeat filter instance with default durations of 500ms for the initial delay and 30ms for the repeat interval. ```APIDOC ## pub fn new() -> Self ### Description Creates a new `Repeat` filter with `after` set to 500ms and `every` set to 30ms. ``` -------------------------------- ### pub fn into_u32(&self) -> u32 Source: https://docs.rs/gilrs/latest/gilrs/ev/struct.Code.html?search= Converts the platform-specific event code into a single u32 value. ```APIDOC ## pub fn into_u32(&self) -> u32 ### Description Returns the platform-specific event code packed into a single `u32` integer. ### Signature `pub fn into_u32(&self) -> u32` ``` -------------------------------- ### Effect::set_gamepads Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Effect.html?search= Updates the list of gamepads associated with the effect. ```APIDOC ## pub fn set_gamepads(&self, ids: &[GamepadId], gilrs: &Gilrs) -> Result<(), Error> ### Description Changes the gamepads associated with the effect. The effect will only be played on the gamepads provided in the last call to this function. ``` -------------------------------- ### Repeat::new() Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/struct.Repeat.html Creates a new Repeat filter instance with default settings (500ms delay, 30ms interval). ```APIDOC ## pub fn new() -> Self ### Description Creates a new `Repeat` filter with `after` set to 500ms and `every` set to 30ms. ### Signature `pub fn new() -> Self` ``` -------------------------------- ### Implement state tracking with the Gilrs counter Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Shows how to use the internal counter to verify if a button state change occurred during the current iteration of the update loop. ```rust use gilrs::{Gilrs, Button}; let mut gilrs = Gilrs::new().unwrap(); let mut player_one = None; loop { while let Some(ev) = gilrs.next_event() { if player_one.is_none() { player_one = Some(ev.id); } // Do other things with event } if let Some(id) = player_one { let gamepad = gilrs.gamepad(id); if gamepad.is_pressed(Button::DPadLeft) { // go left } match gamepad.button_data(Button::South) { Some(d) if d.is_pressed() && d.counter() == gilrs.counter() => { // jump only if button was observed to be pressed in this iteration } _ => () } } // Increase counter gilrs.inc(); } ``` -------------------------------- ### EffectBuilder Methods Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.EffectBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods available for configuring and creating a new force feedback effect. ```APIDOC ## EffectBuilder ### Description A builder pattern implementation for creating new `Effect` instances with specific force feedback parameters. ### Methods - **new() -> Self**: Creates a new builder with default settings (no gamepads, infinite repeat, no distance model, position (0.0, 0.0, 0.0), gain 1.0). - **add_effect(&mut self, effect: BaseEffect) -> &mut Self**: Adds a new `BaseEffect` to the builder. - **gamepads(&mut self, ids: &[GamepadId]) -> &mut Self**: Sets the list of gamepads associated with the effect. - **add_gamepad(&mut self, gamepad: &Gamepad<'_>) -> &mut Self**: Adds a single gamepad to the associated list. - **repeat(&mut self, repeat: Repeat) -> &mut Self**: Configures the behavior of the effect when it ends. - **distance_model(&mut self, model: DistanceModel) -> &mut Self**: Sets the distance model for the effect. - **position>(&mut self, position: Vec3f) -> &mut Self**: Sets the 3D position of the effect source. - **gain(&mut self, gain: f32) -> &mut Self**: Sets the gain of the effect, clamped to [0.0, f32::MAX]. - **finish(&mut self, gilrs: &mut Gilrs) -> Result**: Validates parameters and creates the `Effect` instance. ``` -------------------------------- ### LinuxGamepadExt::devpath Source: https://docs.rs/gilrs/latest/gilrs/struct.Gamepad.html Returns the device node path of the gamepad. This method is only available on Linux platforms. ```APIDOC ## fn devpath(&self) -> &Path ### Description Returns the device node of the gamepad. This method is specific to Linux implementations. ### Returns - **&Path** - The path to the device node. ``` -------------------------------- ### buttons Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search= Iterates over all button data. ```APIDOC ## pub fn buttons(&self) -> ButtonDataIter<'_> ### Description Returns an iterator over the current button data. ``` -------------------------------- ### pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/fn.deadzone.html?search=std%3A%3Avec Drops events in the dead zone and remaps the value to keep it in the standard range. ```APIDOC ## Function: deadzone ### Description Drops events in the dead zone and remaps the value to keep it in the standard range. ### Signature `pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option` ### Parameters - **ev** (Option) - The event to process. - **gilrs** (&mut Gilrs) - A mutable reference to the Gilrs instance. ### Returns - **Option** - The processed event, or None if the event was dropped. ``` -------------------------------- ### pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/fn.deadzone.html?search=u32+-%3E+bool Drops events in the dead zone and remaps the value to keep it in the standard range. ```APIDOC ## Function: deadzone ### Description Drops events in dead zone and remaps value to keep it in standard range. ### Signature `pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option` ### Parameters - **ev** (Option) - The event to process. - **gilrs** (&mut Gilrs) - A mutable reference to the Gilrs instance. ### Returns - **Option** - The filtered or remapped event, or None if the event was dropped. ``` -------------------------------- ### GilrsBuilder Methods Source: https://docs.rs/gilrs/latest/gilrs/struct.GilrsBuilder.html?search= Methods available on the GilrsBuilder struct to configure and build a Gilrs instance. ```APIDOC ## pub fn new() -> Self Creates a new builder with default settings. ## pub fn with_default_filters(self, default_filters: bool) -> Self Configures whether to use default axis and deadzone filters. Defaults to true. ## pub fn with_force_feedback(self, enable_ff: bool) -> Self Enables or disables force feedback support. Defaults to true. ## pub fn add_mappings(self, mappings: &str) -> Self Adds custom SDL mappings. ## pub fn add_env_mappings(self, env_mappings: bool) -> Self Configures whether to load SDL mappings from the SDL_GAMECONTROLLERCONFIG environment variable. Defaults to true. ## pub fn add_included_mappings(self, included_mappings: bool) -> Self Configures whether to include default SDL mappings. Defaults to true. ## pub fn set_axis_to_btn(self, pressed: f32, released: f32) -> Self Sets the threshold values for ButtonPressed and ButtonReleased events. Returns an error on build if pressed <= released or values are outside [0.0, 1.0]. ## pub fn set_update_state(self, enabled: bool) -> Self Enables or disables automatic state updates. ## pub fn build(self) -> Result Finalizes the configuration and returns a Gilrs instance. ``` -------------------------------- ### EffectBuilder::gamepads Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.EffectBuilder.html Sets the list of gamepads for the effect. ```APIDOC ## pub fn gamepads(&mut self, ids: &[GamepadId]) -> &mut Self ### Description Changes the gamepads associated with the effect. The effect will only be played on the gamepads provided in the last call to this function. ``` -------------------------------- ### Mapping::insert_btn Source: https://docs.rs/gilrs/latest/gilrs/struct.Mapping.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Inserts a new button mapping. ```APIDOC ## pub fn insert_btn(&mut self, from: Code, to: Button) -> Option ### Description Inserts a new mapping from an event code to a button. ### Parameters - **from** (Code) - The source event code. - **to** (Button) - The target button. ### Returns - **Option** - The previous event code associated with this button, if any. ``` -------------------------------- ### GilrsBuilder Methods Source: https://docs.rs/gilrs/latest/gilrs/struct.GilrsBuilder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods available on the GilrsBuilder struct for configuring the Gilrs instance. ```APIDOC ## GilrsBuilder Methods ### new() Creates a new builder with default settings. ### with_default_filters(default_filters: bool) Configures whether to use default filters (axis_dpad_to_button, Jitter, deadzone). Defaults to true. ### with_force_feedback(enable_ff: bool) Enables or disables force feedback support. Defaults to true. ### add_mappings(mappings: &str) Adds custom SDL mappings. ### add_env_mappings(env_mappings: bool) Configures whether to add SDL mappings from the SDL_GAMECONTROLLERCONFIG environment variable. Defaults to true. ### add_included_mappings(included_mappings: bool) Configures whether to add SDL mappings included from the SDL_GameControllerDB. Defaults to true. ### set_axis_to_btn(pressed: f32, released: f32) Sets the threshold values for ButtonPressed and ButtonReleased events. Returns an error if pressed <= released or values are outside [0.0, 1.0]. ### set_update_state(enabled: bool) Enables or disables automatic state updates. Useful when using custom filters. ### build() Consumes the builder and returns a Result containing the configured Gilrs instance or an Error. ``` -------------------------------- ### Gilrs::next_event Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the next pending gamepad event without blocking the thread. ```APIDOC ## pub fn next_event(&mut self) -> Option ### Description Returns the next pending event. If there is no pending event, `None` is returned. This function will not block the current thread and is safe to call in an async context. ``` -------------------------------- ### Define GamepadState struct Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search=u32+-%3E+bool The internal structure definition for GamepadState. ```rust pub struct GamepadState { /* private fields */ } ``` -------------------------------- ### Define Gamepad Struct Source: https://docs.rs/gilrs/latest/gilrs/struct.Gamepad.html The internal structure definition for the Gamepad handle. ```rust pub struct Gamepad<'a> { /* private fields */ } ``` -------------------------------- ### Mapping::insert_btn Source: https://docs.rs/gilrs/latest/gilrs/struct.Mapping.html Inserts a new mapping for a button. ```APIDOC ### pub fn insert_btn(&mut self, from: Code, to: Button) -> Option Inserts a new button mapping from a given `Code` to a `Button`. ``` -------------------------------- ### Code::into_u32 Source: https://docs.rs/gilrs/latest/gilrs/ev/struct.Code.html Converts the platform-specific event code into a packed u32 representation. ```APIDOC ## pub fn into_u32(&self) -> u32 ### Description Returns the platform-specific event code packed into a single `u32` value. ### Signature `pub fn into_u32(&self) -> u32` ``` -------------------------------- ### Gilrs::set_mapping Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Configures a custom mapping for a specific gamepad. ```APIDOC ## pub fn set_mapping<'b, O: Into>>(&mut self, gamepad_id: usize, mapping: &MappingData, name: O) -> Result ### Description Sets a gamepad's mapping and returns the SDL2 representation. The name argument allows for a custom gamepad name. ### Parameters - **gamepad_id** (usize) - The ID of the gamepad to map. - **mapping** (&MappingData) - The mapping configuration data. - **name** (O) - Optional custom name for the gamepad. ### Returns - **Result** - The SDL2 mapping string on success, or a MappingError. ``` -------------------------------- ### Replay Struct Definition Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Replay.html?search=u32+-%3E+bool Defines the scheduling parameters for a force feedback effect. ```rust pub struct Replay { pub after: Ticks, pub play_for: Ticks, pub with_delay: Ticks, } ``` -------------------------------- ### EffectBuilder Methods Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.EffectBuilder.html?search=std%3A%3Avec Methods available on the EffectBuilder struct to configure and create force feedback effects. ```APIDOC ## pub fn new() -> Self Creates a new builder with default settings: no gamepads, no base effects, infinite repeat, no distance model, position (0.0, 0.0, 0.0), and gain 1.0. ## pub fn add_effect(&mut self, effect: BaseEffect) -> &mut Self Adds a new BaseEffect to the builder. ## pub fn gamepads(&mut self, ids: &[GamepadId]) -> &mut Self Sets the list of gamepads associated with the effect. The effect will only play on the gamepads specified in the last call to this function. ## pub fn add_gamepad(&mut self, gamepad: &Gamepad<'_>) -> &mut Self Adds a single gamepad to the list of gamepads associated with the effect. ## pub fn repeat(&mut self, repeat: Repeat) -> &mut Self Configures the behavior of the effect when it ends. ## pub fn distance_model(&mut self, model: DistanceModel) -> &mut Self Sets the distance model associated with the effect. ## pub fn position>(&mut self, position: Vec3f) -> &mut Self Sets the 3D position of the effect source. ## pub fn gain(&mut self, gain: f32) -> &mut Self Sets the gain of the effect, clamped to [0.0, f32::MAX]. ## pub fn finish(&mut self, gilrs: &mut Gilrs) -> Result Validates parameters and creates a new Effect. Returns Error::Disconnected or Error::FfNotSupported if a gamepad is invalid, or Error::InvalidDistanceModel if the distance model is invalid. ``` -------------------------------- ### EffectBuilder Methods Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.EffectBuilder.html?search=u32+-%3E+bool Methods available on the EffectBuilder struct for configuring and creating force feedback effects. ```APIDOC ## pub fn new() -> Self Creates a new builder with default settings: no gamepads, no base effects, infinite repeat, no distance model, position (0.0, 0.0, 0.0), and gain 1.0. ## pub fn add_effect(&mut self, effect: BaseEffect) -> &mut Self Adds a new BaseEffect to the builder. ## pub fn gamepads(&mut self, ids: &[GamepadId]) -> &mut Self Sets the list of gamepads associated with the effect. The effect will only play on the gamepads provided in the last call to this function. ## pub fn add_gamepad(&mut self, gamepad: &Gamepad<'_>) -> &mut Self Adds a single gamepad to the list of gamepads associated with the effect. ## pub fn repeat(&mut self, repeat: Repeat) -> &mut Self Configures the behavior of the effect when it ends. ## pub fn distance_model(&mut self, model: DistanceModel) -> &mut Self Sets the distance model associated with the effect. ## pub fn position>(&mut self, position: Vec3f) -> &mut Self Sets the position of the effect source. ## pub fn gain(&mut self, gain: f32) -> &mut Self Sets the gain of the effect, which will be clamped to [0.0, f32::MAX]. ## pub fn finish(&mut self, gilrs: &mut Gilrs) -> Result Validates parameters and creates a new Effect. Returns Error::Disconnected(id) or Error::FfNotSupported(id) if a gamepad is invalid, or Error::InvalidDistanceModel if the model is invalid. ``` -------------------------------- ### pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/fn.deadzone.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Filters an event by applying dead zone logic to controller input. ```APIDOC ## Function: deadzone ### Description Drops events in the dead zone and remaps the value to keep it in the standard range. ### Signature `pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option` ### Parameters - **ev** (Option) - The input event to be filtered. - **gilrs** (&mut Gilrs) - A mutable reference to the Gilrs instance. ### Returns - **Option** - The filtered event, or None if the event was dropped. ``` -------------------------------- ### pub fn next_event_blocking(&mut self, timeout: Option) -> Option Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Retrieves the next pending event, blocking the current thread until an event arrives or the timeout expires. ```APIDOC ## pub fn next_event_blocking(&mut self, timeout: Option) -> Option ### Description Blocks the current thread until an event is available or the optional timeout is reached. Note: This function is not supported on web platforms and will panic. ``` -------------------------------- ### EffectBuilder::add_gamepad Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.EffectBuilder.html Adds a single gamepad to the effect. ```APIDOC ## pub fn add_gamepad(&mut self, gamepad: &Gamepad<'_>) -> &mut Self ### Description Adds a specific gamepad to the list of gamepads associated with the effect. ``` -------------------------------- ### MappingSource Enum Definition Source: https://docs.rs/gilrs/latest/gilrs/enum.MappingSource.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Defines the possible sources for gamepad mappings. ```rust pub enum MappingSource { SdlMappings, Driver, None, } ``` -------------------------------- ### axis_dpad_to_button Function Signature Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/fn.axis_dpad_to_button.html The function signature for mapping axis dpad events to button dpad events. ```rust pub fn axis_dpad_to_button( ev: Option, gilrs: &mut Gilrs, ) -> Option ``` -------------------------------- ### button_data(btn: Code) -> Option<&ButtonData> Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html Retrieves detailed state information for a specific button. ```APIDOC ## pub fn button_data(&self, btn: Code) -> Option<&ButtonData> ### Description Returns the button state and the timestamp of when it last changed. ``` -------------------------------- ### pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/fn.deadzone.html Filters gamepad events by applying a dead zone. Events within the dead zone are dropped, and values are remapped to maintain a standard range. ```APIDOC ## Function: deadzone ### Description Drops events that fall within the dead zone of a gamepad axis and remaps the remaining values to keep them within a standard range. ### Signature `pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option` ### Parameters - **ev** (Option) - The event to be processed. - **gilrs** (&mut Gilrs) - A mutable reference to the Gilrs instance containing configuration and state. ### Returns - **Option** - Returns the processed event if it is outside the dead zone, or None if the event was dropped. ``` -------------------------------- ### deadzone(ev: Option, gilrs: &mut Gilrs) -> Option Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/fn.deadzone.html?search= Drops events in the dead zone and remaps the value to keep it in the standard range. ```APIDOC ## Function: deadzone ### Description Drops events in the dead zone and remaps the value to keep it in the standard range. ### Signature `pub fn deadzone(ev: Option, gilrs: &mut Gilrs) -> Option` ### Parameters - **ev** (Option) - The event to process. - **gilrs** (&mut Gilrs) - A mutable reference to the Gilrs instance. ### Returns - **Option** - The filtered event, or None if the event was dropped. ``` -------------------------------- ### EffectBuilder Methods Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.EffectBuilder.html?search= Methods available on the EffectBuilder struct for configuring and finalizing force feedback effects. ```APIDOC ## pub fn new() -> Self Creates a new builder with default settings (no gamepads, no base effects, infinite repeat, no distance model, position at origin, gain 1.0). ## pub fn add_effect(&mut self, effect: BaseEffect) -> &mut Self Adds a new BaseEffect to the builder. ## pub fn gamepads(&mut self, ids: &[GamepadId]) -> &mut Self Sets the list of gamepads associated with the effect. ## pub fn add_gamepad(&mut self, gamepad: &Gamepad<'_>) -> &mut Self Adds a single gamepad to the list of gamepads associated with the effect. ## pub fn repeat(&mut self, repeat: Repeat) -> &mut Self Configures the behavior of the effect when it ends. ## pub fn distance_model(&mut self, model: DistanceModel) -> &mut Self Sets the distance model for the effect. ## pub fn position>(&mut self, position: Vec3f) -> &mut Self Sets the 3D position of the effect source. ## pub fn gain(&mut self, gain: f32) -> &mut Self Sets the gain of the effect, clamped to [0.0, f32::MAX]. ## pub fn finish(&mut self, gilrs: &mut Gilrs) -> Result Validates parameters and creates the final Effect. Returns Error::Disconnected(id), Error::FfNotSupported(id), or Error::InvalidDistanceModel on failure. ``` -------------------------------- ### Implement a custom filter in Rust Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/index.html Shows how to implement the FilterFn trait to create a custom filter that drops events with Unknown axis or button types. ```rust use gilrs::ev::filter::FilterFn; use gilrs::{Gilrs, Event, EventType, Button, Axis, Filter}; struct UnknownSlayer; impl FilterFn for UnknownSlayer { fn filter(&self, ev: Option, _gilrs: &mut Gilrs) -> Option { match ev { Some(Event { event: EventType::ButtonPressed(Button::Unknown, ..), id, .. }) | Some(Event { event: EventType::ButtonReleased(Button::Unknown, ..), id, .. }) | Some(Event { event: EventType::AxisChanged(Axis::Unknown, ..), id, .. }) => Some(Event::new(id, EventType::Dropped)), _ => ev, } } } ``` -------------------------------- ### Effect::add_gamepad Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Effect.html?search= Adds a single gamepad to the effect's association list. ```APIDOC ## pub fn add_gamepad(&self, gamepad: &Gamepad<'_>) -> Result<(), Error> ### Description Adds a specific gamepad to the list of gamepads associated with the effect. ``` -------------------------------- ### Re-exporting Gilrs components Source: https://docs.rs/gilrs/latest/gilrs/index.html?search= These re-exports provide direct access to core event and gamepad functionality. ```rust pub use crate::ev::filter::Filter; ``` ```rust pub use crate::ev::Axis; ``` ```rust pub use crate::ev::Button; ``` ```rust pub use crate::ev::Event; ``` ```rust pub use crate::ev::EventType; ``` -------------------------------- ### Effect Methods Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Effect.html Methods available on the Effect struct to control force feedback behavior. ```APIDOC ## play() ### Description Plays the force feedback effect on all associated gamepads. ## stop() ### Description Stops the force feedback effect. ## set_gamepads(ids: &[GamepadId], gilrs: &Gilrs) ### Description Changes the gamepads associated with the effect. The effect will only be played on the gamepads provided in the last call to this function. ## add_gamepad(gamepad: &Gamepad<'_>) ### Description Adds a specific gamepad to the list of gamepads associated with the effect. ## set_repeat(repeat: Repeat) ### Description Configures the behavior of the effect when it reaches its end. ## set_distance_model(model: DistanceModel) ### Description Updates the distance model associated with the effect. ## set_position>(position: Vec3f) ### Description Sets the spatial position of the effect source. ## set_gain(gain: f32) ### Description Sets the gain of the effect. The value is clamped to the range [0.0, f32::MAX]. ``` -------------------------------- ### value Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search= Retrieves the current value of a button or axis. ```APIDOC ## pub fn value(&self, el: Code) -> f32 ### Description Returns the value of the specified element (axis or button). Returns 0.0 if there is no information about it. ``` -------------------------------- ### Iterate over input data Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search=u32+-%3E+bool Methods to retrieve iterators for button or axis data. ```rust pub fn buttons(&self) -> ButtonDataIter<'_> ``` ```rust pub fn axes(&self) -> AxisDataIter<'_> ``` -------------------------------- ### Gilrs::next_event Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Retrieves the next event from the internal event queue. ```APIDOC ## Gilrs::next_event ### Description Retrieves the next event from the queue, such as button presses or connection changes. ### Signature `pub fn next_event(&mut self) -> Option` ``` -------------------------------- ### Effect::set_repeat Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Effect.html?search= Configures the repeat behavior of the effect. ```APIDOC ## pub fn set_repeat(&self, repeat: Repeat) -> Result<(), Error> ### Description Changes the behavior of the effect when it reaches its end. ``` -------------------------------- ### Gilrs::gamepad Source: https://docs.rs/gilrs/latest/gilrs/struct.Gilrs.html Retrieves a handle to a gamepad by its ID. ```APIDOC ## Gilrs::gamepad ### Description Returns a handle to a gamepad with the given ID. This will return a handle even if the gamepad is currently disconnected. ### Signature `pub fn gamepad(&self, id: GamepadId) -> Gamepad` ``` -------------------------------- ### button_data Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search= Retrieves detailed state information for a specific button. ```APIDOC ## pub fn button_data(&self, btn: Code) -> Option<&ButtonData> ### Description Returns the button state and the timestamp of its last change. ``` -------------------------------- ### button_data Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves detailed state information for a specific button. ```APIDOC ## pub fn button_data(&self, btn: Code) -> Option<&ButtonData> ### Description Returns the button state and the timestamp of when it last changed. ### Parameters - **btn** (Code) - Required - The button code to retrieve data for. ``` -------------------------------- ### Ticks::from_ms Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Ticks.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new Ticks instance from a duration in milliseconds. ```APIDOC ## pub fn from_ms(dur: u32) -> Self ### Description Creates a new `Ticks` instance from the provided duration in milliseconds. ### Parameters - **dur** (u32) - Required - The duration in milliseconds. ``` -------------------------------- ### Ticks::from_ms Source: https://docs.rs/gilrs/latest/gilrs/ff/struct.Ticks.html?search=std%3A%3Avec Creates a new Ticks instance from a duration in milliseconds. ```APIDOC ## pub fn from_ms(dur: u32) -> Self ### Description Creates a new `Ticks` instance from the provided duration in milliseconds. ### Parameters - **dur** (u32) - Required - The duration in milliseconds. ### Returns - **Self** - A new `Ticks` instance. ``` -------------------------------- ### value Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the current value of an axis or button. ```APIDOC ## pub fn value(&self, el: Code) -> f32 ### Description Returns the value of the specified element (axis or button). Returns 0.0 if there is no information available. ### Parameters - **el** (Code) - Required - The axis or button code to query. ``` -------------------------------- ### Retrieve specific input data Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html?search=u32+-%3E+bool Fetches the state and change timestamp for a specific button or axis. ```rust pub fn button_data(&self, btn: Code) -> Option<&ButtonData> ``` ```rust pub fn axis_data(&self, axis: Code) -> Option<&AxisData> ``` -------------------------------- ### Jitter::new() Source: https://docs.rs/gilrs/latest/gilrs/ev/filter/struct.Jitter.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new instance of the Jitter filter with a default threshold of 0.01. ```APIDOC ## pub fn new() -> Self ### Description Creates a new `Jitter` filter instance with the threshold initialized to 0.01. ### Signature `pub fn new() -> Self` ``` -------------------------------- ### value(el: Code) -> f32 Source: https://docs.rs/gilrs/latest/gilrs/ev/state/struct.GamepadState.html Retrieves the current value of a button or axis. ```APIDOC ## pub fn value(&self, el: Code) -> f32 ### Description Returns the value of the specified element (axis or button). Returns 0.0 if there is no information available. ``` -------------------------------- ### Mapping Struct Definition Source: https://docs.rs/gilrs/latest/gilrs/struct.Mapping.html?search= The internal structure definition for Mapping. ```rust pub struct Mapping { /* private fields */ } ``` -------------------------------- ### Convert Code to u32 Source: https://docs.rs/gilrs/latest/gilrs/ev/struct.Code.html?search= Converts the platform-specific event code into a single u32 value. ```rust pub fn into_u32(&self) -> u32 ```