Skip to main content

toio/
lib.rs

1//! [toio](https://toio.io/) driver in Rust.
2//!
3//! Supports all the messages defined in [the technical specification](https://toio.github.io/toio-spec/).
4//! Provides async/await API.
5//! Provides the similar API as [JavaScript version](https://github.com/toio/toio.js/).
6//! Also provides the low-level API, which allows fine-grained control and configuration.
7//!
8//! Plans to be cross-platform. The targets are:
9//!
10//! * macOS
11//! * Windows 10 (TODO)
12//! * Linux (TODO)
13//!
14//! ```no_run
15//! use std::time::Duration;
16//! use toio::Cube;
17//! use tokio::time::delay_for;
18//!
19//! #[tokio::main]
20//! async fn main() {
21//!     // Search for the nearest cube.
22//!     let mut cube = Cube::search().nearest().await.unwrap();
23//!
24//!     // Connect.
25//!     cube.connect().await.unwrap();
26//!
27//!     // Print status.
28//!     println!("version   : {}", cube.version().await.unwrap());
29//!     println!("battery   : {}%", cube.battery().await.unwrap());
30//!     println!("button    : {}", cube.button().await.unwrap());
31//!
32//!     // Move forward.
33//!     cube.go(10, 10, None).await.unwrap();
34//!
35//!     delay_for(Duration::from_secs(3)).await;
36//!
37//!     // Spin for 2 seconds.
38//!     cube.go(100, 5, Some(Duration::from_secs(2))).await.unwrap();
39//!
40//!     delay_for(Duration::from_secs(3)).await;
41//! }
42//! ```
43
44/// Abstracts BLE.
45#[macro_use]
46pub mod ble;
47
48/// Protocol data structures.
49pub mod proto;
50
51mod cube;
52mod decode;
53mod encode;
54mod searcher;
55
56pub use cube::{Cube, Event, EventStream, LightOp, Position, SoundOp, StdId};
57pub use proto::{IdPos, IdStd, Note, Posture, SoundPresetId};
58pub use searcher::*;