OneWireAsync

Trait OneWireAsync 

Source
pub trait OneWireAsync {
    type Status: OneWireStatus;
    type BusError;

    // Required methods
    async fn reset(&mut self) -> OneWireResult<Self::Status, Self::BusError>;
    async fn write_byte(
        &mut self,
        byte: u8,
    ) -> OneWireResult<(), Self::BusError>;
    async fn read_byte(&mut self) -> OneWireResult<u8, Self::BusError>;
    async fn write_bit(
        &mut self,
        bit: bool,
    ) -> OneWireResult<(), Self::BusError>;
    async fn read_bit(&mut self) -> OneWireResult<bool, Self::BusError>;
    fn get_overdrive_mode(&mut self) -> bool;
    async fn set_overdrive_mode(
        &mut self,
        enable: bool,
    ) -> OneWireResult<(), Self::BusError>;

    // Provided method
    async fn address(
        &mut self,
        rom: Option<u64>,
    ) -> OneWireResult<(), Self::BusError> { ... }
}
Expand description

Trait for 1-Wire communication. This trait defines the basic operations required for 1-Wire communication, such as resetting the bus, writing and reading bytes, and writing and reading bits.

Required Associated Types§

Source

type Status: OneWireStatus

The status type returned by the reset operation. This type must implement the OneWireStatus trait.

Source

type BusError

The error type returned by the operations of this trait. This type is used to indicate errors in the underlying hardware or communication.

Required Methods§

Source

async fn reset(&mut self) -> OneWireResult<Self::Status, Self::BusError>

Resets the 1-Wire bus and returns the status of the bus.

§Returns

A result containing the status of the bus after the reset operation.

§Errors

This method returns an error if the reset operation fails.

Source

async fn write_byte(&mut self, byte: u8) -> OneWireResult<(), Self::BusError>

Writes a byte to the device addressed using OneWireAsync::address on the 1-Wire bus. Multiple bytes can be written in succession after addressing the device.

§Arguments
  • byte - The byte to write to the bus.
§Errors

This method returns an error if the write operation fails.

Source

async fn read_byte(&mut self) -> OneWireResult<u8, Self::BusError>

Reads a byte from the device addressed using OneWireAsync::address on the 1-Wire bus. Multiple bytes can be read in succession after addressing the device.

§Note

If there are more than one devices on the bus and OneWireAsync::address was not called with a specific ROM address, the read operation will return garbage data.

§Returns

Byte read from the bus.

§Errors

This method returns an error if the read operation fails.

Source

async fn write_bit(&mut self, bit: bool) -> OneWireResult<(), Self::BusError>

Write a single bit to the device addressed using OneWireAsync::address on the 1-Wire bus. Multiple bits can be written in succession after addressing the device.

§Arguments
  • bit - The byte to write.
§Errors

This method returns an error if the read operation fails.

Source

async fn read_bit(&mut self) -> OneWireResult<bool, Self::BusError>

Reads a single bit from the device addressed using OneWireAsync::address on the 1-Wire bus. Multiple bits can be read in succession after addressing the device.

§Note

If there are more than one devices on the bus and OneWireAsync::address was not called with a specific ROM address, the read operation will return garbage data.

§Returns

The bit read from the bus.

§Errors

This method returns an error if the read operation fails.

Source

fn get_overdrive_mode(&mut self) -> bool

Check if the 1-Wire bus is in overdrive mode.

§Returns

A result containing a boolean indicating whether the bus is in overdrive mode.

Source

async fn set_overdrive_mode( &mut self, enable: bool, ) -> OneWireResult<(), Self::BusError>

Set the 1-Wire bus to overdrive mode.

§Arguments
  • enable - A boolean indicating whether to enable or disable overdrive mode.
§Returns

A result indicating the success or failure of the operation.

Provided Methods§

Source

async fn address( &mut self, rom: Option<u64>, ) -> OneWireResult<(), Self::BusError>

Addresses devices on the 1-Wire bus. The first OneWireAsync::read_byte, OneWireAsync::read_bit, OneWireAsync::write_byte, OneWireAsync::write_bit operation should be preceded by this method to address devices on the bus. Note: A OneWireAsync::read_byte or OneWireAsync::read_bit call will return garbage data if this method is called without specifying a ROM address on a bus with multiple devices.

§Arguments
  • rom - The ROM address of the device to address. Pass None to skip ROM addressing and address all devices on the bus.
§Returns

A result indicating the success or failure of the operation. If the device is successfully addressed, the method returns Ok(()).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§