diff --git a/src/movement.rs b/src/movement.rs index c27de03..bdb5e31 100644 --- a/src/movement.rs +++ b/src/movement.rs @@ -1,7 +1,7 @@ use embassy_stm32::adc::Adc; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::peripherals; -use embassy_time::{Delay, Duration, Timer}; +use embassy_time::{Delay, Duration, Timer, with_timeout}; use embassy_util::blocking_mutex::raw::ThreadModeRawMutex; use embassy_util::channel::mpmc::{Receiver, Sender}; use embassy_util::{select, Either}; @@ -110,9 +110,10 @@ pub async fn movement_task( down_pin.set_low(); } + // Send with timeouts to prevent blocking if display or usb task are blocked. join( - pos_sender.send(rotor_state.actual_pos), - state_sender.send(rotor_state), + with_timeout(Duration::from_millis(100), pos_sender.send(rotor_state.actual_pos)), + with_timeout(Duration::from_millis(100), state_sender.send(rotor_state)), ) .await; }