diff --git a/src/tasks/ble.rs b/src/tasks/ble.rs index eefc452..f518561 100644 --- a/src/tasks/ble.rs +++ b/src/tasks/ble.rs @@ -3,7 +3,7 @@ use embassy_executor::Spawner; use embassy_futures::select::Either; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, pubsub::{DynSubscriber, PubSubChannel, Publisher}}; use esp_radio::ble::controller::BleConnector; -use static_cell::StaticCell; +use static_cell::{ConstStaticCell, StaticCell}; use trouble_host::{prelude::*, types::gatt_traits::FromGattError}; use log::*; @@ -96,7 +96,7 @@ async fn client_prediction_task(mut src: DynSubscriber<'static, Prediction>, sin static STATIC_RESOURCES: StaticCell> = StaticCell::new(); static STATIC_STACK: StaticCell, 1>, DefaultPacketPool>> = StaticCell::new(); static STATIC_SERVER: StaticCell = StaticCell::new(); -static STATIC_CLIENT_PREDICTIONS: StaticCell> = StaticCell::new(); +static STATIC_CLIENT_PREDICTIONS: ConstStaticCell> = ConstStaticCell::new(PubSubChannel::new()); #[embassy_executor::task] pub async fn ble_task(ble: BleConnector<'static>, predictions: DynSubscriber<'static, Prediction>, spawner: Spawner) { @@ -106,7 +106,7 @@ pub async fn ble_task(ble: BleConnector<'static>, predictions: DynSubscriber<'st let stack = STATIC_STACK.init(trouble_host::new(control, STATIC_RESOURCES.init(HostResources::new()))); let Host { mut peripheral, mut runner, .. } = stack.build(); - let client_predictions = STATIC_CLIENT_PREDICTIONS.init(PubSubChannel::new()); + let client_predictions = STATIC_CLIENT_PREDICTIONS.take(); spawner.must_spawn(client_prediction_task(predictions, client_predictions.publisher().unwrap())); // The host task must be started and ticking beore we can start advertising, so we use a join() here instead of a separate task