diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-04-30 18:45:24 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-04-30 18:45:24 -0400 |
commit | 4a7aa1317e77e6d7a5b5dc4a20b238d12efb148e (patch) | |
tree | d5b45dd40c4b5b21d484a16e8df4ceeeda475f02 /src | |
parent | f89076f8e0da586248f1a5e9c17db19177636a34 (diff) | |
download | switchpro-master.tar.gz switchpro-master.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 23 |
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(()) } |