gearvr_controller/lib.rs
1//! Read the Samsung Gear VR Controller (ET-YO324) over Bluetooth LE.
2//!
3//! The crate has three layers:
4//!
5//! - [`protocol`] decodes the controller's 60-byte data packets. It has no dependencies.
6//! - [`orientation`] turns the gyroscope and accelerometer samples into an orientation.
7//! - [`ble`] (feature `ble`, on by default) finds the controller, connects, and delivers
8//! packets, using [btleplug](https://docs.rs/btleplug) and tokio.
9//!
10//! [`sim`] produces synthetic packets so applications can be developed without the hardware.
11//!
12//! # Example
13//!
14//! Decoding and tracking need no Bluetooth, so this runs anywhere:
15//!
16//! ```
17//! use gearvr_controller::{sim::Simulator, Orientation, Packet};
18//!
19//! let mut controller = Simulator::new();
20//! let mut orientation = Orientation::new();
21//! for _ in 0..100 {
22//! let bytes = controller.next_bytes(); // with real hardware: a Bluetooth notification
23//! let packet = Packet::parse(&bytes).unwrap();
24//! orientation.update(&packet);
25//! }
26//! let e = orientation.euler();
27//! println!("yaw {:.0}° pitch {:.0}° roll {:.0}°", e.yaw.to_degrees(), e.pitch.to_degrees(), e.roll.to_degrees());
28//! ```
29//!
30//! See [`ble`] for the same loop driven by a real controller.
31//!
32//! # Axes
33//!
34//! Sensor values are in the controller's own frame: **x** points right, **y** points forward
35//! out of the tip, and **z** points up out of the touchpad face. The accelerometer reads
36//! about +9.8 m/s² on whichever axis points up.
37
38#[cfg(feature = "ble")]
39pub mod ble;
40mod event;
41pub mod orientation;
42pub mod protocol;
43pub mod sim;
44
45pub use event::Event;
46pub use orientation::{Euler, Orientation, Quat};
47pub use protocol::{Buttons, Command, ImuSample, Packet, ParseError, Touch};