From 3718b1a7525ee92fa8715263e6093530cdbe66e5 Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Thu, 24 Oct 2024 14:16:20 -0400 Subject: [PATCH] noop cityyyyy (#162) * noop cityyyyy add config knobs for: - progress of the print - state of the noop printer (idle, running, etc) - filaments - nozzle dia - loaded filament index * thx clippo * fix config example --- README.md | 5 ++++ src/bin/machine-api/config/mod.rs | 4 +-- src/bin/machine-api/config/noop.rs | 5 ++-- src/noop.rs | 47 ++++++++++++++++++++++++++---- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bd86be4..0d6b7c6 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,11 @@ slicer.config = "config/prusa/mk3.ini" [machines.nada] type = "Noop" +nozzle_diameter = 0.6 +state.state = "idle" +progress = 10.0 +[[machines.nada.filaments]] +material.type = "pla" [machines.neptune"] type = "Moonraker" diff --git a/src/bin/machine-api/config/mod.rs b/src/bin/machine-api/config/mod.rs index 8e34be0..c4215a5 100644 --- a/src/bin/machine-api/config/mod.rs +++ b/src/bin/machine-api/config/mod.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use machine_api::{bambu as crate_bambu, moonraker as crate_moonraker, usb as crate_usb}; +use machine_api::{bambu as crate_bambu, moonraker as crate_moonraker, noop as crate_noop, usb as crate_usb}; use serde::{Deserialize, Serialize}; mod bambu; @@ -18,7 +18,7 @@ pub struct Config { #[non_exhaustive] pub enum MachineConfig { Usb(crate_usb::Config), - Noop {}, + Noop(crate_noop::Config), Moonraker(crate_moonraker::Config), Bambu(crate_bambu::Config), } diff --git a/src/bin/machine-api/config/noop.rs b/src/bin/machine-api/config/noop.rs index 9eb50bc..e218971 100644 --- a/src/bin/machine-api/config/noop.rs +++ b/src/bin/machine-api/config/noop.rs @@ -12,11 +12,11 @@ impl Config { channel: tokio::sync::mpsc::Sender, machines: Arc>>>, ) -> Result<()> { - for (key, _config) in self + for (key, config) in self .machines .iter() .filter_map(|(key, config)| { - if let MachineConfig::Noop {} = config { + if let MachineConfig::Noop(config) = config { Some((key.clone(), config.clone())) } else { None @@ -28,6 +28,7 @@ impl Config { key.clone(), RwLock::new(Machine::new( noop::Noop::new( + config.clone(), MachineMakeModel { manufacturer: Some("Zoo Corporation".to_owned()), model: Some("Null Machine".to_owned()), diff --git a/src/noop.rs b/src/noop.rs index 45988dd..870d5c7 100644 --- a/src/noop.rs +++ b/src/noop.rs @@ -2,10 +2,11 @@ //! and do exactly nothing with it. use anyhow::Result; +use serde::{Deserialize, Serialize}; use crate::{ - Control as ControlTrait, GcodeControl as GcodeControlTrait, GcodeTemporaryFile, HardwareConfiguration, - MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType, + Control as ControlTrait, FdmHardwareConfiguration, Filament, GcodeControl as GcodeControlTrait, GcodeTemporaryFile, + HardwareConfiguration, MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType, SuspendControl as SuspendControlTrait, ThreeMfControl as ThreeMfControlTrait, ThreeMfTemporaryFile, Volume, }; @@ -14,6 +15,26 @@ pub struct Noop { make_model: MachineMakeModel, machine_type: MachineType, volume: Option, + config: Config, +} + +/// Configuration information for a Moonraker-based endpoint. +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct Config { + /// Extrusion hotend nozzle's diameter. + pub nozzle_diameter: f64, + + /// Available filaments. + pub filaments: Vec, + + /// Currently loaded filament, if possible to determine. + pub loaded_filament_idx: Option, + + /// state that the machine is in + pub state: MachineState, + + /// percentage through a print + pub progress: Option, } /// Nothing to see here! @@ -38,11 +59,17 @@ impl MachineInfoTrait for MachineInfo { impl Noop { /// Return a new no-op Machine. - pub fn new(make_model: MachineMakeModel, machine_type: MachineType, volume: Option) -> Self { + pub fn new( + config: Config, + make_model: MachineMakeModel, + machine_type: MachineType, + volume: Option, + ) -> Self { Self { make_model, volume, machine_type, + config, } } } @@ -72,15 +99,23 @@ impl ControlTrait for Noop { } async fn progress(&self) -> Result> { - Ok(None) + Ok(self.config.progress) } async fn state(&self) -> Result { - Ok(MachineState::Unknown) + Ok(self.config.state.clone()) } async fn hardware_configuration(&self) -> Result { - Ok(HardwareConfiguration::None) + let config = &self.config; + + Ok(HardwareConfiguration::Fdm { + config: FdmHardwareConfiguration { + filaments: config.filaments.clone(), + nozzle_diameter: config.nozzle_diameter, + loaded_filament_idx: config.loaded_filament_idx, + }, + }) } }