bugfix, if 0xff 0xff !0xff is encountered, this is finest shitty framing

This commit is contained in:
Robert Schauklies 2026-01-06 22:42:10 +01:00
parent b130c8575b
commit fbc187f001

View file

@ -12,14 +12,14 @@ 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 {
Nextion { Nextion {
interface: uart, interface: uart,
state: UART_STATEMACHINE::WaitingP, state: UART_STATEMACHINE::WaitingP,
idx:0, idx: 0,
} }
} }
pub fn send_command(&mut self, cmd: &[u8]) { pub fn send_command(&mut self, cmd: &[u8]) {
@ -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()
} }