mod common;
use std::error::Error;
use escpos_vfd::VfdWorker;
fn main() -> Result<(), Box<dyn Error>> {
let mut args = common::ExampleArgs::from_env()?;
let delay_ms: u64 = args.parse_or(80);
let columns = args.columns;
let worker = VfdWorker::start(args.config)?;
let vfd = worker.handle();
vfd.clear()?;
vfd.print_line_diff(1, "print_at demo")?;
vfd.print_line_diff(2, "--------------------")?;
let y = 2u8;
let mut x: u8 = 1;
let mut dir: i8 = 1;
let mut prev_x: u8 = x;
loop {
vfd.print_at(prev_x, y, " ")?;
vfd.print_at(x, y, "█")?;
prev_x = x;
if dir > 0 {
if (x as usize) >= columns {
dir = -1;
} else {
x += 1;
}
} else {
if x <= 1 {
dir = 1;
} else {
x -= 1;
}
}
common::sleep_ms(delay_ms);
}
}