use crabcamera::commands::capture::{
capture_single_photo, save_frame_compressed, save_frame_to_disk, start_camera_preview,
stop_camera_preview,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")).init();
println!("\n=============================================================");
println!(" Simulating Hardware Audit Flow");
println!("=============================================================\n");
let device_id = "0".to_string();
println!("[1] start_camera_preview({}, None)...", device_id);
match start_camera_preview(device_id.clone(), None).await {
Ok(msg) => println!(" OK: {}", msg),
Err(e) => println!(" ERROR: {}", e),
}
println!("\n[2] Waiting 3 seconds for warmup...");
tokio::time::sleep(tokio::time::Duration::from_secs(3)).await;
println!("\n[3] stop_camera_preview({})...", device_id);
match stop_camera_preview(device_id.clone()).await {
Ok(msg) => println!(" OK: {}", msg),
Err(e) => println!(" ERROR: {}", e),
}
println!("\n[4] capture_single_photo({}, None)...", device_id);
match capture_single_photo(Some(device_id.clone()), None).await {
Ok(frame) => {
println!(
" OK: {}x{}, {} bytes",
frame.width, frame.height, frame.size_bytes
);
if frame.data.len() >= 3 {
println!(
" First 3 bytes: {:02X} {:02X} {:02X}",
frame.data[0], frame.data[1], frame.data[2]
);
}
println!("\n[5] Saving raw frame...");
match save_frame_to_disk(frame.clone(), "debug_raw.png".to_string()).await {
Ok(msg) => println!(" OK: {}", msg),
Err(e) => println!(" ERROR: {}", e),
}
println!("\n[6] Saving compressed frame...");
match save_frame_compressed(frame.clone(), "debug_compressed.jpg".to_string(), Some(85))
.await
{
Ok(msg) => println!(" OK: {}", msg),
Err(e) => println!(" ERROR: {}", e),
}
}
Err(e) => println!(" ERROR: {}", e),
}
println!("\n=============================================================\n");
Ok(())
}