use super::{GenericPrinter, PrinterBase, PrinterError}; pub struct KlipperPrinter { base: PrinterBase, } impl KlipperPrinter { pub fn new(id: &str, name: &str, host: &str) -> Self { Self { base: PrinterBase { id: id.into(), name: name.into(), host: host.into() }, } } } impl GenericPrinter for KlipperPrinter { fn base(&self) -> &PrinterBase { &self.base } /// OVERRIDE: a third, again-different body - Moonraker's real feed is a /// WebSocket (see `adapters::moonraker`). This also shows the `Err` /// path: an empty `host` fails immediately, same as any other vendor /// would if it couldn't reach its printer. async fn connect(&mut self) -> Result<(), PrinterError> { if self.base.host.is_empty() { return Err(PrinterError(format!("{} has no host configured", self.base.name))); } println!("[{}] connecting over WebSocket (Moonraker)", self.base.name); Ok(()) } async fn publish(&mut self, _payload: String) -> Result<(), PrinterError> { // TODO: add publishing via HTTP Ok(()) } /// OVERRIDE: Moonraker's own **hypothetical** native API, not gcode injection - no /// percent-to-PWM conversion needed since it already takes a /// percentage directly. Real version: /// `POST /printer/gcode/script?script=SET_FAN_SPEED SPEED=0.NN`. async fn set_fan_speed(&mut self, percent: u8) -> Result<(), PrinterError> { println!("[{}] Moonraker: SET_FAN_SPEED SPEED={:.2}", self.base.name, percent as f32 / 100.0); Ok(()) } /// OVERRIDE: real version is a multipart `POST /server/files/upload` /// with `data` as the file part - Moonraker stores it on the printer's /// virtual SD card, same upload-then-start model as Bambu/PrusaLink. async fn upload_project_file(&mut self, file_name: String, data: Vec) -> Result<(), PrinterError> { println!("[{}] POST /server/files/upload {file_name} ({} bytes)", self.base.name, data.len()); Ok(()) } /// OVERRIDE: Moonraker's gcode-script endpoint, one line per call - same /// idea as `set_fan_speed`'s `SET_FAN_SPEED` call above, just with an /// arbitrary line instead of a hardcoded one. async fn send_gcode_line(&mut self, gcode_line: String) -> Result<(), PrinterError> { println!("[{}] POST /printer/gcode/script?script={gcode_line}", self.base.name); Ok(()) } }