pub struct Blinq<G, const N: usize>where
G: OutputPin,{ /* private fields */ }Expand description
A blinking queue
This takes an embedded-hal OutputPin, and drives it based on given patterns on each step.
§Example
use blinq::{Pattern, Blinq, patterns};
// Create a blink queue with room for 8 patterns, that is active-low
// Note that the queue size must be one larger than the amount of patterns
// that you wish to store!
let mut blinq: Blinq<FakeGpio, 9> = Blinq::new(gpio, true);
// Insert "HELLO." in morse code
blinq.enqueue(patterns::morse::H); // 8 steps
blinq.enqueue(patterns::morse::E); // 2 steps
blinq.enqueue(patterns::morse::L); // 10 steps
blinq.enqueue(patterns::morse::L); // 10 steps
blinq.enqueue(patterns::morse::O); // 12 steps
blinq.enqueue(patterns::morse::FULL_STOP); // 18 steps
// This is 60 steps
for _ in 0..60 {
blinq.step();
}
// The queue is now exhausted, and the GPIO will be driven to the
// inactive state
blinq.step();Implementations§
Source§impl<G, const N: usize> Blinq<G, N>where
G: OutputPin,
impl<G, const N: usize> Blinq<G, N>where
G: OutputPin,
Sourcepub fn new(gpio: G, active_low: bool) -> Self
pub fn new(gpio: G, active_low: bool) -> Self
Create a new Blinq with the given GPIO
The GPIO will be driven to the “inactive” state on creation
Sourcepub fn release(self) -> G
pub fn release(self) -> G
Consume the queue, returning the gpio
Note: The gpio will be in whatever the last state was, which may be active or inactive
Sourcepub fn enqueue(&mut self, pat: Pattern)
pub fn enqueue(&mut self, pat: Pattern)
Enqueue a new pattern into the queue
If the queue is currently full, the pattern will be discarded
Sourcepub fn try_enqueue(&mut self, pat: Pattern) -> Result<(), Pattern>
pub fn try_enqueue(&mut self, pat: Pattern) -> Result<(), Pattern>
Try to enqueue a new pattern into the queue
If the queue is currently full, an error will be returned
Sourcepub fn step(&mut self)
pub fn step(&mut self)
Move the queue one step
This will update the GPIO with the next state in the current pattern, or start the next pattern. If the queue is empty, the GPIO will be driven to the inactive state.
If any GPIO errors occur, they will be discarded, but the pattern will still step forward.
blinq has no concept of time, so you should call it at a rate
that makes sense for you. For example, if you wanted the pattern
0b101010 to be a 1hz blink, you should call step every 500ms.
If you want 0b11110000 to be a 1hz blink, you should call step
every 125ms.
Sourcepub fn try_step(&mut self) -> Result<(), G::Error>
pub fn try_step(&mut self) -> Result<(), G::Error>
Try to move the queue one step
This will update the GPIO with the next state in the current pattern, or start the next pattern. If the queue is empty, the GPIO will be driven to the inactive state.
If any GPIO errors occur, they will be returned, but the pattern will still step forward.
blinq has no concept of time, so you should call it at a rate
that makes sense for you. For example, if you wanted the pattern
0b101010 to be a 1hz blink, you should call step every 500ms.
If you want 0b11110000 to be a 1hz blink, you should call step
every 125ms.