From 7351f350fcdde47d8d7d087e31917c4362354dff Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Thu, 17 Oct 2024 21:34:09 -0400 Subject: [PATCH 1/3] add progress --- src/any_machine.rs | 4 ++++ src/bambu/control.rs | 4 ++++ src/moonraker/control.rs | 4 ++++ src/noop.rs | 5 +++++ src/sync.rs | 3 +++ src/traits.rs | 5 +++++ src/usb/control.rs | 4 ++++ 7 files changed, 29 insertions(+) diff --git a/src/any_machine.rs b/src/any_machine.rs index d4d8973..08b782b 100644 --- a/src/any_machine.rs +++ b/src/any_machine.rs @@ -131,6 +131,10 @@ impl ControlTrait for AnyMachine { for_all!(|self, machine| { machine.healthy().await }) } + async fn progress(&self) -> Result> { + for_all!(|self, machine| { machine.progress().await }) + } + async fn state(&self) -> Result { for_all!(|self, machine| { machine.state().await }) } diff --git a/src/bambu/control.rs b/src/bambu/control.rs index 43c65f3..9db0334 100644 --- a/src/bambu/control.rs +++ b/src/bambu/control.rs @@ -71,6 +71,10 @@ impl ControlTrait for Bambu { Ok(()) } + async fn progress(&self) -> Result> { + Ok(None) + } + async fn healthy(&self) -> bool { let Ok(Some(status)) = self.client.get_status() else { return false; diff --git a/src/moonraker/control.rs b/src/moonraker/control.rs index c3e3822..4e341e6 100644 --- a/src/moonraker/control.rs +++ b/src/moonraker/control.rs @@ -66,6 +66,10 @@ impl ControlTrait for Client { self.client.info().await.is_ok() } + async fn progress(&self) -> Result> { + Ok(None) + } + async fn state(&self) -> Result { let status = self.client.status().await?; diff --git a/src/noop.rs b/src/noop.rs index e5d7b01..45988dd 100644 --- a/src/noop.rs +++ b/src/noop.rs @@ -71,6 +71,10 @@ impl ControlTrait for Noop { true } + async fn progress(&self) -> Result> { + Ok(None) + } + async fn state(&self) -> Result { Ok(MachineState::Unknown) } @@ -84,6 +88,7 @@ impl SuspendControlTrait for Noop { async fn pause(&mut self) -> Result<()> { Ok(()) } + async fn resume(&mut self) -> Result<()> { Ok(()) } diff --git a/src/sync.rs b/src/sync.rs index 4bad287..e2cdc20 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -45,6 +45,9 @@ where async fn state(&self) -> Result { self.0.lock().await.state().await } + async fn progress(&self) -> Result, Self::Error> { + self.0.lock().await.progress().await + } async fn hardware_configuration(&self) -> Result { self.0.lock().await.hardware_configuration().await } diff --git a/src/traits.rs b/src/traits.rs index b9ca9e6..8599a05 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -190,6 +190,11 @@ pub trait Control { /// Return the state of the printer. fn state(&self) -> impl Future>; + /// Return the percentage of completion of the job. This may return an + /// error when connecting to the machine, and it may return None if + /// there is no job running, or if there's no way to know the progress. + fn progress(&self) -> impl Future, Self::Error>>; + // TODO: look at merging MachineType and HardwareConfiguration; they // communicate VERY similar things conceptually. diff --git a/src/usb/control.rs b/src/usb/control.rs index dc94633..6ef2eac 100644 --- a/src/usb/control.rs +++ b/src/usb/control.rs @@ -137,6 +137,10 @@ impl ControlTrait for Usb { Ok(MachineState::Unknown) } + async fn progress(&self) -> Result> { + Ok(None) + } + async fn healthy(&self) -> bool { // TODO: fix this, do a gcode ping or something? true From e878745ead8a64d0379535be78ebf95a3c98441b Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Thu, 17 Oct 2024 21:41:22 -0400 Subject: [PATCH 2/3] add progress to the output --- src/server/endpoints.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/server/endpoints.rs b/src/server/endpoints.rs index bed973f..25f3c15 100644 --- a/src/server/endpoints.rs +++ b/src/server/endpoints.rs @@ -85,6 +85,9 @@ pub struct MachineInfoResponse { /// Information about how the Machine is currently configured. pub hardware_configuration: HardwareConfiguration, + /// Progress of the current print, if printing. + pub progress: Option, + /// Status of the printer -- be it printing, idle, or unreachable. This /// may dictate if a machine is capable of taking a new job. pub state: MachineState, @@ -100,6 +103,7 @@ impl MachineInfoResponse { pub(crate) async fn from_machine(id: &str, machine: &AnyMachine) -> anyhow::Result { let machine_info = machine.machine_info().await?; let hardware_configuration = machine.hardware_configuration().await?; + let progress = machine.progress().await?; Ok(MachineInfoResponse { id: id.to_owned(), @@ -107,6 +111,7 @@ impl MachineInfoResponse { machine_type: machine_info.machine_type(), max_part_volume: machine_info.max_part_volume(), hardware_configuration, + progress, state: machine.state().await?, extra: match machine { AnyMachine::Moonraker(_) => Some(ExtraMachineInfoResponse::Moonraker {}), From 41b972556ef70ce1c77e936f3404d4a93b892300 Mon Sep 17 00:00:00 2001 From: "Paul R. Tagliamonte" Date: Thu, 17 Oct 2024 21:43:23 -0400 Subject: [PATCH 3/3] progress --- openapi/api.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/openapi/api.json b/openapi/api.json index 464bc0b..2740a8a 100644 --- a/openapi/api.json +++ b/openapi/api.json @@ -358,6 +358,12 @@ "description": "Maximum part size that can be manufactured by this device. This may be some sort of theoretical upper bound, getting close to this limit seems like maybe a bad idea.\n\nThis may be `None` if the maximum size is not knowable by the Machine API.\n\nWhat \"close\" means is up to you!", "nullable": true }, + "progress": { + "description": "Progress of the current print, if printing.", + "format": "double", + "nullable": true, + "type": "number" + }, "state": { "allOf": [ {