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
impl FlipdotDisplay
Sourcepub fn try_new(
bus_type: SignBusType<'_>,
address: Address,
sign_type: SignType,
) -> Result<Self, Error>
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
)?;Sourcepub fn new_with_bus(
bus: Rc<RefCell<dyn SignBus>>,
address: Address,
sign_type: SignType,
) -> Self
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]);