aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..f48d20e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,22 @@
-fn main() {
- println!("Hello, world!");
+use tokio_stream::StreamExt as _;
+
+#[tokio::main]
+async fn main() -> Result<(), Box<dyn std::error::Error>> {
+ let controller = std::env::args().nth(1).unwrap().parse().unwrap();
+
+ let (_, session) = bluez_async::BluetoothSession::new().await?;
+ session.start_discovery().await?;
+
+ let mut stream = session.event_stream().await?;
+ while let Some(event) = stream.next().await {
+ if let bluez_async::BluetoothEvent::Device { id, .. } = &event {
+ let info = session.get_device_info(id).await?;
+ if info.mac_address == controller {
+ session.connect(id).await?;
+ break;
+ }
+ }
+ }
+
+ Ok(())
}