diff --git a/src/tasks/wifi.rs b/src/tasks/wifi.rs index f580c01..dd7a114 100644 --- a/src/tasks/wifi.rs +++ b/src/tasks/wifi.rs @@ -1,5 +1,6 @@ use bleps::{ad_structure::{create_advertising_data, AdStructure, BR_EDR_NOT_SUPPORTED, LE_GENERAL_DISCOVERABLE}, attribute_server::{AttributeServer, NotificationData}, gatt, Ble, HciConnector}; use embassy_sync::channel::DynamicReceiver; +use embassy_sync::pubsub::DynSubscriber; use embassy_time::Timer; use esp_hal::timer::AnyTimer; use esp_wifi::ble::controller::BleConnector; @@ -7,7 +8,7 @@ use log::*; use crate::events::Notification; -pub async fn ble_task(notify: DynamicReceiver<'static, Notification>, wifi_init: &esp_wifi::EspWifiController<'_>, bluetooth_device: esp_hal::peripherals::BT<'static>) { +pub async fn ble_task(notify: DynSubscriber<'static, Notification>, wifi_init: &esp_wifi::EspWifiController<'_>, bluetooth_device: esp_hal::peripherals::BT<'static>) { info!("Setting up BLE stack"); let connector = BleConnector::new(wifi_init, bluetooth_device); let get_millis = || esp_hal::time::Instant::now().duration_since_epoch().as_millis(); @@ -64,32 +65,10 @@ pub async fn ble_task(notify: DynamicReceiver<'static, Notification>, wifi_init: info!("BLE running!"); // TODO: Somehow need to recreate the attributeserver after disconnecting? - loop { + /*loop { let notification = match notify.try_receive() { Err(_) => None, Ok(Notification::Beat) => Some("beat"), - //TODO: Should make Telemetry values serde-encodable - /*Ok(Telemetry::Measurement(Measurement::IMU { accel, gyro })) => { - let json_data = json!({ - "x": accel.x, - "y": accel.y, - "z": accel.z, - "gx": gyro.x, - "gy": gyro.y, - "gz": gyro.z - }); - let json_buf = serde_json::to_string(&json_data).unwrap(); - Some(json_buf) - }, - Ok(Telemetry::Measurement(Measurement::GPS(Some(measurement)))) => { - info!("gps telemetry"); - let json_data = json!({ - "lat": measurement.x, - "lng": measurement.y - }); - let json_buf = serde_json::to_string(&json_data).unwrap(); - Some(json_buf) - },*/ _ => None }; @@ -105,7 +84,7 @@ pub async fn ble_task(notify: DynamicReceiver<'static, Notification>, wifi_init: srv.do_work_with_notification(Some(NotificationData::new(tx_handle, &b"\n"[..]))).unwrap(); } } - } + }*/ } // TODO: Wifi task needs to know when there is data to upload, so it only connects when needed. @@ -115,7 +94,7 @@ pub async fn wireless_task(notify: DynamicReceiver<'static, Notification>, timer let wifi_init = esp_wifi::init(timer, rng).expect("Failed to initialize WIFI/BLE controller"); - ble_task(notify, &wifi_init, bluetooth_device).await; + //ble_task(notify, &wifi_init, bluetooth_device).await; /* loop {