From d4c9fa65be94f1420b3e14941d0c62f5705b3d86 Mon Sep 17 00:00:00 2001 From: Aode Date: Sun, 13 Jun 2021 17:05:06 -0500 Subject: [PATCH] Send device reset command --- src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index d0e3a9c..33ca886 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,18 +17,31 @@ fn main() -> Result<(), Box> { if let Ok(repo) = get_prop(&mut port, b"repo") { println!("repo success: {}", String::from_utf8_lossy(&repo)); } + + if send_cmd(&mut port, b"reset").is_ok() { + println!("Device reset"); + continue; + } } } Ok(()) } +fn send_cmd( + port: &mut Box, + cmd: &[u8], +) -> Result<(), Box> { + port.write_all(cmd)?; + port.flush()?; + Ok(()) +} + fn get_prop( port: &mut Box, prop: &[u8], ) -> Result, Box> { - port.write_all(prop)?; - port.flush()?; + send_cmd(port, prop)?; let mut len_buf = [0u8; 1]; port.read_exact(&mut len_buf)?;