-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add in MachineState to the Control trait, HTTP Endpoint (#118)
This is a first step as we start to chip away on #68 slash #49 and others. This will add a standard part of our "Control" trait to check on the state of a printer -- is the printer running? idle? paused mid-print? Broken? I implemented this for Moonraker (since I was able to test it), and stubbed in Unknown elsewhere. USB is doable here -- and I think we can do Bambu, but that may wait until I get into the office to play with it myself.
- Loading branch information
Showing
12 changed files
with
222 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
mod metrics; | ||
mod print; | ||
mod status; | ||
mod upload; | ||
|
||
use anyhow::Result; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::Client; | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
pub struct VirtualSdcard { | ||
pub progress: f64, | ||
pub file_position: f64, | ||
pub is_active: bool, | ||
pub file_path: Option<String>, | ||
pub file_size: f64, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
pub struct Webhooks { | ||
pub state: String, | ||
pub state_message: String, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
pub struct PrintStats { | ||
pub print_duration: f64, | ||
pub total_duration: f64, | ||
pub filament_used: f64, | ||
pub filename: String, | ||
pub state: String, | ||
pub message: String, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
pub struct Status { | ||
pub virtual_sdcard: VirtualSdcard, | ||
pub webhooks: Webhooks, | ||
pub print_stats: PrintStats, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
struct QueryResponse { | ||
status: Status, | ||
eventtime: f64, | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] | ||
struct QueryResponseWrapper { | ||
result: QueryResponse, | ||
} | ||
|
||
impl Client { | ||
/// Print an uploaded file. | ||
pub async fn status(&self) -> Result<Status> { | ||
tracing::debug!(base = self.url_base, "requesting status"); | ||
let client = reqwest::Client::new(); | ||
|
||
let resp: QueryResponseWrapper = client | ||
.get(format!( | ||
"{}/printer/objects/query?webhooks&virtual_sdcard&print_stats", | ||
self.url_base | ||
)) | ||
.send() | ||
.await? | ||
.json() | ||
.await?; | ||
|
||
Ok(resp.result.status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters