63 lines
1.6 KiB
Rust
63 lines
1.6 KiB
Rust
pub mod api;
|
|
pub mod display;
|
|
pub mod errors;
|
|
pub mod imageproc;
|
|
|
|
use crate::display::{EInkPanel, FakeEInk, Wrapper};
|
|
use crate::imageproc::{DiffusionMatrix, Ditherer, EInkImage, ErrorDiffusionDither};
|
|
use clap::{Parser, Subcommand};
|
|
use image::RgbImage;
|
|
|
|
/// Display images over
|
|
#[derive(Debug, Parser)]
|
|
#[command(version, about)]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
command: Command,
|
|
}
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
enum Command {
|
|
/// Load a single image
|
|
Show,
|
|
/// Display a test pattern
|
|
Test,
|
|
/// Start the HTTP server
|
|
Serve,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> anyhow::Result<()> {
|
|
tracing_subscriber::fmt::init();
|
|
let cli = Cli::parse();
|
|
println!("CLI {cli:?}");
|
|
|
|
if matches!(cli.command, Command::Show) {
|
|
let img: RgbImage = image::ImageReader::open("myimage.png")?.decode()?.into();
|
|
let mut display = Wrapper::new()?;
|
|
|
|
let mut eink_buf = EInkImage::new(800, 480);
|
|
let dither = ErrorDiffusionDither::new(DiffusionMatrix::Atkinson);
|
|
|
|
dither.dither(&img, &mut eink_buf);
|
|
let raw_buf = eink_buf.into_display_buffer();
|
|
display.display(&raw_buf)?;
|
|
}
|
|
if matches!(cli.command, Command::Test) {
|
|
let mut display = Wrapper::new()?;
|
|
|
|
display.test()?;
|
|
}
|
|
|
|
if matches!(cli.command, Command::Serve) {
|
|
let display = FakeEInk {};
|
|
let ctx = api::Context::new(Box::new(display));
|
|
|
|
let app = api::router().with_state(ctx);
|
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
|
|
axum::serve(listener, app).await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|