12 releases (breaking)

✓ Uses Rust 2018 edition

0.9.0 May 18, 2020
0.7.1 Jul 18, 2019
0.4.1 Aug 5, 2018
0.4.0 May 24, 2018
0.3.0 Feb 4, 2018

#5 in Hardware support

Download history 71/week @ 2020-01-25 237/week @ 2020-02-01 808/week @ 2020-02-08 774/week @ 2020-02-15 700/week @ 2020-02-22 1759/week @ 2020-02-29 1176/week @ 2020-03-07 955/week @ 2020-03-14 94/week @ 2020-03-21 13/week @ 2020-03-28 38/week @ 2020-04-04 59/week @ 2020-04-11 20/week @ 2020-04-18 7/week @ 2020-04-25 31/week @ 2020-05-02 8/week @ 2020-05-09

1,745 downloads per month
Used in 8 crates (2 directly)

Apache-2.0 OR Zlib

60KB
1K SLoC

Stick

Platform-agnostic asynchronous gamepad library for Rust

Build Status Docs crates.io

Stick supports getting controller input, as well as using rumble haptic effects.

Platform Support

  • Linux

Planned Platform Support

  • Windows
  • MacOS
  • BSD
  • Redox
  • Fuchsia
  • Android
  • iOS
  • Web Assembly
  • Nintendo Switch (And other game consoles)
  • Others

Table of Contents

Getting Started

Add the following to your Cargo.toml.

[dependencies]
pasts = "0.4"
stick = "0.9"

Example

This example can be used to test joystick input and haptic feedback.

use pasts::{CvarExec, prelude::*};
use stick::{Event, Gamepad, Port};

async fn event_loop() {
    let mut port = Port::new();
    let mut gamepads = Vec::<Gamepad>::new();
    'e: loop {
        match [port.fut(), gamepads.select().fut()]
            .select()
            .await
            .1
        {
            (_, Event::Connect(gamepad)) => {
                println!(
                    "Connected p{}, id: {:X}, name: {}",
                    gamepads.len() + 1,
                    gamepad.id(),
                    gamepad.name(),
                );
                gamepads.push(*gamepad);
            }
            (id, Event::Disconnect) => {
                println!("Disconnected p{}", id + 1);
                gamepads.swap_remove(id);
            }
            (id, Event::Quit) => {
                println!("p{} ended the session", id + 1);
                break 'e;
            }
            (id, event) => {
                println!("p{}: {}", id + 1, event);
                match event {
                    Event::Accept(pressed) => {
                        gamepads[id].rumble(if pressed {
                            0.25
                        } else {
                            0.0
                        });
                    }
                    Event::Cancel(pressed) => {
                        gamepads[id].rumble(if pressed {
                            1.0
                        } else {
                            0.0
                        });
                    }
                    _ => {}
                }
            }
        }
    }
}

fn main() {
    static EXECUTOR: CvarExec = CvarExec::new();

    EXECUTOR.block_on(event_loop())
}

API

API documentation can be found on docs.rs.

Features

There are no optional features.

Upgrade

You can use the changelog to facilitate upgrading this crate as a dependency.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Contributors are always welcome (thank you for being interested!), whether it be a bug report, bug fix, feature request, feature implementation or whatever. Don't be shy about getting involved. I always make time to fix bugs, so usually a patched version of the library will be out a few days after a report. Features requests will not complete as fast. If you have any questions, design critques, or want me to find you something to work on based on your skill level, you can email me at jeronlau@plopgrizzly.com. Otherwise, here's a link to the issues on GitHub. Before contributing, check out the contribution guidelines, and, as always, make sure to follow the code of conduct.

Dependencies