bluetooth_core 0.0.1

Cross-platform Bluetooth LE (btleplug wrapper) with a small C ABI.
Documentation
//! Scans for nearby BLE devices using the in-process API (no FFI).
//!
//! Run from the repo root:
//!   cargo run --manifest-path native/bluetooth_core/Cargo.toml --example scan

use std::time::{Duration, Instant};

use bluetooth_core::{BleEvent, BleSession};

fn main() {
    let session = match BleSession::new() {
        Ok(s) => s,
        Err(e) => {
            eprintln!("could not open BLE session: {e}");
            std::process::exit(1);
        }
    };

    if let Err(e) = session.start_scan(None) {
        eprintln!("could not start scan: {e}");
        std::process::exit(1);
    }
    println!("Scanning for 5 seconds...");

    let deadline = Instant::now() + Duration::from_secs(5);
    while Instant::now() < deadline {
        while let Some(event) = session.poll_event() {
            if let BleEvent::Device { device } = event {
                println!(
                    "  {}  {}  {} dBm",
                    device.id,
                    device.name.as_deref().unwrap_or("(unknown)"),
                    device
                        .rssi
                        .map(|r| r.to_string())
                        .unwrap_or_else(|| "?".to_string()),
                );
            }
        }
        std::thread::sleep(Duration::from_millis(100));
    }

    let _ = session.stop_scan();
    println!("Done.");
}