blocking to async now

This commit is contained in:
Filipriec
2026-02-24 15:29:59 +01:00
parent 1b4ddcaf6c
commit 88f2ec3ae9

View File

@@ -29,7 +29,12 @@ fn main() -> ! {
let mut buf = [0u8; 1];
let mut send_allowed: bool = true;
let mut rec_allowed: bool = true;
let data = b"filip\r\n";
let start_time = embassy_time::Instant::now();
loop {
rec_allowed = (start_time.elapsed().as_secs() / 2) % 2 == 0;
if rec_allowed == true {
if usart.blocking_read(&mut buf).is_ok() {
let byte = buf[0];
match byte {
@@ -45,16 +50,17 @@ fn main() -> ! {
}
}
}
while let Ok(stored_byte) = receiver.try_receive() {
unwrap!(usart.blocking_write(&[stored_byte]));
unwrap!(usart.blocking_write(b" (pipe)\r\n"));
}
if send_allowed {
unwrap!(usart.blocking_write(&buf));
unwrap!(usart.blocking_write(b"a\r\n"));
if let Ok(stored_byte) = receiver.try_receive() {
unwrap!(usart.blocking_write(&[stored_byte]));
} else {
// let _ = sender.try_send(byte);
unwrap!(usart.blocking_write(data));
}
} else {
for b in data {
let _ = sender.try_send(*b);
}
}
}
let _ = Timer::after(Duration::from_millis(100));
}