Skip to content

Commit 79ae571

Browse files
committed
main: cleanup old Bluetooth init leftovers
1 parent afad52e commit 79ae571

File tree

1 file changed

+7
-53
lines changed

1 file changed

+7
-53
lines changed

src/main.rs

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -252,23 +252,10 @@ async fn tokio_main(
252252
}
253253
});
254254

255+
// initial bluetooth setup
255256
let mut bluetooth;
256257
loop {
257-
match bluetooth::init(
258-
cfg.btalias.clone(),
259-
// true, // enable BLE
260-
cfg.advertise,
261-
// true, // enable classic BT
262-
cfg.dongle_mode,
263-
// cfg.connect,
264-
// wifi_conf.clone(),
265-
// tcp_start.clone(),
266-
// Duration::from_secs(cfg.bt_timeout_secs.into()),
267-
// state.clone(),
268-
// stopped,
269-
)
270-
.await
271-
{
258+
match bluetooth::init(cfg.btalias.clone(), cfg.advertise, cfg.dongle_mode).await {
272259
Ok(result) => {
273260
bluetooth = result;
274261
break;
@@ -282,10 +269,11 @@ async fn tokio_main(
282269
}
283270
if cfg.advertise {
284271
if let Err(e) = bluetooth.start_ble(state.clone(), true).await {
285-
info!("{} Error starting BLE: {}", NAME, e);
272+
warn!("{} Error starting BLE: {}", NAME, e);
286273
}
287274
}
288275

276+
// main connection loop
289277
let change_usb_order = cfg.change_usb_order;
290278
loop {
291279
if let Some(ref mut leds) = led_manager {
@@ -301,38 +289,16 @@ async fn tokio_main(
301289
enable_usb_if_present(&mut usb, accessory_started.clone()).await;
302290
}
303291

304-
// --- Setup Bluetooth (Classic + BLE) ---
305-
// read and clone the effective config in advance to avoid holding the lock
306-
let cfg = config.read().await.clone();
307-
let stopped = cfg.action_requested == Some(Action::Stop);
308-
309-
// --- Keep BLE advertisement and GATT server alive ---
310-
//let mut bt_stop = None;
311-
//let mut btle_keepalive = None;
312-
//let mut adv_keepalive = None;
313-
314-
//if let Some(resources) = bluetooth_resources {
315-
// if let Some(state) = resources.bt_state {
316-
// bt_stop = Some(tokio::spawn(async move {
317-
// bluetooth::bluetooth_stop(state).await.unwrap_or_else(|e| {
318-
// error!("{} Error stopping Bluetooth: {}", NAME, e);
319-
// })
320-
// }));
321-
// }
322-
323-
// // keep BLE handles alive for the lifetime of this loop iteration
324-
// btle_keepalive = resources.btle_handle;
325-
// adv_keepalive = resources.adv_handle;
326-
//}
292+
// bluetooth handshake
327293
if let Err(e) = bluetooth
328294
.aa_handshake(
329295
cfg.dongle_mode,
330-
cfg.connect,
296+
cfg.connect.clone(),
331297
wifi_conf.clone().unwrap(),
332298
tcp_start.clone(),
333299
Duration::from_secs(cfg.bt_timeout_secs.into()),
334300
state.clone(),
335-
stopped,
301+
cfg.action_requested == Some(Action::Stop),
336302
)
337303
.await
338304
{
@@ -345,18 +311,6 @@ async fn tokio_main(
345311
enable_usb_if_present(&mut usb, accessory_started.clone()).await;
346312
}
347313

348-
//if let Some(bt_stop) = bt_stop {
349-
// // wait for bluetooth stop properly
350-
// let _ = bt_stop.await;
351-
//}
352-
// --- Clean up previous BLE resources ---
353-
//if let Some(handle) = btle_keepalive.take() {
354-
// drop(handle); // or handle.stop().await if your library supports it
355-
//}
356-
//if let Some(handle) = adv_keepalive.take() {
357-
// drop(handle); // stops advertising
358-
//}
359-
360314
// inform via LED about successful connection
361315
if let Some(ref mut leds) = led_manager {
362316
leds.set_led(LedColor::Blue, LedMode::On).await;

0 commit comments

Comments
 (0)