Blinq

Struct Blinq 

Source
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,

Source

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

Source

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

Source

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

Source

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

Source

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.

Source

pub fn idle(&self) -> bool

Is the queue empty?

Source

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.

Auto Trait Implementations§

§

impl<G, const N: usize> !Freeze for Blinq<G, N>

§

impl<G, const N: usize> !RefUnwindSafe for Blinq<G, N>

§

impl<G, const N: usize> Send for Blinq<G, N>
where G: Send,

§

impl<G, const N: usize> !Sync for Blinq<G, N>

§

impl<G, const N: usize> Unpin for Blinq<G, N>
where G: Unpin,

§

impl<G, const N: usize> UnwindSafe for Blinq<G, N>
where G: UnwindSafe,

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.