use std::cell::RefCell;
use std::error::Error;
use std::rc::Rc;
use flipdot::{Address, PageFlipStyle, PageId, Sign, SignType};
use flipdot_testing::{VirtualSign, VirtualSignBus};
fn main() -> Result<(), Box<dyn Error>> {
let virtual_signs = vec![VirtualSign::new(Address(3), PageFlipStyle::Manual)];
let bus = Rc::new(RefCell::new(VirtualSignBus::new(virtual_signs)));
let sign = Sign::new(bus.clone(), Address(3), SignType::Max3000Side90x7);
sign.configure()?;
let mut page1 = sign.create_page(PageId(0));
for x in 0..page1.width() {
for y in 0..page1.height() {
page1.set_pixel(x, y, x % 4 == y % 4);
}
}
let mut page2 = sign.create_page(PageId(1));
for x in 0..page2.width() {
for y in 0..page2.height() {
page2.set_pixel(x, y, (x + y) % 5 > 2);
}
}
if sign.send_pages(&[page1, page2])? == PageFlipStyle::Manual {
println!("Manually flipping pages");
sign.show_loaded_page()?;
sign.load_next_page()?;
sign.show_loaded_page()?;
} else {
println!("Sign should automatically flip pages");
}
println!("Sign configured as {:?}", bus.borrow().sign(0).sign_type());
for page in bus.borrow().sign(0).pages() {
println!("Page {}:\n{}", page.id(), page);
}
Ok(())
}