use serde::Deserialize; #[derive(Debug, Default)] pub enum PrintStatus { #[default] Unknown, Idle, Printing, Paused, Finished, } #[derive(Debug, Default)] pub struct PrinterState { pub bed_temp: f32, pub status: PrintStatus, } #[derive(Debug, Deserialize)] #[serde(rename_all = "SCREAMING_SNAKE_CASE")] pub enum PrusaState { Idle, Printing, Paused, Finished, Stopped, Error, Attention, Busy, } #[derive(Debug, Deserialize)] pub struct PrusaJob { pub id: u32, pub progress: f32, pub time_remaining: u32, pub time_printing: u32, } #[derive(Debug, Deserialize)] pub struct PrusaPrinterInfo { pub state: PrusaState, pub temp_nozzle: f32, pub target_nozzle: f32, pub temp_bed: f32, pub target_bed: f32, pub axis_x: f32, pub axis_y: f32, pub axis_z: f32, pub flow: u32, pub speed: u32, pub fan_hotend: u32, pub fan_print: u32, } #[derive(Debug, Deserialize)] pub struct PrusaStatus { pub job: Option, pub printer: PrusaPrinterInfo, } #[derive(Deserialize)] pub struct BambuState { pub bed_temper: f32, } #[derive(Deserialize)] pub struct BambuMessage { pub print: BambuState, } #[derive(Debug, Deserialize)] pub struct Config { // This allows you to have a list of different printer types pub printers: Vec, } impl Config { pub fn load(toml: &str) -> Config { toml::from_str(toml).expect("Couldn't parse config.toml") } } #[derive(Debug, Deserialize)] #[serde(tag = "type", rename_all = "lowercase")] pub enum Printer { Prusa { name: String, host: String, api_key: String, }, Bambu { name: String, host: String, access_code: String, serial_number: String, }, } pub fn extract_status_from_prusa(status: &PrusaStatus) -> PrinterState { let print_status = match status.printer.state { PrusaState::Idle => PrintStatus::Idle, PrusaState::Printing => PrintStatus::Printing, PrusaState::Paused => PrintStatus::Paused, PrusaState::Finished => PrintStatus::Finished, _ => PrintStatus::Unknown, }; PrinterState { bed_temp: status.printer.temp_bed, status: print_status } }