Skip to content

Commit 5ec42d5

Browse files
committed
bluetooth: add dongle mode (hardcoded)
1 parent 5ec0f63 commit 5ec42d5

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

src/bluetooth.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,36 +133,39 @@ async fn power_up_and_wait_for_connection(
133133
let mut handle_aa = session.register_profile(profile).await?;
134134
info!("{} 📱 AA Wireless Profile: registered", NAME);
135135

136-
// Headset profile
137-
let profile = Profile {
138-
uuid: HSP_HS_UUID,
139-
name: Some("HSP HS".to_string()),
140-
require_authentication: Some(false),
141-
require_authorization: Some(false),
142-
..Default::default()
143-
};
144-
let handle_hsp = match session.register_profile(profile).await {
145-
Ok(handle_hsp) => {
146-
info!("{} 🎧 Headset Profile (HSP): registered", NAME);
147-
Some(handle_hsp)
148-
}
149-
Err(e) => {
150-
warn!(
151-
"{} 🎧 Headset Profile (HSP) registering error: {}, ignoring",
152-
NAME, e
153-
);
154-
None
136+
let mut handle_hsp = None;
137+
if true {
138+
// Headset profile
139+
let profile = Profile {
140+
uuid: HSP_HS_UUID,
141+
name: Some("HSP HS".to_string()),
142+
require_authentication: Some(false),
143+
require_authorization: Some(false),
144+
..Default::default()
145+
};
146+
match session.register_profile(profile).await {
147+
Ok(handle) => {
148+
info!("{} 🎧 Headset Profile (HSP): registered", NAME);
149+
handle_hsp = Some(handle);
150+
}
151+
Err(e) => {
152+
warn!(
153+
"{} 🎧 Headset Profile (HSP) registering error: {}, ignoring",
154+
NAME, e
155+
);
156+
}
155157
}
156-
};
158+
}
157159

158160
info!("{} ⏳ Waiting for phone to connect via bluetooth...", NAME);
159161

160162
// try to connect to saved devices or provided one via command line
161-
let connect_task: Option<JoinHandle<Result<()>>> = match connect {
162-
Some(address) => {
163+
let mut connect_task: Option<JoinHandle<Result<()>>> = None;
164+
if true {
165+
if let Some(address) = connect {
163166
let adapter_cloned = adapter.clone();
164167

165-
Some(tokio::spawn(async move {
168+
connect_task = Some(tokio::spawn(async move {
166169
let addresses = if address == Address::any() {
167170
info!("{} 🥏 Enumerating known bluetooth devices...", NAME);
168171
adapter_cloned.device_addresses().await?
@@ -196,10 +199,9 @@ async fn power_up_and_wait_for_connection(
196199
}
197200
sleep(Duration::from_secs(1)).await;
198201
}
199-
}))
202+
}));
200203
}
201-
None => None,
202-
};
204+
}
203205

204206
// handling connection to headset profile in own task
205207
let task_hsp = {

0 commit comments

Comments
 (0)