Struct hx711_spi::Hx711

source ·
pub struct Hx711<SPI> { /* private fields */ }
Expand description

Represents an instance of a HX711 device

Implementations§

source§

impl<SPI, E> Hx711<SPI>where SPI: Transfer<u8, Error = E> + Write<u8, Error = E>,

source

pub fn new(spi: SPI) -> Self

opens a connection to a HX711 on a specified SPI.

The datasheet specifies PD_SCK high time and PD_SCK low time to be in the 0.2 to 50 us range, therefore bus speed has to be between 5 MHz and 20 kHz. 1 MHz seems to be a good choice. D is an embedded_hal implementation of DelayMs.

source

pub fn read(&mut self) -> Result<i32, E>

reads a value from the HX711 and returns it

Errors

Returns SPI errors and nb::Error::WouldBlock if data isn’t ready to be read from hx711

source

pub fn retrieve(&mut self) -> Result<i32, E>

This is for compatibility only. Use read instead.

source

pub fn reset(&mut self) -> Result<(), E>

Reset the chip to it’s default state. Mode is set to convert channel A with a gain factor of 128.

Errors

Returns SPI errors

source

pub fn set_mode(&mut self, m: Mode) -> Result<Mode, E>

Set the mode to the value specified.

Errors

Returns SPI errors

source

pub fn mode(&mut self) -> Mode

Get the current mode.

source

pub fn get_mode(&mut self) -> Mode

This is for compatibility only. Use mode instead.

source

pub fn disable(&mut self) -> Result<(), E>

To power down the chip the PD_SCK line has to be held in a ‘high’ state. To do this we would need to write a constant stream of binary ‘1’ to the SPI bus which would totally defy the purpose. Therefore it’s not implemented.

source

pub fn enable(&mut self) -> Result<(), E>

Power up / down is not implemented (see disable)

Trait Implementations§

source§

impl<SPI: Debug> Debug for Hx711<SPI>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<SPI> RefUnwindSafe for Hx711<SPI>where SPI: RefUnwindSafe,

§

impl<SPI> Send for Hx711<SPI>where SPI: Send,

§

impl<SPI> Sync for Hx711<SPI>where SPI: Sync,

§

impl<SPI> Unpin for Hx711<SPI>where SPI: Unpin,

§

impl<SPI> UnwindSafe for Hx711<SPI>where SPI: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.