commit 96b387bd68ae3ecaf3daf6cf01696371d38018ea
parent 31c9b93f9cadc40d1f9154abd366ef7e0a30fff4
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 16 Nov 2025 15:27:14 +0000
use async uart so that reading doesn't block ble
Diffstat:
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/src/bin/main.rs b/src/bin/main.rs
@@ -92,7 +92,8 @@ async fn run_ecu(periph_uart : esp_hal::peripherals::UART0<'_>,
)
.expect("now I got a reason")
.with_rx(rx_peripheral)
- .with_tx(tx_peripheral.reborrow());
+ .with_tx(tx_peripheral.reborrow())
+ .into_async();
uart.write(b"\xfe\x04\xff\xff").expect("write failed");
let _ = uart.flush();
@@ -100,23 +101,18 @@ async fn run_ecu(periph_uart : esp_hal::peripherals::UART0<'_>,
uart.write(b"\x72\x05\x00\xF0\x99").expect("write 2 failed");
let _ = uart.flush();
- // loop {
- // info!("waiting");
- // let mut buf = [0u8; 80];
- // let bytes = uart.read(&mut buf[..]).expect("read failed");
- // // if bytes>0 { led.toggle(); }
-
- // info!("got {}", bytes);
- // Timer::after_secs(1).await;
- // }
+ loop {
+ info!("waiting");
+ delay.delay_millis(60*1000);
+ let mut buf = [0u8; 80];
+ let bytes = uart.read_async(&mut buf[..]).await.expect("read failed");
+ // if bytes>0 { led.toggle(); }
+
+ info!("got {}", bytes);
+ Timer::after_secs(1).await;
+ }
}
-async fn setup_ble(peripheral : esp_hal::peripherals::BT<'_>) {
- let radio_init = esp_radio::init().expect("Failed to initialize Wi-Fi/BLE controller");
- let connector = BleConnector::new(&radio_init, peripheral, Default::default()).expect("connector");
- let controller: ExternalController<_, 20> = ExternalController::new(connector);
- run_ble_stack(controller).await;
-}
/// Max number of connections
const CONNECTIONS_MAX: usize = 1;