Browse Source

protocol optimizations

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

7
src/encoder.rs

@ -90,17 +90,18 @@ impl Encodestate {
for i in 0 .. 8 { for i in 0 .. 8 {
if self.current.get_segment(i) != self.next.get_segment(i) { if self.current.get_segment(i) != self.next.get_segment(i) {
let mut text = String::new(); 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(std::char::from_u32(('0' as u32) + i as u32).unwrap());
text.push(' '); text.push(' ');
text.push_str(match self.next.get_segment(i) { text.push_str(match self.next.get_segment(i) {
true => "on", true => "0",
false => "off", false => "1",
}); });
self.current.set_segment(i, self.next.get_segment(i)); self.current.set_segment(i, self.next.get_segment(i));
instructions.push(text); instructions.push(text);
} }
} }
instructions.push(String::from("show"));
instructions instructions
} }
} }

13
src/main.rs

@ -40,19 +40,6 @@ fn main() {
return; 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)); //thread::sleep(Duration::from_millis(500));
} }
let mut response = String::new(); let mut response = String::new();

Loading…
Cancel
Save