firmware for my Touchscreen E-Paper Input Module for Framework Laptop 16
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

at f6676c82689a4e7314b93c8eb98ddd08152fe708 90 lines 2.4 kB view raw
1use std::fs::File; 2use std::io::Read; 3use std::path::PathBuf; 4use clap::{Parser, Subcommand}; 5use tar::Archive; 6use eepy_serial_host::{Normal, Serial}; 7use eepy_serial_host::image::IMAGE_BYTES; 8 9#[derive(Parser, Debug)] 10#[command(version, about, long_about = None)] 11struct Args { 12 #[arg(short = 'p', long)] 13 serial_port: String, 14 15 #[command(subcommand)] 16 command: Subcommands, 17} 18 19#[derive(Subcommand, Debug)] 20enum Subcommands { 21 EnterHostApp, 22 ExitHostApp, 23 24 Refresh { 25 #[arg(long, action)] 26 fast: bool, 27 #[arg(long, action)] 28 maybe: bool, 29 #[arg(short, long)] 30 image: PathBuf, 31 }, 32 33 DisableTouch, 34 EnableTouch, 35 NextEvent, 36 37 UploadProgram { 38 package: PathBuf, 39 }, 40} 41 42use Subcommands::*; 43 44fn upload_program(serial: &mut Serial<Normal>, path: PathBuf) -> color_eyre::Result<()> { 45 let slot_n = serial.get_slot()?; 46 47 let file = File::open(path)?; 48 let zstd_reader = zstd::stream::read::Decoder::new(file)?; 49 let mut tar = Archive::new(zstd_reader); 50 for file in tar.entries()? { 51 let mut file = file?; 52 if file.path()?.to_str().unwrap().ends_with(&format!(".s{slot_n:02}.epb")) { 53 println!("Uploading {}", file.path()?.to_str().unwrap()); 54 let mut buf = vec![0u8; file.size() as usize]; 55 file.read_exact(&mut buf)?; 56 serial.upload(&buf)?; 57 return Ok(()); 58 } 59 } 60 61 panic!("App package did not contain binary for slot {slot_n}"); 62} 63 64fn main() -> color_eyre::Result<()> { 65 let args = Args::parse(); 66 67 let port = Serial::new(&args.serial_port)?; 68 69 match args.command { 70 EnterHostApp => { port.host_app()?; }, 71 ExitHostApp => { port.normal()?; }, 72 Refresh { fast, maybe, image } => { 73 let mut buf = [0u8; IMAGE_BYTES]; 74 let mut file = File::open(image)?; 75 file.read_exact(&mut buf)?; 76 77 if maybe { 78 port.host_app()?.maybe_refresh(fast, &buf)?; 79 } else { 80 port.host_app()?.refresh(fast, &buf)?; 81 } 82 }, 83 DisableTouch => port.host_app()?.set_touch_enabled(false)?, 84 EnableTouch => port.host_app()?.set_touch_enabled(true)?, 85 NextEvent => println!("{:?}", port.host_app()?.next_event()?), 86 UploadProgram { package } => upload_program(&mut port.normal()?, package)?, 87 } 88 89 Ok(()) 90}