46 lines
938 B
Rust
46 lines
938 B
Rust
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> where
|
|
USART: UsartOps<H, 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;
|
|
}
|
|
}
|