Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noop cityyyyy #162

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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 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 @@
}

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

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