headless?

This commit is contained in:
2023-10-14 12:45:48 +02:00
parent df53777a80
commit 8167fe55a0
5 changed files with 156 additions and 24 deletions

View File

@@ -4,13 +4,15 @@ use arduino_hal::port::mode::{Input, Output};
use arduino_hal::usart::{Usart, UsartOps};
use arduino_hal::prelude::*;
mod simple_vector;
pub use simple_vector::SimpleVec;
use heapless::Vec;
// mod simple_vector;
// pub use simple_vector::SimpleVec;
pub struct Webee<USART: UsartOps<Atmega, RX, TX>, RX, TX>
{
webee: Usart<USART, RX, TX>,
pub webee: Usart<USART, RX, TX>,
}
enum SendCmd {}
@@ -34,7 +36,7 @@ where
}
}
pub fn send(&mut self, data: &[u8]) -> SimpleVec {
pub fn send(&mut self, data: &[u8]) -> Vec<u8, 128> {
for byte in data {
self.webee.write_byte(*byte);
}
@@ -42,12 +44,31 @@ where
return self.recv();
}
fn recv(&mut self) -> SimpleVec {
let mut byte: u8 = self.webee.read_byte();
let mut buffer = SimpleVec::new();
pub fn send_void(&mut self, data: &[u8]) {
for byte in data {
self.webee.write_byte(*byte);
}
}
while byte != STOP {
buffer.push(byte);
pub fn recv(&mut self) -> Vec<u8, 128> {
let mut byte: u8 = self.webee.read_byte();
let mut buffer = Vec::new();
while byte != STOP && !buffer.is_full() {
buffer.push(byte).unwrap();
byte = self.webee.read_byte();
}
return buffer;
}
pub fn recv_debug(&mut self, callback: fn(u8)) -> Vec<u8, 128> {
let mut byte: u8 = self.webee.read_byte();
callback(byte);
let mut buffer = Vec::new();
while byte != STOP && !buffer.is_full() {
buffer.push(byte).unwrap();
byte = self.webee.read_byte();
}