diff --git a/src/tasks/ble.rs b/src/tasks/ble.rs index f518561..6243e3d 100644 --- a/src/tasks/ble.rs +++ b/src/tasks/ble.rs @@ -7,7 +7,7 @@ use static_cell::{ConstStaticCell, StaticCell}; use trouble_host::{prelude::*, types::gatt_traits::FromGattError}; use log::*; -use crate::{backoff::Backoff, events::Prediction}; +use crate::events::Prediction; #[gatt_server] struct SerialServer { @@ -101,9 +101,9 @@ static STATIC_CLIENT_PREDICTIONS: ConstStaticCell, predictions: DynSubscriber<'static, Prediction>, spawner: Spawner) { info!("Starting BLE stack"); - let server = STATIC_SERVER.init(SerialServer::new_with_config(GapConfig::Peripheral(PeripheralConfig { name: "Renderbug", appearance: &appearance::light_source::LED_ARRAY })).unwrap()); + let server = STATIC_SERVER.init_with(|| { SerialServer::new_with_config(GapConfig::Peripheral(PeripheralConfig { name: "Renderbug", appearance: &appearance::light_source::LED_ARRAY })).unwrap() }); let control: ExternalController, 1> = ExternalController::new(ble); - let stack = STATIC_STACK.init(trouble_host::new(control, STATIC_RESOURCES.init(HostResources::new()))); + let stack = STATIC_STACK.init_with(|| { trouble_host::new(control, STATIC_RESOURCES.init_with(|| { HostResources::new() })) }); let Host { mut peripheral, mut runner, .. } = stack.build(); let client_predictions = STATIC_CLIENT_PREDICTIONS.take(); @@ -114,43 +114,41 @@ pub async fn ble_task(ble: BleConnector<'static>, predictions: DynSubscriber<'st runner.run(), async { loop { - let advertiser = Backoff::from_secs(5).forever().attempt(async || { - info!("Starting BLE advertising"); - let mut adv_data = [0; 64]; - let len = AdStructure::encode_slice( - &[ - AdStructure::CompleteLocalName("Renderbug".as_bytes()), - AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED), - AdStructure::ServiceUuids128(&[ - [ // Serial service - 0x6E, 0x40, 0x00, 0x01, - 0xB5, 0xA3, - 0xF3, 0x93, - 0xE0, 0xA9, - 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E - //0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, - //0x01, 0x00, 0x40, 0x6E, - ], - [ // Renderbug mesh service - 0x00, 0x00, 0x00, 0x00, - 0xf4, 0x3a, - 0x48, 0xc4, - 0x84, 0x11, - 0xef, 0xe6, 0xa3, 0x8a, 0x5d, 0x75 - ] - ]), - AdStructure::ServiceUuids16(&[ - // Location and navigation - [0x18, 0x19] - ]) - ], - &mut adv_data[..], - ).unwrap(); - peripheral.advertise( - &Default::default(), - Advertisement::ConnectableScannableUndirected { adv_data: &adv_data[..len], scan_data: &[] } - ).await - }).await.unwrap(); + info!("Starting BLE advertising"); + let mut adv_data = [0; 64]; + let len = AdStructure::encode_slice( + &[ + AdStructure::CompleteLocalName("Renderbug".as_bytes()), + AdStructure::Flags(LE_GENERAL_DISCOVERABLE | BR_EDR_NOT_SUPPORTED), + AdStructure::ServiceUuids128(&[ + [ // Serial service + 0x6E, 0x40, 0x00, 0x01, + 0xB5, 0xA3, + 0xF3, 0x93, + 0xE0, 0xA9, + 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E + //0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, + //0x01, 0x00, 0x40, 0x6E, + ], + [ // Renderbug mesh service + 0x00, 0x00, 0x00, 0x00, + 0xf4, 0x3a, + 0x48, 0xc4, + 0x84, 0x11, + 0xef, 0xe6, 0xa3, 0x8a, 0x5d, 0x75 + ] + ]), + AdStructure::ServiceUuids16(&[ + // Location and navigation + [0x18, 0x19] + ]) + ], + &mut adv_data[..], + ).unwrap(); + let advertiser = peripheral.advertise( + &Default::default(), + Advertisement::ConnectableScannableUndirected { adv_data: &adv_data[..len], scan_data: &[] } + ).await.unwrap(); info!("Waiting for connection"); match advertiser.accept().await.and_then(|raw| { raw.with_attribute_server(server) }) { Ok(conn) => {