Restructure printer code

This commit is contained in:
Joscha 2024-03-08 11:50:25 +01:00
parent dc6265f837
commit ce2f986983
5 changed files with 149 additions and 96 deletions

View file

@ -1,4 +1,4 @@
mod command;
mod drawer;
mod printer;
mod server;
mod util;
@ -6,26 +6,39 @@ mod util;
use std::path::PathBuf;
use clap::Parser;
use drawer::Drawer;
use printer::Printer;
use tokio::{runtime::Runtime, sync::mpsc};
#[derive(Parser)]
struct Args {
path: PathBuf,
/// Address the web server will listen at.
addr: String,
/// Path to the printer's USB device file.
///
/// Usually, this is located at `/dev/usb/lp0` or a similar location.
#[arg(long, short)]
printer: Option<PathBuf>,
/// Export an image of whatever is printed here.
#[arg(long, short)]
export: Option<PathBuf>,
}
fn main() -> anyhow::Result<()> {
let args = Args::parse();
let (tx, rx) = mpsc::channel(3);
let mut printer = Printer::new(rx, &args.path)?;
let printer = Printer::new(args.printer, args.export)?;
let mut drawer = Drawer::new(rx, printer);
let runtime = Runtime::new()?;
runtime.spawn(server::run(tx, args.addr));
println!("Running");
printer.run()?;
drawer.run()?;
Ok(())
}