From 20482350c751924bfed8bc3edcb8cebb613eba0f Mon Sep 17 00:00:00 2001 From: Michael Preisach Date: Tue, 30 Apr 2019 23:59:57 +0200 Subject: [PATCH] protocol optimizations --- src/encoder.rs | 7 ++++--- src/main.rs | 15 +-------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/encoder.rs b/src/encoder.rs index 74c1ced..00f04db 100644 --- a/src/encoder.rs +++ b/src/encoder.rs @@ -90,17 +90,18 @@ impl Encodestate { for i in 0 .. 8 { if self.current.get_segment(i) != self.next.get_segment(i) { let mut text = String::new(); - text.push_str("setsegment "); + text.push_str("set "); text.push(std::char::from_u32(('0' as u32) + i as u32).unwrap()); text.push(' '); text.push_str(match self.next.get_segment(i) { - true => "on", - false => "off", + true => "0", + false => "1", }); self.current.set_segment(i, self.next.get_segment(i)); instructions.push(text); } } + instructions.push(String::from("show")); instructions } } diff --git a/src/main.rs b/src/main.rs index a5a890f..4306097 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ fn main() { let mut outstream = stream.try_clone().unwrap(); let mut reader = BufReader::new(stream); let mut instructions; - let input = String::from("0123456789aBcDeFhijlnOpTuY"); + let input = String::from("0123456789aBcDeFhijlnOpTuY "); let mut state = Encodestate::new(); @@ -40,19 +40,6 @@ fn main() { return; } } - let mut response = String::new(); - let inst = String::from("display"); - if DEBUG { - print!("{} ",inst); - } - writeln!(outstream, "{}", inst).expect("write failed"); - reader.read_line(&mut response).expect("Reading line failed"); - if DEBUG { - println!("{}", response); - } - if !response.trim_end().contains("OK") { - return; - } //thread::sleep(Duration::from_millis(500)); } let mut response = String::new();