Add Webee stuff

This commit is contained in:
2023-08-24 01:53:41 +02:00
parent 86994e0f8c
commit 3c5a7215d1
7 changed files with 215 additions and 15 deletions

44
src/webee.rs Normal file
View File

@@ -0,0 +1,44 @@
use arduino_hal::Usart;
use arduino_hal::usart::UsartOps;
use arduino_hal::prelude::*;
use embedded_hal::serial::{Read};
mod vector;
pub use vector::Vector;
pub struct Webee<USART, RX, TX> {
webee: Usart<USART, RX, TX>,
}
enum SEND_CMD {
}
impl<USART, RX, TX> Webee<USART, RX, TX> {
const STOP : u8 = 0xFF;
pub fn new(device: USART, rx: RX, tx: TX) -> Self {
Self {
webee: Usart::new(device, rx, tx, 38400.into_baudrate())
}
}
pub fn send(&mut self, data: Vector<u8>) -> Vector<u8> {
for byte in data {
self.webee.write_byte(byte);
}
return self.recv();
}
fn recv(&mut self) -> Vector<u8> {
const buffer : Vector<u8> = Vector::new(0, &[]);
let byte : u8 = self.webee.read_byte();
while byte != self.STOP {
buffer.push(byte);
}
return buffer;
}
}