Skip to content

Commit 3718b1a

Browse files
authored
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
1 parent c279bf8 commit 3718b1a

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ slicer.config = "config/prusa/mk3.ini"
1818

1919
[machines.nada]
2020
type = "Noop"
21+
nozzle_diameter = 0.6
22+
state.state = "idle"
23+
progress = 10.0
24+
[[machines.nada.filaments]]
25+
material.type = "pla"
2126

2227
[machines.neptune"]
2328
type = "Moonraker"

src/bin/machine-api/config/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use machine_api::{bambu as crate_bambu, moonraker as crate_moonraker, usb as crate_usb};
3+
use machine_api::{bambu as crate_bambu, moonraker as crate_moonraker, noop as crate_noop, usb as crate_usb};
44
use serde::{Deserialize, Serialize};
55

66
mod bambu;
@@ -18,7 +18,7 @@ pub struct Config {
1818
#[non_exhaustive]
1919
pub enum MachineConfig {
2020
Usb(crate_usb::Config),
21-
Noop {},
21+
Noop(crate_noop::Config),
2222
Moonraker(crate_moonraker::Config),
2323
Bambu(crate_bambu::Config),
2424
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ impl Config {
1212
channel: tokio::sync::mpsc::Sender<String>,
1313
machines: Arc<RwLock<HashMap<String, RwLock<Machine>>>>,
1414
) -> Result<()> {
15-
for (key, _config) in self
15+
for (key, config) in self
1616
.machines
1717
.iter()
1818
.filter_map(|(key, config)| {
19-
if let MachineConfig::Noop {} = config {
19+
if let MachineConfig::Noop(config) = config {
2020
Some((key.clone(), config.clone()))
2121
} else {
2222
None
@@ -28,6 +28,7 @@ impl Config {
2828
key.clone(),
2929
RwLock::new(Machine::new(
3030
noop::Noop::new(
31+
config.clone(),
3132
MachineMakeModel {
3233
manufacturer: Some("Zoo Corporation".to_owned()),
3334
model: Some("Null Machine".to_owned()),

src/noop.rs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
//! and do exactly nothing with it.
33
44
use anyhow::Result;
5+
use serde::{Deserialize, Serialize};
56

67
use crate::{
7-
Control as ControlTrait, GcodeControl as GcodeControlTrait, GcodeTemporaryFile, HardwareConfiguration,
8-
MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType,
8+
Control as ControlTrait, FdmHardwareConfiguration, Filament, GcodeControl as GcodeControlTrait, GcodeTemporaryFile,
9+
HardwareConfiguration, MachineInfo as MachineInfoTrait, MachineMakeModel, MachineState, MachineType,
910
SuspendControl as SuspendControlTrait, ThreeMfControl as ThreeMfControlTrait, ThreeMfTemporaryFile, Volume,
1011
};
1112

@@ -14,6 +15,26 @@ pub struct Noop {
1415
make_model: MachineMakeModel,
1516
machine_type: MachineType,
1617
volume: Option<Volume>,
18+
config: Config,
19+
}
20+
21+
/// Configuration information for a Moonraker-based endpoint.
22+
#[derive(Clone, Debug, Serialize, Deserialize)]
23+
pub struct Config {
24+
/// Extrusion hotend nozzle's diameter.
25+
pub nozzle_diameter: f64,
26+
27+
/// Available filaments.
28+
pub filaments: Vec<Filament>,
29+
30+
/// Currently loaded filament, if possible to determine.
31+
pub loaded_filament_idx: Option<usize>,
32+
33+
/// state that the machine is in
34+
pub state: MachineState,
35+
36+
/// percentage through a print
37+
pub progress: Option<f64>,
1738
}
1839

1940
/// Nothing to see here!
@@ -38,11 +59,17 @@ impl MachineInfoTrait for MachineInfo {
3859

3960
impl Noop {
4061
/// Return a new no-op Machine.
41-
pub fn new(make_model: MachineMakeModel, machine_type: MachineType, volume: Option<Volume>) -> Self {
62+
pub fn new(
63+
config: Config,
64+
make_model: MachineMakeModel,
65+
machine_type: MachineType,
66+
volume: Option<Volume>,
67+
) -> Self {
4268
Self {
4369
make_model,
4470
volume,
4571
machine_type,
72+
config,
4673
}
4774
}
4875
}
@@ -72,15 +99,23 @@ impl ControlTrait for Noop {
7299
}
73100

74101
async fn progress(&self) -> Result<Option<f64>> {
75-
Ok(None)
102+
Ok(self.config.progress)
76103
}
77104

78105
async fn state(&self) -> Result<MachineState> {
79-
Ok(MachineState::Unknown)
106+
Ok(self.config.state.clone())
80107
}
81108

82109
async fn hardware_configuration(&self) -> Result<HardwareConfiguration> {
83-
Ok(HardwareConfiguration::None)
110+
let config = &self.config;
111+
112+
Ok(HardwareConfiguration::Fdm {
113+
config: FdmHardwareConfiguration {
114+
filaments: config.filaments.clone(),
115+
nozzle_diameter: config.nozzle_diameter,
116+
loaded_filament_idx: config.loaded_filament_idx,
117+
},
118+
})
84119
}
85120
}
86121

0 commit comments

Comments
 (0)