tasks: ble: drop unnessicary Backoff usage

This commit is contained in:
2026-03-24 12:36:25 +01:00
parent 6779881523
commit 38f49513f3

View File

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