Skip to main content

Module ble

Module ble 

Source
Expand description

Bluetooth LE transport, built on btleplug and tokio.

There are two ways in:

  • events is the easy one. It runs a background task that finds the controller, connects, keeps the data flowing and reconnects after the controller goes to sleep.
  • Controller is the manual one: connect once and read packets yourself.
use gearvr_controller::{ble, Orientation};

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let mut orientation = Orientation::new();
    let mut events = ble::events();
    while let Some(event) = events.recv().await {
        match event {
            ble::Event::Packet(packet) => {
                orientation.update(&packet);
                let e = orientation.euler();
                println!("yaw {:.0}°  buttons {:?}", e.yaw.to_degrees(), packet.buttons);
            }
            other => println!("{other:?}"),
        }
    }
}

§Things to know

  • The controller sleeps after about a minute without movement and drops the connection. Pressing any button wakes it; events then reconnects on its own.
  • Only one program can hold the connection. If a phone or a browser tab is connected, the controller will not be found.
  • On macOS the terminal (or app) running your program needs the Bluetooth permission: System Settings → Privacy & Security → Bluetooth.

Structs§

Controller
A connected controller.

Enums§

Error
What can go wrong talking to the controller.
Event
What a connection to a controller reports.

Functions§

events
Starts a background task that finds the controller, streams its packets, and reconnects whenever the connection drops. The task stops when the receiver is dropped.

Type Aliases§

PacketStream
A stream of decoded packets. Short packets (sent when the controller is not in sensor mode) appear as errors.