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
impl Controller
Sourcepub fn new(c_struct: ws2811_t) -> Self
pub fn new(c_struct: ws2811_t) -> Self
Creates a new Controller
Note: This is only to be called from the Builder struct
Sourcepub fn render(&mut self) -> Result<()>
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?
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}
Sourcepub fn channels(&self) -> Vec<usize>
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.
Sourcepub fn brightness(&self, channel: usize) -> u8
pub fn brightness(&self, channel: usize) -> u8
Gets the brightness of the LEDs
Sourcepub fn set_brightness(&mut self, channel: usize, value: u8)
pub fn set_brightness(&mut self, channel: usize, value: u8)
Sets the brighness of the LEDs
Sourcepub fn leds(&self, channel: usize) -> &[RawColor] ⓘ
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.
Sourcepub fn leds_mut(&mut self, channel: usize) -> &mut [RawColor] ⓘ
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?
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
impl Clone for Controller
Source§fn clone(&self) -> Controller
fn clone(&self) -> Controller
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more