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,32 +29,38 @@ fn main() -> ! {
let mut buf = [0u8; 1]; let mut buf = [0u8; 1];
let mut send_allowed: bool = true; let mut send_allowed: bool = true;
let mut rec_allowed: bool = true; let mut rec_allowed: bool = true;
let data = b"filip\r\n";
let start_time = embassy_time::Instant::now();
loop { loop {
if usart.blocking_read(&mut buf).is_ok() { rec_allowed = (start_time.elapsed().as_secs() / 2) % 2 == 0;
let byte = buf[0]; if rec_allowed == true {
match byte { if usart.blocking_read(&mut buf).is_ok() {
0x11 => { let byte = buf[0];
send_allowed = true; match byte {
info!("Vysielanie povolené"); 0x11 => {
} send_allowed = true;
0x13 => { info!("Vysielanie povolené");
send_allowed = false; }
info!("Vysielanie zakázané"); 0x13 => {
} send_allowed = false;
_ => { info!("Vysielanie zakázané");
}
_ => {
}
}
}
if send_allowed {
if let Ok(stored_byte) = receiver.try_receive() {
unwrap!(usart.blocking_write(&[stored_byte]));
} else {
unwrap!(usart.blocking_write(data));
}
} else {
for b in data {
let _ = sender.try_send(*b);
} }
} }
}
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"));
} else {
// let _ = sender.try_send(byte);
} }
let _ = Timer::after(Duration::from_millis(100)); let _ = Timer::after(Duration::from_millis(100));
} }