The monitor now correctly outputs stuff to the screen

This commit is contained in:
2025-09-19 15:15:40 +02:00
parent 1dbbaab197
commit 80dd1c1a70

View File

@@ -1,4 +1,4 @@
use std::io::Error;
use std::io::{Error, ErrorKind, Write};
use std::time::Duration;
use serial2::SerialPort;
@@ -46,13 +46,31 @@ impl Monitor {
println!();
let mut _stdout = std::io::stdout().into_raw_mode().unwrap();
let mut stdout = std::io::stdout().into_raw_mode().unwrap();
let mut stdin = termion::async_stdin().keys();
'main: loop {
let mut buf = [0u8; 1];
let res = port.read_exact(&mut buf);
if res.is_ok() {
if buf[0] == b'\n' {
stdout.write_all(b"\r")?;
}
stdout.write_all(&buf)?;
stdout.flush()?;
}
if let Err(err) = res && err.kind() != ErrorKind::TimedOut {
Err(err)?
}
if let Some(Ok(key)) = stdin.next() {
if let Key::Ctrl('r') = key {
stdout.write_all(b"\r\n*** Reboot ***\r\n")?;
port.set_dtr(true)?;
port.set_rts(true)?;
std::thread::sleep(Duration::from_millis(10));