blocking to async now
This commit is contained in:
@@ -29,32 +29,38 @@ 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 {
|
||||
if usart.blocking_read(&mut buf).is_ok() {
|
||||
let byte = buf[0];
|
||||
match byte {
|
||||
0x11 => {
|
||||
send_allowed = true;
|
||||
info!("Vysielanie povolené");
|
||||
}
|
||||
0x13 => {
|
||||
send_allowed = false;
|
||||
info!("Vysielanie zakázané");
|
||||
}
|
||||
_ => {
|
||||
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 {
|
||||
0x11 => {
|
||||
send_allowed = true;
|
||||
info!("Vysielanie povolené");
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user