Struct flipdot::Sign [−][src]
A single sign on an associated bus.
Basic operation consists of configuring the sign, sending one or more pages of a message, then requesting a page flip as desired. The types of signs that are supported are “dumb” in that they don’t have any display logic of their own; all operations are remotely controlled.
Examples
use std::cell::RefCell; use std::rc::Rc; use flipdot::{Address, PageId, Sign, SignType, SerialSignBus}; // Set up bus. Because the bus can be shared among // multiple signs, it must be wrapped in an Rc<RefCell>. let port = serial::open("/dev/ttyUSB0")?; let bus = SerialSignBus::try_new(port)?; let bus = Rc::new(RefCell::new(bus)); // Create a sign with the appropriate address and type. let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); // First, the configuration data must be sent to the sign. sign.configure()?; // Next, we can create some pages, turn on pixels, and send them to the sign. let mut page1 = sign.create_page(PageId(0)); page1.set_pixel(0, 0, true); let mut page2 = sign.create_page(PageId(1)); page2.set_pixel(1, 1, true); sign.send_pages(&[page1, page2])?; // The first page is now loaded in the sign's memory and can be shown. sign.show_loaded_page()?; // Load the second page into memory, then show it. sign.load_next_page()?; sign.show_loaded_page()?;
Implementations
impl Sign
[src]
pub fn new(
bus: Rc<RefCell<dyn SignBus>>,
address: Address,
sign_type: SignType
) -> Self
[src]
bus: Rc<RefCell<dyn SignBus>>,
address: Address,
sign_type: SignType
) -> Self
Creates a new Sign
with the given address and type, which will represent and control
an actual sign on the provided SignBus
.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7);
pub fn address(&self) -> Address
[src]
Returns the sign’s address.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); assert_eq!(Address(3), sign.address());
pub fn sign_type(&self) -> SignType
[src]
Returns the sign’s type.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); assert_eq!(SignType::Max3000Side90x7, sign.sign_type());
pub fn width(&self) -> u32
[src]
Returns the width in pixels of the sign’s display area.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); assert_eq!(90, sign.width());
pub fn height(&self) -> u32
[src]
Returns the height in pixels of the sign’s display area.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); assert_eq!(7, sign.height());
pub fn create_page<'a>(&self, id: PageId) -> Page<'a>
[src]
Creates a page with the given ID that matches the sign’s dimensions.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); let mut page = sign.create_page(PageId(1)); assert_eq!(PageId(1), page.id()); assert_eq!(page.width(), sign.width()); assert_eq!(page.height(), sign.height()); page.set_pixel(1, 5, true);
pub fn configure(&self) -> Result<(), SignError>
[src]
Opens communications with the sign and sends the necessary configuration.
This must be called first before communicating with the sign. If the sign has already been configured, it will be reset and its page memory will be cleared.
Errors
Returns:
SignError::Bus
if the underlying bus failed to process a message.SignError::UnexpectedResponse
if the sign did not send the expected response according to the protocol. In this case it is recommended to re-configure
the sign and start over.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); sign.configure()?; // Sign is now ready to receive pages.
pub fn send_pages<'a, I>(&self, pages: I) -> Result<(), SignError> where
I: IntoIterator<Item = &'a Page<'a>>,
<I as IntoIterator>::IntoIter: Clone,
[src]
I: IntoIterator<Item = &'a Page<'a>>,
<I as IntoIterator>::IntoIter: Clone,
Sends one or more pages of pixel data to the sign.
Can be called at any time after configure
. Replaces any pages that had been previously sent.
Upon return, the first page will be loaded and ready to be shown.
Errors
Returns:
SignError::Bus
if the underlying bus failed to process a message.SignError::UnexpectedResponse
if the sign did not send the expected response according to the protocol. In this case it is recommended to re-configure
the sign and start over.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); sign.configure()?; let page = sign.create_page(PageId(1)); sign.send_pages(&[page])?; // Page has now been loaded but not shown.
pub fn load_next_page(&self) -> Result<(), SignError>
[src]
Loads the next page into memory.
Once a page has been shown, this is called to prepare the next page to be shown.
Errors
Returns:
SignError::Bus
if the underlying bus failed to process a message.SignError::UnexpectedResponse
if the sign did not send the expected response according to the protocol. In this case it is recommended to re-configure
the sign and start over.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); sign.configure()?; let pages = [sign.create_page(PageId(1)), sign.create_page(PageId(2))]; sign.send_pages(&pages)?; sign.show_loaded_page()?; sign.load_next_page()?; // Page 1 is now shown and page 2 is loaded.
pub fn show_loaded_page(&self) -> Result<(), SignError>
[src]
Shows the currently loaded page on the display.
Once a page has been loaded (either via send_pages
or load_next_page
), this method will make it visible.
Errors
Returns:
SignError::Bus
if the underlying bus failed to process a message.SignError::UnexpectedResponse
if the sign did not send the expected response according to the protocol. In this case it is recommended to re-configure
the sign and start over.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); sign.configure()?; let page = sign.create_page(PageId(1)); sign.send_pages(&[page])?; sign.show_loaded_page()?; // Page is now shown.
pub fn shut_down(&self) -> Result<(), SignError>
[src]
Blanks the display and shuts the sign down.
The sign will not be usable for 30 seconds after calling this method. Generally optional as disconnecting switched power from the sign should have the same effect.
Errors
Returns:
SignError::Bus
if the underlying bus failed to process a message.SignError::UnexpectedResponse
if the sign did not send the expected response according to the protocol. In this case it is recommended to re-configure
the sign and start over.
Examples
let bus = get_bus(); let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7); sign.configure()?; let page = sign.create_page(PageId(1)); sign.send_pages(&[page])?; sign.show_loaded_page()?; sign.shut_down()?; // Sign is now blanked.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Sign
impl !Send for Sign
impl !Sync for Sign
impl Unpin for Sign
impl !UnwindSafe for Sign
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,
pub 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, 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.
pub 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>,