FlipdotDisplay

Struct FlipdotDisplay 

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

A DrawTarget implementation to easily draw graphics to a Luminator sign.

Drawing results are buffered and only sent to the sign when flush is called.

§Examples

use embedded_graphics::{
    mono_font::{MonoTextStyle, ascii::FONT_5X7},
    pixelcolor::BinaryColor,
    prelude::*,
    primitives::{Circle, PrimitiveStyle, Triangle},
    text::{Baseline, Text},
};
use flipdot_graphics::{Address, FlipdotDisplay, SignBusType, SignType};

// Create a display for a sign connected over serial.
let mut display = FlipdotDisplay::try_new(
    SignBusType::Serial("/dev/ttyUSB0"),
    Address(3),
    SignType::Max3000Side90x7
)?;

// Draw some shapes and text to the page.
Circle::new(Point::new(2, 0), 6)
    .into_styled(PrimitiveStyle::with_stroke(BinaryColor::On, 1))
    .draw(&mut display)?;

Triangle::new(Point::new(11, 1), Point::new(15, 5), Point::new(19, 1))
    .into_styled(PrimitiveStyle::with_fill(BinaryColor::On))
    .draw(&mut display)?;

let style = MonoTextStyle::new(&FONT_5X7, BinaryColor::On);
Text::with_baseline("Hello, world!", Point::new(24, 0), style, Baseline::Top)
    .draw(&mut display)?;

// Send the page to the sign to be displayed.
display.flush()?;

Implementations§

Source§

impl FlipdotDisplay

Source

pub fn try_new( bus_type: SignBusType<'_>, address: Address, sign_type: SignType, ) -> Result<Self, Error>

The easiest way to get started drawing to a sign in a standalone fashion.

Creates a SignBus internally based on bus_type to simplify the common case. If you do need more control, you can provide your own bus using new_with_bus.

§Errors

Returns the underlying serial::Error if the serial port cannot be configured. Virtual sign bus creation can never fail.

§Examples
use flipdot_graphics::{Address, FlipdotDisplay, SignBusType, SignType};

// Create a display for a sign connected over serial.
let mut display = FlipdotDisplay::try_new(
    SignBusType::Serial("COM3"),
    Address(6),
    SignType::Max3000Front98x16
)?;
use flipdot_graphics::{Address, FlipdotDisplay, SignBusType, SignType};

// Create a display for a virtual sign for testing
// (set RUST_LOG=flipdot=info environment variable to see the results).
let mut display = FlipdotDisplay::try_new(
    SignBusType::Virtual,
    Address(4),
    SignType::HorizonDash40x12
)?;
Source

pub fn new_with_bus( bus: Rc<RefCell<dyn SignBus>>, address: Address, sign_type: SignType, ) -> Self

Alternative constructor if you need access to the underlying SignBus, perhaps because you want to draw to multiple signs on the same bus, want to inspect a VirtualSignBus for tests, etc.

For the common case where you only want to draw to a single sign, try_new is simpler.

§Examples
use std::{cell::RefCell, iter, rc::Rc};

use embedded_graphics::{
    pixelcolor::BinaryColor,
    prelude::*,
};
use flipdot::PageFlipStyle;
use flipdot_graphics::{Address, FlipdotDisplay, SignBusType, SignType};
use flipdot_testing::{VirtualSign, VirtualSignBus};

// Set up bus
let bus = VirtualSignBus::new(iter::once(VirtualSign::new(Address(3), PageFlipStyle::Manual)));
let bus = Rc::new(RefCell::new(bus));

let mut display = FlipdotDisplay::new_with_bus(
    bus.clone(),
    Address(3),
    SignType::Max3000Side90x7
);

// Draw to the display
display.draw_iter([Pixel(Point::new(0, 0), BinaryColor::On)])?;
display.flush()?;

// Show the page sent to the sign
println!("Got page:\n{}", bus.borrow().sign(0).pages()[0]);
Source

pub fn flush(&self) -> Result<(), SignError>

Sends all pending changes since the last flush to the sign.

Trait Implementations§

Source§

impl Debug for FlipdotDisplay

Source§

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

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

impl DrawTarget for FlipdotDisplay

Source§

type Color = BinaryColor

The pixel color type the targetted display supports.
Source§

type Error = Infallible

Error type to return when a drawing operation fails. Read more
Source§

fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where I: IntoIterator<Item = Pixel<Self::Color>>,

Draw individual pixels to the display without a defined order. Read more
Source§

fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error>

Fill the entire display with a solid color. Read more
Source§

fn fill_contiguous<I>( &mut self, area: &Rectangle, colors: I, ) -> Result<(), Self::Error>
where I: IntoIterator<Item = Self::Color>,

Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more
Source§

fn fill_solid( &mut self, area: &Rectangle, color: Self::Color, ) -> Result<(), Self::Error>

Fill a given area with a solid color. Read more
Source§

impl From<Sign> for FlipdotDisplay

Source§

fn from(sign: Sign) -> Self

Converts to this type from the input type.
Source§

impl OriginDimensions for FlipdotDisplay

Source§

fn size(&self) -> Size

Returns the size of the bounding box.

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> Dimensions for T

Source§

fn bounding_box(&self) -> Rectangle

Returns the bounding box.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.