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,7 +114,6 @@ 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(
@@ -146,11 +145,10 @@ pub async fn ble_task(ble: BleConnector<'static>, predictions: DynSubscriber<'st
], ],
&mut adv_data[..], &mut adv_data[..],
).unwrap(); ).unwrap();
peripheral.advertise( let advertiser = 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 ).await.unwrap();
}).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) => {