`Serial.read()` is unbuffered, and will return `-1` (which we cast to an unsigned char, so 255) immediately if there is no data in the incoming buffer. This is unlike every other kind of read we do, which use `parseInt()`, and are thus buffered reads with a timeout. The problem with returning `-1` immediately is that Chrysalis sends data in chunks, so if we end up trying to read a char at a chunk boundary, we'll end up reading -1s, which we treat as valid data, and cast it to an unsigned char, completely throwing off the protocol in the process. By using `readBytes()`, we have a one second window during which more data can arrive, and as such, is consistent with the rest of our reads. Signed-off-by: Gergely Nagy <algernon@keyboard.io>pull/1236/head
parent
62a0fae04d
commit
a4b84057b0
Loading…
Reference in new issue