1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Stick
//
// Copyright (c) 2017-2020 Jeron Aldaron Lau
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// https://apache.org/licenses/LICENSE-2.0>, or the Zlib License, <LICENSE-ZLIB
// or http://opensource.org/licenses/Zlib>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
//
//! ## Getting Started
//! Add the following to your *Cargo.toml*:
//!
//! ```toml
//! [dependencies]
//! pasts = "0.6"
//! stick = "0.11"
//! ```
//!
//! ### Example
//! This example demonstrates getting joystick input and sending haptic
//! feedback (copied from *examples/haptic.rs*):
//!
//! ```rust,no_run
//! use pasts::prelude::*;
//! use stick::{Controller, Event};
//!
//! async fn event_loop() {
//!     let mut listener = Controller::listener();
//!     let mut ctlrs = Vec::<Controller>::new();
//!     'e: loop {
//!         match poll![listener, poll!(ctlrs)].await.1 {
//!             (_, Event::Connect(new)) => {
//!                 println!(
//!                     "Connected p{}, id: {:04X}_{:04X}_{:04X}_{:04X}, name: {}",
//!                     ctlrs.len() + 1,
//!                     new.id()[0],
//!                     new.id()[1],
//!                     new.id()[2],
//!                     new.id()[3],
//!                     new.name(),
//!                 );
//!                 ctlrs.push(*new);
//!             }
//!             (id, Event::Disconnect) => {
//!                 println!("Disconnected p{}", id + 1);
//!                 ctlrs.swap_remove(id);
//!             }
//!             (id, Event::Home(true)) => {
//!                 println!("p{} ended the session", id + 1);
//!                 break 'e;
//!             }
//!             (id, event) => {
//!                 println!("p{}: {}", id + 1, event);
//!                 match event {
//!                     Event::ActionA(pressed) => {
//!                         ctlrs[id].rumble(if pressed { 1.0 } else { 0.0 });
//!                     }
//!                     Event::ActionB(pressed) => {
//!                         ctlrs[id].rumble(if pressed { 0.3 } else { 0.0 });
//!                     }
//!                     _ => {}
//!                 }
//!             }
//!         }
//!     }
//! }
//!
//! fn main() {
//!     exec!(event_loop());
//! }
//! ```

#![doc(
    html_logo_url = "https://libcala.github.io/logo.svg",
    html_favicon_url = "https://libcala.github.io/icon.svg",
    html_root_url = "https://docs.rs/stick"
)]
#![deny(unsafe_code)]
#![warn(
    anonymous_parameters,
    missing_copy_implementations,
    missing_debug_implementations,
    missing_docs,
    nonstandard_style,
    rust_2018_idioms,
    single_use_lifetimes,
    trivial_casts,
    trivial_numeric_casts,
    unreachable_pub,
    unused_extern_crates,
    unused_qualifications,
    variant_size_differences
)]

mod ctlr;
mod event;

#[cfg_attr(target_arch = "wasm32", path = "ffi/wasm32.rs")]
#[cfg_attr(
    not(target_arch = "wasm32"),
    cfg_attr(target_os = "linux", path = "ffi/linux.rs"),
    cfg_attr(target_os = "android", path = "ffi/android.rs"),
    cfg_attr(target_os = "macos", path = "ffi/macos.rs"),
    cfg_attr(target_os = "ios", path = "ffi/ios.rs"),
    cfg_attr(target_os = "windows", path = "ffi/windows.rs"),
    cfg_attr(
        any(
            target_os = "freebsd",
            target_os = "dragonfly",
            target_os = "bitrig",
            target_os = "openbsd",
            target_os = "netbsd"
        ),
        path = "ffi/bsd.rs"
    ),
    cfg_attr(target_os = "fuchsia", path = "ffi/fuchsia.rs"),
    cfg_attr(target_os = "redox", path = "ffi/redox.rs"),
    cfg_attr(target_os = "none", path = "ffi/none.rs"),
    cfg_attr(target_os = "dummy", path = "ffi/dummy.rs")
)]
#[allow(unsafe_code)]
mod ffi;

pub use ctlr::Controller;
pub use event::Event;