bugfix, if 0xff 0xff !0xff is encountered, this is finest shitty framing
This commit is contained in:
parent
b130c8575b
commit
fbc187f001
1 changed files with 19 additions and 9 deletions
|
|
@ -12,7 +12,7 @@ enum UART_STATEMACHINE {
|
||||||
pub struct Nextion<'a> {
|
pub struct Nextion<'a> {
|
||||||
interface: &'a mut Uart<'static, Blocking>,
|
interface: &'a mut Uart<'static, Blocking>,
|
||||||
state: UART_STATEMACHINE,
|
state: UART_STATEMACHINE,
|
||||||
idx: usize
|
idx: usize,
|
||||||
}
|
}
|
||||||
impl<'a> Nextion<'a> {
|
impl<'a> Nextion<'a> {
|
||||||
pub fn new<'b>(uart: &'a mut Uart<'static, Blocking>) -> Self {
|
pub fn new<'b>(uart: &'a mut Uart<'static, Blocking>) -> Self {
|
||||||
|
|
@ -74,19 +74,29 @@ impl<'a> Nextion<'a> {
|
||||||
} else {
|
} else {
|
||||||
self.state = UART_STATEMACHINE::Terminator(n + 1)
|
self.state = UART_STATEMACHINE::Terminator(n + 1)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
self.state = UART_STATEMACHINE::Reading;
|
|
||||||
if self.idx < buf.len() {
|
|
||||||
buf[self.idx] = byte;
|
|
||||||
self.idx += 1;
|
|
||||||
} else {
|
} else {
|
||||||
|
self.state = UART_STATEMACHINE::Reading;
|
||||||
|
|
||||||
|
let needed: usize = (n + 1).into(); // number of bytes to reinsert (FFs + current byte)
|
||||||
|
|
||||||
|
if self.idx + needed > buf.len() {
|
||||||
self.reset();
|
self.reset();
|
||||||
return Err(RxError::FifoOverflowed);
|
return Err(RxError::FifoOverflowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _ in 0..n {
|
||||||
|
buf[self.idx] = 0xff;
|
||||||
|
self.idx += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[self.idx] = byte;
|
||||||
|
self.idx += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn read_ready(&mut self) -> bool {
|
pub fn read_ready(&mut self) -> bool {
|
||||||
self.interface.read_ready()
|
self.interface.read_ready()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue