Skip to content

Commit

Permalink
Add static receiver
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiseiYokoyama committed May 30, 2020
1 parent 680e82b commit b8c339c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exclude = ["/images/*"]
[dependencies]
hidapi-alt-for-hidapi-issue-127 = "1.2.1"
crossbeam-channel = "0.4.2"
lazy_static = "1.4.0"

[dev-dependencies]
doc-comment = "0.3.3"
Expand Down
10 changes: 10 additions & 0 deletions src/joycon/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,13 @@ impl JoyConManager {
}
}

lazy_static! {
pub static ref JOYCON_RECEIVER: crossbeam_channel::Receiver<Arc<Mutex<JoyConDevice>>> = {
let manager = JoyConManager::get_instance();
let manager = match manager.lock() {
Ok(manager) => manager,
Err(e) => e.into_inner(),
};
manager.new_devices()
};
}
2 changes: 1 addition & 1 deletion src/joycon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use driver::{
lights,
device_info,
};
pub use manager::JoyConManager;
pub use manager::{JoyConManager, JOYCON_RECEIVER};

use std::sync::Arc;
use std::fmt::{Debug, Formatter};
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
//! [Deal with LED (Player lights)]: joycon/lights/index.html
//! [Vibration (Rumble)]:joycon/struct.Rumble.html
extern crate hidapi_alt_for_hidapi_issue_127 as hidapi;
#[macro_use]
extern crate lazy_static;

pub mod joycon;

Expand Down

0 comments on commit b8c339c

Please sign in to comment.