[−][src]Struct blinq::Blinq
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, consts}; // Create a blink queue with room for 8 patterns, that is active-low let mut blinq: Blinq<consts::U8, FakeGpio> = 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
impl<N, G> Blinq<N, G> where
N: ArrayLength<Pattern>,
G: OutputPin,
[src]
N: ArrayLength<Pattern>,
G: OutputPin,
pub fn new(gpio: G, active_low: bool) -> Self
[src]
Create a new Blinq with the given GPIO
The GPIO will be driven to the "inactive" state on creation
pub fn release(self) -> G
[src]
Consume the queue, returning the gpio
Note: The gpio will be in whatever the last state was, which may be active or inactive
pub fn enqueue(&mut self, pat: Pattern)
[src]
Enqueue a new pattern into the queue
If the queue is currently full, the pattern will be discarded
pub fn try_enqueue(&mut self, pat: Pattern) -> Result<(), Pattern>
[src]
Try to enqueue a new pattern into the queue
If the queue is currently full, an error will be returned
pub fn step(&mut self)
[src]
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.
pub fn idle(&self) -> bool
[src]
Is the queue empty?
pub fn try_step(&mut self) -> Result<(), G::Error>
[src]
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.
Auto Trait Implementations
impl<N, G> Send for Blinq<N, G> where
G: Send,
G: Send,
impl<N, G> !Sync for Blinq<N, G>
impl<N, G> Unpin for Blinq<N, G> where
G: Unpin,
<N as ArrayLength<Pattern>>::ArrayType: Unpin,
G: Unpin,
<N as ArrayLength<Pattern>>::ArrayType: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,