From f2f257e9e1f1e2a6fefd5df00a317ae721031d5a Mon Sep 17 00:00:00 2001 From: Serguey Parkhomovsky Date: Mon, 16 Mar 2026 21:13:51 -0700 Subject: add more fields to bambu status --- src/lib.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index a49aba0..7c2aea7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,16 @@ pub enum PrusaState { Busy, } +#[derive(Debug, Deserialize)] +#[serde(rename_all = "SCREAMING_SNAKE_CASE")] +pub enum BambuState { + Idle, + Running, + Pause, + Finish, + Failed, +} + #[derive(Debug, Deserialize)] pub struct PrusaJob { pub id: u32, @@ -60,13 +70,22 @@ pub struct PrusaStatus { } #[derive(Deserialize)] -pub struct BambuState { - pub bed_temper: f32, +pub struct BambuPrintMessage { + pub bed_target_temper: Option, + pub bed_temper: Option, + pub gcode_state: Option, + pub layer_num: Option, + pub mc_percent: Option, + pub mc_remaining_time: Option, + pub nozzle_target_temper: Option, + pub nozzle_temper: Option, + pub print_speed: Option, + pub total_layer_num: Option, } #[derive(Deserialize)] -pub struct BambuMessage { - pub print: BambuState, +pub struct BambuStatus { + pub print: Option, } #[derive(Debug, Deserialize)] @@ -97,13 +116,30 @@ pub enum Printer { }, } -pub fn extract_status_from_prusa(status: &PrusaStatus) -> PrinterState { - let print_status = match status.printer.state { +pub fn extract_status_from_prusa(status: &PrusaStatus, state: &mut PrinterState) { + state.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 } -} \ No newline at end of file + state.bed_temp = status.printer.temp_bed; +} + +pub fn extract_status_from_bambu(status: &BambuStatus, state: &mut PrinterState) { + if let Some(print) = &status.print { + if let Some(bed_temper) = print.bed_temper { + state.bed_temp = bed_temper; + } + if let Some(gcode_state) = &print.gcode_state { + state.status = match gcode_state { + BambuState::Idle => PrintStatus::Idle, + BambuState::Running => PrintStatus::Printing, + BambuState::Pause => PrintStatus::Paused, + BambuState::Finish => PrintStatus::Finished, + _ => PrintStatus::Unknown, + }; + } + } +} -- cgit v1.2.3