diff --git a/examples/auto_connect_bambu.rs b/examples/auto_connect_bambu.rs index 44992f1..c4a15b1 100644 --- a/examples/auto_connect_bambu.rs +++ b/examples/auto_connect_bambu.rs @@ -17,9 +17,8 @@ fn main() -> anyhow::Result<()> { let cert_dir = std::path::Path::new("certs/pinned"); for printer in &mut printers { - match printer { - PrinterHandle::Bambu(bambu) => report(&bambu.ensure_trusted(cert_dir)), - _ => {} + if let PrinterHandle::Bambu(bambu) = printer { + report(&bambu.ensure_trusted(cert_dir)) } } diff --git a/examples/bambu_cache_list.rs b/examples/bambu_cache_list.rs index 03905af..62cb722 100644 --- a/examples/bambu_cache_list.rs +++ b/examples/bambu_cache_list.rs @@ -53,34 +53,34 @@ async fn main() -> anyhow::Result<()> { let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT; loop { - if let Some(report) = bambu.print_status().await { - if let Some(state) = report.gcode_state.clone() { - println!(" gcode_state: {state}"); - println!(" subtask_name: {}", report.subtask_name.clone().unwrap_or_default()); - println!( - " layer: {}/{}", - report.layer_num.unwrap_or_default(), - report.total_layer_num.unwrap_or_default() - ); - println!(" percent: {}", report.mc_percent.unwrap_or_default()); - // Temperatures and remaining time, because state plus layer - // number cannot tell a print that is working from one that is - // stalled: a P1P sits at layer 0 for minutes during bed - // levelling and purge, and the only thing moving in that - // window is the heat. - println!( - " nozzle: {:.1} -> {:.1} C", - report.nozzle_temper.unwrap_or_default(), - report.nozzle_target_temper.unwrap_or_default() - ); - println!( - " bed: {:.1} -> {:.1} C", - report.bed_temper.unwrap_or_default(), - report.bed_target_temper.unwrap_or_default() - ); - println!(" remaining: {} min", report.mc_remaining_time.unwrap_or_default()); - break; - } + if let Some(report) = bambu.print_status().await + && let Some(state) = report.gcode_state.clone() + { + println!(" gcode_state: {state}"); + println!(" subtask_name: {}", report.subtask_name.clone().unwrap_or_default()); + println!( + " layer: {}/{}", + report.layer_num.unwrap_or_default(), + report.total_layer_num.unwrap_or_default() + ); + println!(" percent: {}", report.mc_percent.unwrap_or_default()); + // Temperatures and remaining time, because state plus layer + // number cannot tell a print that is working from one that is + // stalled: a P1P sits at layer 0 for minutes during bed + // levelling and purge, and the only thing moving in that + // window is the heat. + println!( + " nozzle: {:.1} -> {:.1} C", + report.nozzle_temper.unwrap_or_default(), + report.nozzle_target_temper.unwrap_or_default() + ); + println!( + " bed: {:.1} -> {:.1} C", + report.bed_temper.unwrap_or_default(), + report.bed_target_temper.unwrap_or_default() + ); + println!(" remaining: {} min", report.mc_remaining_time.unwrap_or_default()); + break; } if tokio::time::Instant::now() >= deadline { println!(" (no gcode_state within {STATUS_TIMEOUT:?} - listing cache/ anyway)"); diff --git a/examples/bambu_idle_checks.rs b/examples/bambu_idle_checks.rs index eddaf8e..30400a9 100644 --- a/examples/bambu_idle_checks.rs +++ b/examples/bambu_idle_checks.rs @@ -69,10 +69,10 @@ async fn main() -> anyhow::Result<()> { let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT; let state = loop { - if let Some(report) = bambu.print_status().await { - if let Some(state) = report.gcode_state.clone() { - break state; - } + if let Some(report) = bambu.print_status().await + && let Some(state) = report.gcode_state.clone() + { + break state; } if tokio::time::Instant::now() >= deadline { anyhow::bail!( diff --git a/examples/bambu_print_probe.rs b/examples/bambu_print_probe.rs index 971fad4..1303b44 100644 --- a/examples/bambu_print_probe.rs +++ b/examples/bambu_print_probe.rs @@ -10,20 +10,20 @@ //! //! - `status` read-only. Connect, print state, list `cache/`. //! - `probe-missing` **zero physical risk.** Sends `print.gcode_file` -//! pointing at a file that does not exist. The printer -//! cannot start anything, so this isolates one -//! question: does it accept and parse the command shape -//! at all? A clean rejection naming the file means the -//! shape is right and only the target was wrong. A -//! parse error, or silence, means the shape is wrong. +//! pointing at a file that does not exist. The printer +//! cannot start anything, so this isolates one +//! question: does it accept and parse the command shape +//! at all? A clean rejection naming the file means the +//! shape is right and only the target was wrong. A +//! parse error, or silence, means the shape is wrong. //! - `start ` sends `print.gcode_file`/`print.project_file` for a -//! file in `cache/`. Gated on `gcode_state: IDLE` and -//! on the explicit flag. +//! file in `cache/`. Gated on `gcode_state: IDLE` and +//! on the explicit flag. //! - `pause` / `resume` / `stop` -//! the control commands. `stop` cancels - it is the -//! undo for `start`, and the reason `start` is worth -//! testing at all: without it a cloud-initiated print -//! could only be ended at the machine. +//! the control commands. `stop` cancels - it is the +//! undo for `start`, and the reason `start` is worth +//! testing at all: without it a cloud-initiated print +//! could only be ended at the machine. //! //! After whatever it sends, it watches the `print.push_status` stream and //! reports every change to the fields that matter. Run with @@ -230,10 +230,10 @@ async fn main() -> anyhow::Result<()> { async fn wait_for_state(bambu: &continuum_proxy::printer::BambuPrinter) -> anyhow::Result { let deadline = tokio::time::Instant::now() + STATUS_TIMEOUT; loop { - if let Some(report) = bambu.print_status().await { - if let Some(state) = report.gcode_state.clone() { - return Ok(state); - } + if let Some(report) = bambu.print_status().await + && let Some(state) = report.gcode_state.clone() + { + return Ok(state); } if tokio::time::Instant::now() >= deadline { anyhow::bail!( @@ -259,11 +259,11 @@ async fn watch(bambu: &continuum_proxy::printer::BambuPrinter, before: String) { tokio::time::sleep(Duration::from_millis(1500)).await; if let Some(report) = bambu.print_status().await { - if let Some(state) = report.gcode_state.clone() { - if state != last { - println!(" gcode_state: {last} -> {state}"); - last = state; - } + if let Some(state) = report.gcode_state.clone() + && state != last + { + println!(" gcode_state: {last} -> {state}"); + last = state; } if report.print_error != last_error { println!(" print_error: {:?} -> {:?}", last_error, report.print_error); @@ -274,10 +274,10 @@ async fn watch(bambu: &continuum_proxy::printer::BambuPrinter, before: String) { println!(" subtask_name: '{last_task}' -> '{task}'"); last_task = task; } - if let Some(hms) = &report.hms { - if !hms.is_empty() { - println!(" hms (printer alerts): {}", serde_json::to_string(hms).unwrap_or_default()); - } + if let Some(hms) = &report.hms + && !hms.is_empty() + { + println!(" hms (printer alerts): {}", serde_json::to_string(hms).unwrap_or_default()); } } } diff --git a/examples/live_reports.rs b/examples/live_reports.rs index 9e617ec..96ffa35 100644 --- a/examples/live_reports.rs +++ b/examples/live_reports.rs @@ -9,7 +9,7 @@ //! //! - `get_version` - read-only. //! - `pushall` - "re-send the full status object". A request for data, -//! not a state change. v1 only; a no-op on v2. +//! not a state change. v1 only; a no-op on v2. //! - `print_status` - reads this process's own in-memory cache, no traffic. //! //! It deliberately sends **no** `gcode_line`, **no** `set_fan_speed`, **no** @@ -65,10 +65,10 @@ async fn main() -> anyhow::Result<()> { let only: Option = std::env::args().nth(1); for printer in &mut printers { - if let Some(id) = &only { - if &printer.base().id != id { - continue; - } + if let Some(id) = &only + && &printer.base().id != id + { + continue; } let PrinterHandle::Bambu(bambu) = printer else { println!("skipping {} - not a Bambu printer", printer.display_name()); diff --git a/examples/printer_polymorphism.rs b/examples/printer_polymorphism.rs index 4067ac9..b3215c4 100644 --- a/examples/printer_polymorphism.rs +++ b/examples/printer_polymorphism.rs @@ -61,9 +61,8 @@ async fn main() { // cache) - none of these connected above (fake IPs), so it's always // `None`, but the point is the downcast, not a live reading. for printer in &fleet { - match printer { - PrinterHandle::Bambu(bambu) => println!(" {}: cached print_status = {:?}", bambu.sn, bambu.print_status().await), - _ => {} + if let PrinterHandle::Bambu(bambu) = printer { + println!(" {}: cached print_status = {:?}", bambu.sn, bambu.print_status().await) } } diff --git a/examples/test_bambu_certs.rs b/examples/test_bambu_certs.rs index ae29aa3..555045a 100644 --- a/examples/test_bambu_certs.rs +++ b/examples/test_bambu_certs.rs @@ -13,9 +13,8 @@ fn main() -> anyhow::Result<()> { let printers = fleet::load(std::path::Path::new("printers.toml"))?; for printer in &printers { - match printer { - PrinterHandle::Bambu(bambu) => report(bambu.base().name.as_str(), bambu.test_tls_handshake()), - _ => {} + if let PrinterHandle::Bambu(bambu) = printer { + report(bambu.base().name.as_str(), bambu.test_tls_handshake()) } } diff --git a/src/printer/bambu_commands/mod.rs b/src/printer/bambu_commands/mod.rs index 7c74397..c285ab3 100644 --- a/src/printer/bambu_commands/mod.rs +++ b/src/printer/bambu_commands/mod.rs @@ -7,9 +7,10 @@ //! continuum-schemas for continuum.v1, which is a schema we designed //! ourselves and that both TS and Rust genuinely need. //! -//! One file per Bambu *category* (`get_version.rs` for "info", `pushall.rs` -//! + `print.rs` for "pushing"/"print" - see below for why those are two -//! files, not one). Copy `get_version.rs`'s shape for your next command. +//! One file per Bambu *category* (`get_version.rs` for "info", +//! `pushall.rs` + `print.rs` for "pushing"/"print" - see below for why +//! those are two files, not one). Copy `get_version.rs`'s shape for your +//! next command. //! //! Mirrors continuum-schemas' `schemas/bambulab/` JSON Schemas - same //! category split, same "print vs pushing" correction (see that diff --git a/src/printer/bambu_commands/print.rs b/src/printer/bambu_commands/print.rs index 448a548..8c7eaee 100644 --- a/src/printer/bambu_commands/print.rs +++ b/src/printer/bambu_commands/print.rs @@ -207,9 +207,9 @@ pub struct AmsUnit { pub info: Option, } -/// A tray slot is either empty (just `id`) or loaded (the full field set) -/// - two genuinely different shapes, not one shape with optional fields, -/// so this is an untagged enum rather than a struct full of `Option`. +/// A tray slot is either empty (just `id`) or loaded (the full field set) - +/// two genuinely different shapes, not one shape with optional fields, so +/// this is an untagged enum rather than a struct full of `Option`. /// `#[serde(deny_unknown_fields)]` on `Empty` is load-bearing: untagged /// enums try variants in order, and without it a *loaded* tray (which has /// every field `Empty` allows, plus more) would incorrectly match `Empty` diff --git a/src/printer/bambu_mqtt.rs b/src/printer/bambu_mqtt.rs index d6f2e3d..146cf37 100644 --- a/src/printer/bambu_mqtt.rs +++ b/src/printer/bambu_mqtt.rs @@ -162,14 +162,14 @@ impl PrintStatusCache { // the next one that did looked like it had skipped ahead. That is now // reported where it happens (see `handle_incoming_report`), which // leaves this warning meaning what it says. - if let (Some(last), Some(incoming_seq), false) = (self.last_sequence_id, incoming_seq, is_full_object) { - if incoming_seq != last.wrapping_add(1) { - eprintln!( - "print.push_status sequence gap: expected {}, got {incoming_seq} - the in-memory \ - object may be missing whatever changed in between", - last.wrapping_add(1) - ); - } + if let (Some(last), Some(incoming_seq), false) = (self.last_sequence_id, incoming_seq, is_full_object) + && incoming_seq != last.wrapping_add(1) + { + eprintln!( + "print.push_status sequence gap: expected {}, got {incoming_seq} - the in-memory \ + object may be missing whatever changed in between", + last.wrapping_add(1) + ); } if let Some(incoming_seq) = incoming_seq { self.last_sequence_id = Some(incoming_seq); @@ -305,17 +305,17 @@ impl BambuMqttSession { /// whose `sequence_id` matches the one this call sent. /// /// This crate tried adding its own correlation field - /// (`continuum_correlation_id`) instead of relying on `sequence_id`, - /// on the understanding that extra fields survive into most replies. - /// Confirmed live that this doesn't hold for `get_version` specifically - /// - a real H2C's reply had exactly `["command", "module", + /// (`continuum_correlation_id`) instead of relying on `sequence_id`, on + /// the understanding that extra fields survive into most replies. + /// Confirmed live that this doesn't hold for `get_version` + /// specifically - a real H2C's reply had exactly `["command", "module", /// "sequence_id"]`, nothing extra at all, so the correlation field /// never came back and every `get_version` call just timed out. /// `sequence_id` is what's actually proven to round-trip for it - /// (confirmed earlier, live, on both protocol versions), so that's - /// what this uses. Whether a custom field survives on some *other* - /// command (`calibration`, say) is unverified, not confirmed false - - /// this was only ever checked for `get_version`. + /// (confirmed earlier, live, on both protocol versions), so that's what + /// this uses. Whether a custom field survives on some *other* command + /// (`calibration`, say) is unverified, not confirmed false - this was + /// only ever checked for `get_version`. /// /// Not for `print.push_status` - that's not a single reply, see /// `PrintStatusCache`. Not for a command with no reply at all either, diff --git a/src/printer/mod.rs b/src/printer/mod.rs index fa9f22c..eafdd3c 100644 --- a/src/printer/mod.rs +++ b/src/printer/mod.rs @@ -143,11 +143,12 @@ pub trait GenericPrinter { } /// M106's `S` parameter is a raw 0-255 PWM value, not a percentage. Shared -/// by anything that ultimately sends gcode (Bambu, PrusaLink, PrusaSerial) -/// - *not* a trait default, since Klipper's hypothetical native fan API -/// below takes a percent directly and has no use for this at all. Private, -/// but still visible to bambu.rs/prusa.rs: Rust's module privacy reaches -/// into child modules, not just the exact file it's defined in. +/// by anything that ultimately sends gcode (Bambu, PrusaLink, +/// PrusaSerial) - *not* a trait default, since Klipper's hypothetical +/// native fan API below takes a percent directly and has no use for this at +/// all. Private, but still visible to bambu.rs/prusa.rs: Rust's module +/// privacy reaches into child modules, not just the exact file it's defined +/// in. fn percent_to_pwm(percent: u8) -> u8 { ((percent.min(100) as u16 * 255) / 100) as u8 }