Browse Source

protocol optimizations

master
Michael Preisach 7 years ago
parent
commit
20482350c7
  1. 7
      src/encoder.rs
  2. 15
      src/main.rs

7
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
}
}

15
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();

Loading…
Cancel
Save