1
1
use anyhow:: Result ;
2
+ use serde:: { Deserialize , Serialize } ;
2
3
use std:: path:: Path ;
3
4
4
5
use super :: PrintManager ;
5
6
7
+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
8
+ pub struct InfoResponse {
9
+ pub state : String ,
10
+ pub state_message : String ,
11
+ pub hostname : String ,
12
+ pub software_version : String ,
13
+ pub cpu_info : String ,
14
+ }
15
+
16
+ #[ derive( Clone , Debug , Deserialize , Serialize ) ]
17
+ struct InfoResponseWrapper {
18
+ pub result : InfoResponse ,
19
+ }
20
+
6
21
impl PrintManager {
7
22
/// Print an uploaded file.
8
23
pub async fn print ( & self , file_name : & Path ) -> Result < ( ) > {
@@ -16,6 +31,38 @@ impl PrintManager {
16
31
Ok ( ( ) )
17
32
}
18
33
34
+ /// This endpoint will immediately halt the printer and put it in a
35
+ /// "shutdown" state. It should be used to implement an "emergency stop"
36
+ /// button and also used if a user enters M112(emergency stop) via a
37
+ /// console.
38
+ pub async fn emergency_stop ( & self ) -> Result < ( ) > {
39
+ let client = reqwest:: Client :: new ( ) ;
40
+ client
41
+ . post ( format ! ( "{}/printer/emergency_stop" , self . url_base) )
42
+ . send ( )
43
+ . await ?;
44
+ Ok ( ( ) )
45
+ }
46
+
47
+ /// Get information regarding the processor and its state.
48
+ pub async fn info ( & self ) -> Result < InfoResponse > {
49
+ let client = reqwest:: Client :: new ( ) ;
50
+ let resp: InfoResponseWrapper = client
51
+ . post ( format ! ( "{}/printer/info" , self . url_base) )
52
+ . send ( )
53
+ . await ?
54
+ . json ( )
55
+ . await ?;
56
+ Ok ( resp. result )
57
+ }
58
+
59
+ /// Restart the printer (shut down and reboot).
60
+ pub async fn restart ( & self ) -> Result < ( ) > {
61
+ let client = reqwest:: Client :: new ( ) ;
62
+ client. post ( format ! ( "{}/printer/restart" , self . url_base) ) . send ( ) . await ?;
63
+ Ok ( ( ) )
64
+ }
65
+
19
66
/// Cancel a print job.
20
67
pub async fn cancel_print ( & self ) -> Result < ( ) > {
21
68
let client = reqwest:: Client :: new ( ) ;
@@ -25,4 +72,24 @@ impl PrintManager {
25
72
. await ?;
26
73
Ok ( ( ) )
27
74
}
75
+
76
+ /// Pause a print job.
77
+ pub async fn pause_print ( & self ) -> Result < ( ) > {
78
+ let client = reqwest:: Client :: new ( ) ;
79
+ client
80
+ . post ( format ! ( "{}/printer/print/pause" , self . url_base) )
81
+ . send ( )
82
+ . await ?;
83
+ Ok ( ( ) )
84
+ }
85
+
86
+ /// Resume a print job.
87
+ pub async fn resume_print ( & self ) -> Result < ( ) > {
88
+ let client = reqwest:: Client :: new ( ) ;
89
+ client
90
+ . post ( format ! ( "{}/printer/print/resume" , self . url_base) )
91
+ . send ( )
92
+ . await ?;
93
+ Ok ( ( ) )
94
+ }
28
95
}
0 commit comments