WS28xxSpiAdapter

Struct WS28xxSpiAdapter 

Source
pub struct WS28xxSpiAdapter { /* private fields */ }
Expand description

Adapter that connects your application via SPI to your WS28xx LEDs. This requires an SPI device on your machine. This doesn’t work with #[no-std].

Implementations§

Source§

impl WS28xxSpiAdapter

Source

pub fn new(dev: &str) -> Result<Self, String>

Connects your application with the SPI-device of your device. This uses the spidev-crate. Returns a new adapter object for the WS28xx LEDs.

  • dev - Device name. Probably “/dev/spidev0.0” if available.

Fails if connection to SPI can’t be established.

Trait Implementations§

Source§

impl WS28xxAdapter for WS28xxSpiAdapter

Source§

fn get_hw_dev(&mut self) -> &mut Box<dyn HardwareDev>

Returns a reference to the hardware device. This function only needs to be implemented once in the generic adapter.
Source§

fn write_rgb(&mut self, rgb_data: &[(u8, u8, u8)]) -> Result<(), String>

Encodes RGB values and write them via the hardware device to the LEDs. The length of the vector is the number of LEDs you want to write to. Note that if you have performance critical applications (like you need a signal on the LEDS on a given time) it’s a better idea to encode the data earlier by yourself using crate::encoding-module and calling WS28xxAdapter::write_encoded_rgb. Otherwise and if your device is slow the encoding could cost a few microseconds to milliseconds - depending on your amount of data and machine.
Source§

fn clear(&mut self, num_leds: usize)

Clears all LEDs. Sets each to (0, 0, 0).
Source§

fn write_encoded_rgb(&mut self, encoded_data: &[u8]) -> Result<(), String>

Directly writes encoded RGB values via hardware device to the LEDs. This method and the encoded data must fulfill the restrictions given by crate::timings and crate::encoding if the hardware device uses the specified frequency in crate::timings::PI_SPI_HZ.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.