Skip to content

Commit

Permalink
noop cityyyyy
Browse files Browse the repository at this point in the history
add config knobs for:
 - progress of the print
 - state of the noop printer (idle, running, etc)
 - filaments
 - nozzle dia
 - loaded filament index
  • Loading branch information
paultag committed Oct 24, 2024
1 parent c279bf8 commit f490c64
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
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

Check warning on line 15 in src/bin/machine-api/config/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/machine-api/config/noop.rs#L15

Added line #L15 was not covered by tests
.machines
.iter()
.filter_map(|(key, config)| {
if let MachineConfig::Noop {} = config {
if let MachineConfig::Noop(config) = config {

Check warning on line 19 in src/bin/machine-api/config/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/machine-api/config/noop.rs#L19

Added line #L19 was not covered by tests
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(),

Check warning on line 31 in src/bin/machine-api/config/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/machine-api/config/noop.rs#L31

Added line #L31 was not covered by tests
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)]

Check warning on line 22 in src/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/noop.rs#L22

Added line #L22 was not covered by tests
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 {

Check warning on line 67 in src/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/noop.rs#L62-L67

Added lines #L62 - L67 were not covered by tests
Self {
make_model,
volume,
machine_type,
config,

Check warning on line 72 in src/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/noop.rs#L72

Added line #L72 was not covered by tests
}
}
}
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.clone())

Check failure on line 102 in src/noop.rs

View workflow job for this annotation

GitHub Actions / cargo clippy

using `clone` on type `Option<f64>` which implements the `Copy` trait

Check warning on line 102 in src/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/noop.rs#L102

Added line #L102 was not covered by tests
}

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

Check warning on line 106 in src/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/noop.rs#L106

Added line #L106 was not covered by tests
}

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,
},
})

Check warning on line 118 in src/noop.rs

View check run for this annotation

Codecov / codecov/patch

src/noop.rs#L110-L118

Added lines #L110 - L118 were not covered by tests
}
}

Expand Down

0 comments on commit f490c64

Please sign in to comment.