reformat
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
mod shtp;
|
||||
|
||||
use crate::data::reader::{DataBufferReader, DataReader};
|
||||
use crate::data::writer::{DataBufferWriter, DataWriter};
|
||||
use crate::hardware::error::{NotAvailableError, SpiError};
|
||||
use crate::hardware::imu::{Imu, ImuMeasurement};
|
||||
use anyhow::{anyhow, bail, ensure, Result};
|
||||
@@ -8,7 +9,6 @@ use chrono::TimeDelta;
|
||||
use embedded_hal::spi::SpiDevice;
|
||||
use log::info;
|
||||
use num_traits::ToPrimitive;
|
||||
use crate::data::writer::{DataBufferWriter, DataWriter};
|
||||
|
||||
const RX_BUFFER_LENGTH: usize = 1024;
|
||||
|
||||
@@ -30,15 +30,15 @@ pub struct Bno085<SPI> {
|
||||
|
||||
impl<SPI> Bno085<SPI>
|
||||
where
|
||||
SPI : SpiDevice<u8>,
|
||||
SPI::Error : Send,
|
||||
SPI::Error : Sync,
|
||||
SPI::Error : 'static,
|
||||
SPI: SpiDevice<u8>,
|
||||
SPI::Error: Send,
|
||||
SPI::Error: Sync,
|
||||
SPI::Error: 'static,
|
||||
{
|
||||
pub fn new(spi: SPI) -> Self {
|
||||
Self {
|
||||
spi,
|
||||
sequence_number: 0u8
|
||||
sequence_number: 0u8,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ where
|
||||
|
||||
let mut tx = DataBufferWriter::<128>::new();
|
||||
self.produce_sensor_enable(&tx)?;
|
||||
self.spi.write( tx.get_buffer()).map_err(SpiError)?;
|
||||
self.spi.write(tx.get_buffer()).map_err(SpiError)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -131,7 +131,7 @@ where
|
||||
|
||||
fn produce_sensor_enable(
|
||||
&mut self,
|
||||
tx: &impl DataWriter
|
||||
tx: &impl DataWriter,
|
||||
) -> Result<()> {
|
||||
let starting_position = tx.get_position();
|
||||
let length = tx.defer::<u16>()?;
|
||||
@@ -146,7 +146,7 @@ where
|
||||
0,
|
||||
TimeDelta::seconds(1) / 100, // 100Hz
|
||||
TimeDelta::zero(),
|
||||
0
|
||||
0,
|
||||
)?;
|
||||
self.produce_set_feature(
|
||||
tx,
|
||||
@@ -155,7 +155,7 @@ where
|
||||
0,
|
||||
TimeDelta::seconds(1) / 100, // 100Hz
|
||||
TimeDelta::zero(),
|
||||
0
|
||||
0,
|
||||
)?;
|
||||
self.produce_set_feature(
|
||||
tx,
|
||||
@@ -164,7 +164,7 @@ where
|
||||
0,
|
||||
TimeDelta::seconds(1) / 100, // 100Hz
|
||||
TimeDelta::zero(),
|
||||
0
|
||||
0,
|
||||
)?;
|
||||
|
||||
length.set_le((tx.get_position() - starting_position) as u16); // Fill in the length as we finish
|
||||
@@ -179,7 +179,7 @@ where
|
||||
change_sensitivity: u16,
|
||||
report_interval: TimeDelta,
|
||||
batch_interval: TimeDelta,
|
||||
configuration_word: u32
|
||||
configuration_word: u32,
|
||||
) -> Result<()> {
|
||||
tx.push_le(SET_FEATURE_REPORT_ID)?;
|
||||
tx.push_le(feature_report_id)?;
|
||||
@@ -198,7 +198,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<SPI : SpiDevice> Imu for Bno085<SPI> {
|
||||
impl<SPI: SpiDevice> Imu for Bno085<SPI> {
|
||||
fn step(&mut self) -> Result<ImuMeasurement> {
|
||||
todo!("asd")
|
||||
}
|
||||
@@ -206,7 +206,6 @@ impl<SPI : SpiDevice> Imu for Bno085<SPI> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::test_utils::SilentDrop;
|
||||
use embedded_hal_mock::eh1::spi::Mock as SpiMock;
|
||||
use embedded_hal_mock::eh1::spi::Transaction as SpiTransaction;
|
||||
@@ -258,7 +257,6 @@ mod tests {
|
||||
bno.spi.done();
|
||||
|
||||
Ok(())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
use crate::data::reader::DataReader;
|
||||
use crate::hardware::error::NotAvailableError;
|
||||
use anyhow::Result;
|
||||
|
||||
pub struct Header {
|
||||
pub length: u16,
|
||||
pub channel: u8,
|
||||
pub sequence_number: u8
|
||||
pub sequence_number: u8,
|
||||
}
|
||||
|
||||
impl Header {
|
||||
pub const SIZE: usize = size_of::<u16>() + size_of::<u8>() + size_of::<u8>();
|
||||
|
||||
|
||||
pub fn parse(bytes: &mut impl DataReader) -> Result<Self> {
|
||||
let length = bytes.read_le::<u16>().ok_or(NotAvailableError)?;
|
||||
let channel = bytes.read_le::<u8>().ok_or(NotAvailableError)?;
|
||||
let sequence_number = bytes.read_le::<u8>().ok_or(NotAvailableError)?;
|
||||
|
||||
|
||||
Ok(Self {
|
||||
length,
|
||||
channel,
|
||||
|
||||
@@ -10,7 +10,7 @@ impl<ERR: Debug + embedded_hal::i2c::Error> Display for I2cError<ERR> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<ERR: Debug + embedded_hal::i2c::Error> Error for I2cError<ERR> { }
|
||||
impl<ERR: Debug + embedded_hal::i2c::Error> Error for I2cError<ERR> {}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct SpiError<ERR: Debug + embedded_hal::spi::Error>(pub ERR);
|
||||
@@ -21,7 +21,7 @@ impl<ERR: Debug + embedded_hal::spi::Error> Display for SpiError<ERR> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<ERR: Debug + embedded_hal::spi::Error> Error for SpiError<ERR> { }
|
||||
impl<ERR: Debug + embedded_hal::spi::Error> Error for SpiError<ERR> {}
|
||||
|
||||
// #[derive(Copy, Clone, Debug)]
|
||||
// pub struct NotAvailableError;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use nalgebra::Vector3;
|
||||
use anyhow::Result;
|
||||
|
||||
pub struct ImuMeasurement {
|
||||
pub acceleration: Vector3<f64>,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::time::Instant;
|
||||
use crate::hardware::error::I2cError;
|
||||
use anyhow::{bail, Result};
|
||||
use embedded_hal::i2c::I2c;
|
||||
use log::{info, trace};
|
||||
use crate::hardware::error::I2cError;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::time::Instant;
|
||||
|
||||
pub trait Mcp23017 {
|
||||
fn init(&mut self) -> Result<()>;
|
||||
@@ -27,9 +27,9 @@ impl<I2C> Debug for Mcp23017Driver<I2C> {
|
||||
impl<I2C> Mcp23017Driver<I2C>
|
||||
where
|
||||
I2C: I2c,
|
||||
I2C::Error : Send,
|
||||
I2C::Error : Sync,
|
||||
I2C::Error : 'static
|
||||
I2C::Error: Send,
|
||||
I2C::Error: Sync,
|
||||
I2C::Error: 'static,
|
||||
{
|
||||
pub fn new(i2c: I2C, address: u8) -> Self {
|
||||
trace!("Mcp23017Driver::new(i2c, address: {address:07b})");
|
||||
@@ -46,9 +46,9 @@ where
|
||||
impl<I2C> Mcp23017 for Mcp23017Driver<I2C>
|
||||
where
|
||||
I2C: I2c,
|
||||
I2C::Error : Send,
|
||||
I2C::Error : Sync,
|
||||
I2C::Error : 'static
|
||||
I2C::Error: Send,
|
||||
I2C::Error: Sync,
|
||||
I2C::Error: 'static,
|
||||
{
|
||||
fn init(&mut self) -> Result<()> {
|
||||
trace!("Mcp23017Driver::init(self: {self:?})");
|
||||
@@ -64,10 +64,10 @@ where
|
||||
let (pin_bank, dirty_flag, pin_index) = match pin {
|
||||
0..8 => {
|
||||
(&mut self.bank[0], &mut self.dirty, pin as u32)
|
||||
},
|
||||
8 ..16 => {
|
||||
}
|
||||
8..16 => {
|
||||
(&mut self.bank[1], &mut self.dirty, (pin as u32) - 8)
|
||||
},
|
||||
}
|
||||
_ => bail!("Invalid Pin ID"),
|
||||
};
|
||||
let pin_mask = 1u8.unbounded_shl(pin_index);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use crate::hardware::error::SpiError;
|
||||
use anyhow::{ensure, Result};
|
||||
use embedded_hal::spi::SpiDevice;
|
||||
use log::trace;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
pub struct Mcp3208<SPI> {
|
||||
spi: SPI,
|
||||
vref: f64
|
||||
vref: f64,
|
||||
}
|
||||
|
||||
impl<SPI> Debug for Mcp3208<SPI> {
|
||||
@@ -17,16 +17,16 @@ impl<SPI> Debug for Mcp3208<SPI> {
|
||||
|
||||
impl<SPI> Mcp3208<SPI>
|
||||
where
|
||||
SPI : SpiDevice<u8>,
|
||||
SPI::Error : Send,
|
||||
SPI::Error : Sync,
|
||||
SPI::Error : 'static,
|
||||
SPI: SpiDevice<u8>,
|
||||
SPI::Error: Send,
|
||||
SPI::Error: Sync,
|
||||
SPI::Error: 'static,
|
||||
{
|
||||
pub fn new(spi: SPI, vref: f64) -> Self {
|
||||
trace!("Mcp3208::new(spi, vref: {vref})");
|
||||
Self {
|
||||
spi,
|
||||
vref
|
||||
vref,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ use crate::hardware::mcp23017::Mcp23017;
|
||||
use anyhow::Result;
|
||||
|
||||
pub trait Hardware {
|
||||
|
||||
fn get_mcp23017_a(&self) -> impl Mcp23017;
|
||||
fn get_mcp23017_b(&self) -> impl Mcp23017;
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Mutex;
|
||||
use crate::hardware::mcp23017::{Mcp23017, Mcp23017Driver};
|
||||
use crate::hardware::mcp3208::Mcp3208;
|
||||
use crate::hardware::Hardware;
|
||||
use anyhow::Result;
|
||||
use embedded_hal_bus::i2c::MutexDevice;
|
||||
use log::{debug, info, trace};
|
||||
// use rpi_pal::gpio::Gpio;
|
||||
use rpi_pal::i2c::I2c;
|
||||
use rpi_pal::spi::{Bus, Mode, SlaveSelect, Spi};
|
||||
use crate::hardware::mcp23017::{Mcp23017, Mcp23017Driver};
|
||||
use crate::hardware::mcp3208::Mcp3208;
|
||||
use rpi_pal::spi::SimpleHalSpiDevice;
|
||||
use rpi_pal::spi::{Bus, Mode, SlaveSelect, Spi};
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Mutex;
|
||||
|
||||
const CLOCK_1MHZ: u32 = 1_000_000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user