additional bugfixing
This commit is contained in:
parent
46ff7c865e
commit
36ab15255f
3 changed files with 64 additions and 16 deletions
|
|
@ -2,6 +2,7 @@ use esp_hal::uart::RxError;
|
|||
#[no_std]
|
||||
use esp_hal::uart::{Uart};
|
||||
use esp_hal::{Blocking };
|
||||
use rtt_target::rprintln;
|
||||
|
||||
use crate::peripherals::{ErrCommand,Command};
|
||||
|
||||
|
|
@ -70,6 +71,7 @@ impl<'a> Nextion<'a> {
|
|||
UartStatemachine::Terminator(n) => {
|
||||
if byte == b'\xff' {
|
||||
if n >= 2 {
|
||||
rprintln!("SENDING {:?}",buf);
|
||||
let idx = self.idx;
|
||||
self.reset();
|
||||
return Ok(idx);
|
||||
|
|
@ -100,20 +102,31 @@ impl<'a> Nextion<'a> {
|
|||
}
|
||||
pub fn read_command(&mut self) -> Result<Command,ErrCommand>{
|
||||
let mut buf:[u8;8] = [0;8];
|
||||
let read_bytes = self.read_frame(&mut buf).unwrap_or(return Err(ErrCommand::READ_ERROR));
|
||||
let _read_bytes = match self.read_frame(&mut buf){
|
||||
Ok(x) => x,
|
||||
Err(e) => {rprintln!("ERROR while reading");
|
||||
return Err(ErrCommand::NoValidCmd);
|
||||
}
|
||||
};
|
||||
|
||||
rprintln!("READ SUCCESS!:{:?}",buf);
|
||||
match buf[0]{
|
||||
|
||||
01 => {Ok(Command::Start)},
|
||||
02 =>{Ok(Command::Stop)},
|
||||
03 => {
|
||||
let rpm = u32::from_be_bytes(buf[1..4].try_into().expect("failed to parse rpm!"));
|
||||
let rpm = u32::from_le_bytes(buf[1..5].try_into().expect("failed to parse rpm!"));
|
||||
Ok(Command::SetRpm(rpm))
|
||||
},
|
||||
04 => {
|
||||
let time = u32::from_be_bytes(buf[1..4].try_into().expect("failed to parse time!"));
|
||||
let time = u32::from_le_bytes(buf[1..5].try_into().expect("failed to parse time!"));
|
||||
Ok(Command::SetTimer(time))
|
||||
}
|
||||
05 => {
|
||||
05 =>{
|
||||
Ok(Command::SendConfig)
|
||||
}
|
||||
00 => {
|
||||
Ok(Command::CommandSuccess)
|
||||
},
|
||||
_ => {
|
||||
Err(ErrCommand::NoValidCmd)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue