Struct Controller

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

The main struct used to control lights. Provides ways of accessing the light color values and rendering those values to the string.

Implementations§

Source§

impl Controller

Source

pub fn new(c_struct: ws2811_t) -> Self

Creates a new Controller

Note: This is only to be called from the Builder struct

Source

pub fn render(&mut self) -> Result<()>

Render the colors to the string.

It doesn’t automatically do this because it is a somewhat costly operation that should be batched.

Examples found in repository?
examples/basic.rs (line 30)
5fn main() {
6    // Construct a single channel controller. Note that the
7    // Controller is initialized by default and is cleaned up on drop
8
9    let mut controller = ControllerBuilder::new()
10        .freq(800_000)
11        .dma(10)
12        .channel(
13            0, // Channel Index
14            ChannelBuilder::new()
15                .pin(10) // GPIO 10 = SPI0 MOSI
16                .count(64) // Number of LEDs
17                .strip_type(StripType::Ws2812)
18                .brightness(20) // default: 255
19                .build(),
20        )
21        .build()
22        .unwrap();
23
24    let leds = controller.leds_mut(0);
25
26    for led in leds {
27        *led = [0, 0, 255, 0];
28    }
29
30    controller.render().unwrap();
31}
Source

pub fn wait(&mut self) -> Result<()>

Wait for a render to be completed.

Source

pub fn channels(&self) -> Vec<usize>

Gets the channels with non-zero number of LED’s associated with them.

I know this is somewhat non-intuitive, but naming it something like active_channels(&self) seemed overly verbose.

Source

pub fn brightness(&self, channel: usize) -> u8

Gets the brightness of the LEDs

Source

pub fn set_brightness(&mut self, channel: usize, value: u8)

Sets the brighness of the LEDs

Source

pub fn leds(&self, channel: usize) -> &[RawColor]

Gets a slice view to the color array to be written to the LEDs. See leds_mut for a mutable slice view to this data.

§Safety

This function is moderately unsafe because we rely on the promise from the C library that it will stick to its memory layout and that the pointer is valid.

Source

pub fn leds_mut(&mut self, channel: usize) -> &mut [RawColor]

Gets a mutable slice pointing to the color array to be written to the LEDs.

§Safety

This function is moderately unsafe because we rely on the promise from the C library that it will stick to its memory layout and that the pointer is valid.

Examples found in repository?
examples/basic.rs (line 24)
5fn main() {
6    // Construct a single channel controller. Note that the
7    // Controller is initialized by default and is cleaned up on drop
8
9    let mut controller = ControllerBuilder::new()
10        .freq(800_000)
11        .dma(10)
12        .channel(
13            0, // Channel Index
14            ChannelBuilder::new()
15                .pin(10) // GPIO 10 = SPI0 MOSI
16                .count(64) // Number of LEDs
17                .strip_type(StripType::Ws2812)
18                .brightness(20) // default: 255
19                .build(),
20        )
21        .build()
22        .unwrap();
23
24    let leds = controller.leds_mut(0);
25
26    for led in leds {
27        *led = [0, 0, 255, 0];
28    }
29
30    controller.render().unwrap();
31}

Trait Implementations§

Source§

impl Clone for Controller

Source§

fn clone(&self) -> Controller

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Controller

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Controller

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.