pi-frame-server/src/main.rs

63 lines
1.6 KiB
Rust
Raw Normal View History

2024-07-18 12:34:28 +00:00
pub mod api;
pub mod display;
2024-07-24 14:43:09 +00:00
pub mod errors;
pub mod imageproc;
2024-06-29 16:55:37 +00:00
use crate::display::{EInkPanel, FakeEInk, Wrapper};
2024-07-17 18:27:31 +00:00
use crate::imageproc::{DiffusionMatrix, Ditherer, EInkImage, ErrorDiffusionDither};
2024-07-02 15:57:29 +00:00
use clap::{Parser, Subcommand};
use image::RgbImage;
/// Display images over
2024-06-29 16:55:37 +00:00
#[derive(Debug, Parser)]
#[command(version, about)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
/// Load a single image
2024-07-02 15:57:29 +00:00
Show,
2024-07-17 05:24:11 +00:00
/// Display a test pattern
Test,
/// Start the HTTP server
2024-06-29 16:55:37 +00:00
Serve,
}
2024-07-18 12:34:28 +00:00
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt::init();
2024-06-29 16:55:37 +00:00
let cli = Cli::parse();
println!("CLI {cli:?}");
2024-07-17 05:24:11 +00:00
if matches!(cli.command, Command::Show) {
let img: RgbImage = image::ImageReader::open("myimage.png")?.decode()?.into();
2024-07-16 23:55:59 +00:00
let mut display = Wrapper::new()?;
2024-07-02 15:57:29 +00:00
2024-07-17 18:27:31 +00:00
let mut eink_buf = EInkImage::new(800, 480);
let dither = ErrorDiffusionDither::new(DiffusionMatrix::Atkinson);
2024-07-02 15:57:29 +00:00
dither.dither(&img, &mut eink_buf);
let raw_buf = eink_buf.into_display_buffer();
display.display(&raw_buf)?;
2024-07-17 05:24:11 +00:00
}
if matches!(cli.command, Command::Test) {
let mut display = Wrapper::new()?;
display.test()?;
}
2024-07-24 14:43:09 +00:00
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?;
2024-07-24 14:43:09 +00:00
}
2024-06-29 16:55:37 +00:00
Ok(())
2024-06-24 13:29:59 +00:00
}