Skip to content

Commit

Permalink
noop cityyyyy (#162)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
paultag authored Oct 24, 2024
1 parent c279bf8 commit 3718b1a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions src/bin/machine-api/config/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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),
}
5 changes: 3 additions & 2 deletions src/bin/machine-api/config/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ impl Config {
channel: tokio::sync::mpsc::Sender<String>,
machines: Arc<RwLock<HashMap<String, RwLock<Machine>>>>,
) -> 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
Expand All @@ -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()),
Expand Down
47 changes: 41 additions & 6 deletions src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -14,6 +15,26 @@ pub struct Noop {
make_model: MachineMakeModel,
machine_type: MachineType,
volume: Option<Volume>,
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<Filament>,

/// Currently loaded filament, if possible to determine.
pub loaded_filament_idx: Option<usize>,

/// state that the machine is in
pub state: MachineState,

/// percentage through a print
pub progress: Option<f64>,
}

/// Nothing to see here!
Expand All @@ -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<Volume>) -> Self {
pub fn new(
config: Config,
make_model: MachineMakeModel,
machine_type: MachineType,
volume: Option<Volume>,
) -> Self {
Self {
make_model,
volume,
machine_type,
config,
}
}
}
Expand Down Expand Up @@ -72,15 +99,23 @@ impl ControlTrait for Noop {
}

async fn progress(&self) -> Result<Option<f64>> {
Ok(None)
Ok(self.config.progress)
}

async fn state(&self) -> Result<MachineState> {
Ok(MachineState::Unknown)
Ok(self.config.state.clone())
}

async fn hardware_configuration(&self) -> Result<HardwareConfiguration> {
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,
},
})
}
}

Expand Down

0 comments on commit 3718b1a

Please sign in to comment.