flashforge-python-api 1.5.0__py3-none-any.whl → 3.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flashforge/__init__.py +337 -233
- flashforge/_removed.py +65 -0
- flashforge/api/__init__.py +12 -18
- flashforge/api/constants/__init__.py +11 -11
- flashforge/api/constants/commands.py +18 -15
- flashforge/api/constants/endpoints.py +11 -11
- flashforge/api/misc/__init__.py +8 -8
- flashforge/api/network/__init__.py +11 -11
- flashforge/api/network/utils.py +71 -71
- flashforge/backends/__init__.py +80 -0
- flashforge/backends/connect.py +275 -0
- flashforge/backends/creator5_backend.py +191 -0
- flashforge/backends/dual_api_backend.py +170 -0
- flashforge/backends/dual_api_models.py +145 -0
- flashforge/backends/http_core.py +431 -0
- flashforge/backends/http_printer_backend.py +254 -0
- flashforge/backends/legacy_backend.py +436 -0
- flashforge/backends/printer_backend.py +217 -0
- flashforge/backends/types.py +125 -0
- flashforge/capabilities/__init__.py +98 -0
- flashforge/capabilities/models.py +67 -0
- flashforge/capabilities/palettes/__init__.py +28 -0
- flashforge/capabilities/palettes/ad5x_palette.py +70 -0
- flashforge/capabilities/palettes/creator5_palette.py +78 -0
- flashforge/capabilities/palettes/palette.py +54 -0
- flashforge/{api/controls/creator5_palette.py → capabilities/palettes/palette_snap.py} +226 -258
- flashforge/capabilities/printer_capabilities.py +145 -0
- flashforge/capabilities/registry.py +125 -0
- flashforge/capabilities/resolve_model.py +61 -0
- flashforge/discovery/__init__.py +39 -39
- flashforge/discovery/discovery.py +730 -763
- flashforge/exceptions.py +90 -51
- flashforge/models/__init__.py +52 -55
- flashforge/models/machine_info.py +540 -543
- flashforge/{api/controls/info.py → models/machine_info_parser.py} +35 -242
- flashforge/models/responses.py +119 -254
- flashforge/status/__init__.py +43 -0
- flashforge/status/printer_snapshot.py +396 -0
- flashforge/tcp/__init__.py +55 -54
- flashforge/tcp/a3_client.py +427 -427
- flashforge/tcp/a4_client.py +304 -304
- flashforge/tcp/ff_client.py +609 -590
- flashforge/tcp/gcode/__init__.py +15 -13
- flashforge/tcp/gcode/a3_gcode_controller.py +109 -109
- flashforge/tcp/gcode/gcode_controller.py +292 -308
- flashforge/tcp/gcode/gcodes.py +81 -99
- flashforge/tcp/gcode/legacy_gcode_controller.py +56 -0
- flashforge/tcp/parsers/__init__.py +27 -27
- flashforge/tcp/parsers/endstop_status.py +248 -248
- flashforge/tcp/parsers/location_info.py +83 -83
- flashforge/tcp/parsers/print_status.py +180 -180
- flashforge/tcp/parsers/printer_info.py +146 -146
- flashforge/tcp/parsers/temp_info.py +218 -218
- flashforge/tcp/parsers/thumbnail_info.py +274 -274
- flashforge/tcp/tcp_client.py +52 -12
- flashforge/threemf/__init__.py +40 -0
- flashforge/threemf/parser.py +560 -0
- flashforge/threemf/warnings.py +58 -0
- flashforge_python_api-3.0.0.dist-info/METADATA +184 -0
- flashforge_python_api-3.0.0.dist-info/RECORD +69 -0
- {flashforge_python_api-1.5.0.dist-info → flashforge_python_api-3.0.0.dist-info}/WHEEL +1 -1
- {flashforge_python_api-1.5.0.dist-info → flashforge_python_api-3.0.0.dist-info}/licenses/LICENSE +21 -21
- flashforge/api/controls/__init__.py +0 -17
- flashforge/api/controls/control.py +0 -413
- flashforge/api/controls/files.py +0 -210
- flashforge/api/controls/job_control.py +0 -880
- flashforge/api/controls/temp_control.py +0 -309
- flashforge/client.py +0 -609
- flashforge_python_api-1.5.0.dist-info/METADATA +0 -152
- flashforge_python_api-1.5.0.dist-info/RECORD +0 -49
- {flashforge_python_api-1.5.0.dist-info → flashforge_python_api-3.0.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,308 +1,292 @@
|
|
|
1
|
-
"""
|
|
2
|
-
G-code controller for FlashForge 3D printers.
|
|
3
|
-
|
|
4
|
-
This module provides high-level G-code command methods that build upon
|
|
5
|
-
the basic TCP communication provided by FlashForgeTcpClient.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import asyncio
|
|
9
|
-
import logging
|
|
10
|
-
from typing import TYPE_CHECKING, Protocol
|
|
11
|
-
|
|
12
|
-
from .gcodes import GCodes
|
|
13
|
-
|
|
14
|
-
if TYPE_CHECKING:
|
|
15
|
-
from ..parsers.temp_info import TempInfo
|
|
16
|
-
|
|
17
|
-
logger = logging.getLogger(__name__)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class SupportsGCodeClient(Protocol):
|
|
21
|
-
"""Client protocol implemented by both the legacy and Adventurer 3 TCP clients."""
|
|
22
|
-
|
|
23
|
-
async def send_cmd_ok(self, cmd: str) -> bool: ...
|
|
24
|
-
|
|
25
|
-
async def get_temp_info(self) -> "TempInfo | None": ...
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class GCodeController:
|
|
29
|
-
"""
|
|
30
|
-
Controller for sending specific G-code commands to FlashForge printers.
|
|
31
|
-
|
|
32
|
-
This class provides convenient methods for common printer operations
|
|
33
|
-
like LED control, job management, movement, and temperature control.
|
|
34
|
-
"""
|
|
35
|
-
|
|
36
|
-
def __init__(self, client: SupportsGCodeClient) -> None:
|
|
37
|
-
"""
|
|
38
|
-
Initialize the G-code controller.
|
|
39
|
-
|
|
40
|
-
Args:
|
|
41
|
-
client: The FlashForgeClient instance for sending commands
|
|
42
|
-
"""
|
|
43
|
-
self.client = client
|
|
44
|
-
|
|
45
|
-
async def led_on(self) -> bool:
|
|
46
|
-
"""
|
|
47
|
-
Turn the printer's LED lights on.
|
|
48
|
-
|
|
49
|
-
Returns:
|
|
50
|
-
True if the command was successful, False otherwise
|
|
51
|
-
"""
|
|
52
|
-
return await self.client.send_cmd_ok(GCodes.CMD_LED_ON)
|
|
53
|
-
|
|
54
|
-
async def led_off(self) -> bool:
|
|
55
|
-
"""
|
|
56
|
-
Turn the printer's LED lights off.
|
|
57
|
-
|
|
58
|
-
Returns:
|
|
59
|
-
True if the command was successful, False otherwise
|
|
60
|
-
"""
|
|
61
|
-
return await self.client.send_cmd_ok(GCodes.CMD_LED_OFF)
|
|
62
|
-
|
|
63
|
-
async def pause_job(self) -> bool:
|
|
64
|
-
"""
|
|
65
|
-
Pause the current print job.
|
|
66
|
-
|
|
67
|
-
Returns:
|
|
68
|
-
True if the command was successful, False otherwise
|
|
69
|
-
"""
|
|
70
|
-
return await self.client.send_cmd_ok(GCodes.CMD_PAUSE_PRINT)
|
|
71
|
-
|
|
72
|
-
async def resume_job(self) -> bool:
|
|
73
|
-
"""
|
|
74
|
-
Resume a paused print job.
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
True if the command was successful, False otherwise
|
|
78
|
-
"""
|
|
79
|
-
return await self.client.send_cmd_ok(GCodes.CMD_RESUME_PRINT)
|
|
80
|
-
|
|
81
|
-
async def stop_job(self) -> bool:
|
|
82
|
-
"""
|
|
83
|
-
Stop the current print job.
|
|
84
|
-
|
|
85
|
-
Returns:
|
|
86
|
-
True if the command was successful, False otherwise
|
|
87
|
-
"""
|
|
88
|
-
return await self.client.send_cmd_ok(GCodes.CMD_STOP_PRINT)
|
|
89
|
-
|
|
90
|
-
async def start_job(self, filename: str) -> bool:
|
|
91
|
-
"""
|
|
92
|
-
Start a print job from a file stored on the printer.
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
filename: The name of the file to print (typically without path)
|
|
96
|
-
|
|
97
|
-
Returns:
|
|
98
|
-
True if the command was successful, False otherwise
|
|
99
|
-
"""
|
|
100
|
-
cmd = GCodes.CMD_START_PRINT.replace("%%filename%%", filename)
|
|
101
|
-
return await self.client.send_cmd_ok(cmd)
|
|
102
|
-
|
|
103
|
-
async def home(self) -> bool:
|
|
104
|
-
"""
|
|
105
|
-
Home all axes (X, Y, Z) of the printer.
|
|
106
|
-
|
|
107
|
-
Returns:
|
|
108
|
-
True if the command was successful, False otherwise
|
|
109
|
-
"""
|
|
110
|
-
return await self.client.send_cmd_ok(GCodes.CMD_HOME_AXES)
|
|
111
|
-
|
|
112
|
-
async def rapid_home(self) -> bool:
|
|
113
|
-
"""
|
|
114
|
-
Perform a rapid homing of all axes.
|
|
115
|
-
|
|
116
|
-
Note: This uses the same command as regular homing in the current implementation.
|
|
117
|
-
|
|
118
|
-
Returns:
|
|
119
|
-
True if the command was successful, False otherwise
|
|
120
|
-
"""
|
|
121
|
-
# In the TypeScript implementation, this is the same as home()
|
|
122
|
-
return await self.home()
|
|
123
|
-
|
|
124
|
-
async def move(self, x: float, y: float, z: float, feedrate: int) -> bool:
|
|
125
|
-
"""
|
|
126
|
-
Move the extruder to a specified X, Y, Z position.
|
|
127
|
-
|
|
128
|
-
Args:
|
|
129
|
-
x: The target X coordinate
|
|
130
|
-
y: The target Y coordinate
|
|
131
|
-
z: The target Z coordinate
|
|
132
|
-
feedrate: The feedrate for the movement in mm/min
|
|
133
|
-
|
|
134
|
-
Returns:
|
|
135
|
-
True if the command was successful, False otherwise
|
|
136
|
-
"""
|
|
137
|
-
cmd = f"~G1 X{x} Y{y} Z{z} F{feedrate}"
|
|
138
|
-
return await self.client.send_cmd_ok(cmd)
|
|
139
|
-
|
|
140
|
-
async def move_extruder(self, x: float, y: float, feedrate: int) -> bool:
|
|
141
|
-
"""
|
|
142
|
-
Move the extruder to a specified X, Y position.
|
|
143
|
-
|
|
144
|
-
Args:
|
|
145
|
-
x: The target X coordinate
|
|
146
|
-
y: The target Y coordinate
|
|
147
|
-
feedrate: The feedrate for the movement in mm/min
|
|
148
|
-
|
|
149
|
-
Returns:
|
|
150
|
-
True if the command was successful, False otherwise
|
|
151
|
-
"""
|
|
152
|
-
cmd = f"~G1 X{x} Y{y} F{feedrate}"
|
|
153
|
-
return await self.client.send_cmd_ok(cmd)
|
|
154
|
-
|
|
155
|
-
async def extrude(self, length: float, feedrate: int = 450) -> bool:
|
|
156
|
-
"""
|
|
157
|
-
Command the extruder to extrude a specific length of filament.
|
|
158
|
-
|
|
159
|
-
Args:
|
|
160
|
-
length: The length of filament to extrude in millimeters
|
|
161
|
-
feedrate: The feedrate for extrusion in mm/min (default: 450)
|
|
162
|
-
|
|
163
|
-
Returns:
|
|
164
|
-
True if the command was successful, False otherwise
|
|
165
|
-
"""
|
|
166
|
-
cmd = f"~G1 E{length} F{feedrate}"
|
|
167
|
-
return await self.client.send_cmd_ok(cmd)
|
|
168
|
-
|
|
169
|
-
async def set_extruder_temp(self, temp: int
|
|
170
|
-
"""
|
|
171
|
-
Set the target temperature for the extruder.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
start_time = asyncio.get_event_loop().time()
|
|
294
|
-
timeout_time = start_time + timeout
|
|
295
|
-
|
|
296
|
-
while asyncio.get_event_loop().time() < timeout_time:
|
|
297
|
-
temp_info = await self.client.get_temp_info()
|
|
298
|
-
if temp_info:
|
|
299
|
-
extruder_temp = temp_info.get_extruder_temp()
|
|
300
|
-
if extruder_temp:
|
|
301
|
-
current_temp = extruder_temp.get_current()
|
|
302
|
-
if abs(current_temp - target_temp) <= 2: # Within 2°C tolerance
|
|
303
|
-
return True
|
|
304
|
-
|
|
305
|
-
await asyncio.sleep(5) # Check every 5 seconds
|
|
306
|
-
|
|
307
|
-
logger.warning(f"Timeout waiting for extruder temperature to reach {target_temp}°C")
|
|
308
|
-
return False
|
|
1
|
+
"""
|
|
2
|
+
G-code controller for FlashForge 3D printers.
|
|
3
|
+
|
|
4
|
+
This module provides high-level G-code command methods that build upon
|
|
5
|
+
the basic TCP communication provided by FlashForgeTcpClient.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import asyncio
|
|
9
|
+
import logging
|
|
10
|
+
from typing import TYPE_CHECKING, Protocol
|
|
11
|
+
|
|
12
|
+
from .gcodes import GCodes
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from ..parsers.temp_info import TempInfo
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SupportsGCodeClient(Protocol):
|
|
21
|
+
"""Client protocol implemented by both the legacy and Adventurer 3 TCP clients."""
|
|
22
|
+
|
|
23
|
+
async def send_cmd_ok(self, cmd: str) -> bool: ...
|
|
24
|
+
|
|
25
|
+
async def get_temp_info(self) -> "TempInfo | None": ...
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class GCodeController:
|
|
29
|
+
"""
|
|
30
|
+
Controller for sending specific G-code commands to FlashForge printers.
|
|
31
|
+
|
|
32
|
+
This class provides convenient methods for common printer operations
|
|
33
|
+
like LED control, job management, movement, and temperature control.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(self, client: SupportsGCodeClient) -> None:
|
|
37
|
+
"""
|
|
38
|
+
Initialize the G-code controller.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
client: The FlashForgeClient instance for sending commands
|
|
42
|
+
"""
|
|
43
|
+
self.client = client
|
|
44
|
+
|
|
45
|
+
async def led_on(self) -> bool:
|
|
46
|
+
"""
|
|
47
|
+
Turn the printer's LED lights on.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
True if the command was successful, False otherwise
|
|
51
|
+
"""
|
|
52
|
+
return await self.client.send_cmd_ok(GCodes.CMD_LED_ON)
|
|
53
|
+
|
|
54
|
+
async def led_off(self) -> bool:
|
|
55
|
+
"""
|
|
56
|
+
Turn the printer's LED lights off.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
True if the command was successful, False otherwise
|
|
60
|
+
"""
|
|
61
|
+
return await self.client.send_cmd_ok(GCodes.CMD_LED_OFF)
|
|
62
|
+
|
|
63
|
+
async def pause_job(self) -> bool:
|
|
64
|
+
"""
|
|
65
|
+
Pause the current print job.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
True if the command was successful, False otherwise
|
|
69
|
+
"""
|
|
70
|
+
return await self.client.send_cmd_ok(GCodes.CMD_PAUSE_PRINT)
|
|
71
|
+
|
|
72
|
+
async def resume_job(self) -> bool:
|
|
73
|
+
"""
|
|
74
|
+
Resume a paused print job.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
True if the command was successful, False otherwise
|
|
78
|
+
"""
|
|
79
|
+
return await self.client.send_cmd_ok(GCodes.CMD_RESUME_PRINT)
|
|
80
|
+
|
|
81
|
+
async def stop_job(self) -> bool:
|
|
82
|
+
"""
|
|
83
|
+
Stop the current print job.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
True if the command was successful, False otherwise
|
|
87
|
+
"""
|
|
88
|
+
return await self.client.send_cmd_ok(GCodes.CMD_STOP_PRINT)
|
|
89
|
+
|
|
90
|
+
async def start_job(self, filename: str) -> bool:
|
|
91
|
+
"""
|
|
92
|
+
Start a print job from a file stored on the printer.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
filename: The name of the file to print (typically without path)
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
True if the command was successful, False otherwise
|
|
99
|
+
"""
|
|
100
|
+
cmd = GCodes.CMD_START_PRINT.replace("%%filename%%", filename)
|
|
101
|
+
return await self.client.send_cmd_ok(cmd)
|
|
102
|
+
|
|
103
|
+
async def home(self) -> bool:
|
|
104
|
+
"""
|
|
105
|
+
Home all axes (X, Y, Z) of the printer.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
True if the command was successful, False otherwise
|
|
109
|
+
"""
|
|
110
|
+
return await self.client.send_cmd_ok(GCodes.CMD_HOME_AXES)
|
|
111
|
+
|
|
112
|
+
async def rapid_home(self) -> bool:
|
|
113
|
+
"""
|
|
114
|
+
Perform a rapid homing of all axes.
|
|
115
|
+
|
|
116
|
+
Note: This uses the same command as regular homing in the current implementation.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
True if the command was successful, False otherwise
|
|
120
|
+
"""
|
|
121
|
+
# In the TypeScript implementation, this is the same as home()
|
|
122
|
+
return await self.home()
|
|
123
|
+
|
|
124
|
+
async def move(self, x: float, y: float, z: float, feedrate: int) -> bool:
|
|
125
|
+
"""
|
|
126
|
+
Move the extruder to a specified X, Y, Z position.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
x: The target X coordinate
|
|
130
|
+
y: The target Y coordinate
|
|
131
|
+
z: The target Z coordinate
|
|
132
|
+
feedrate: The feedrate for the movement in mm/min
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
True if the command was successful, False otherwise
|
|
136
|
+
"""
|
|
137
|
+
cmd = f"~G1 X{x} Y{y} Z{z} F{feedrate}"
|
|
138
|
+
return await self.client.send_cmd_ok(cmd)
|
|
139
|
+
|
|
140
|
+
async def move_extruder(self, x: float, y: float, feedrate: int) -> bool:
|
|
141
|
+
"""
|
|
142
|
+
Move the extruder to a specified X, Y position.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
x: The target X coordinate
|
|
146
|
+
y: The target Y coordinate
|
|
147
|
+
feedrate: The feedrate for the movement in mm/min
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
True if the command was successful, False otherwise
|
|
151
|
+
"""
|
|
152
|
+
cmd = f"~G1 X{x} Y{y} F{feedrate}"
|
|
153
|
+
return await self.client.send_cmd_ok(cmd)
|
|
154
|
+
|
|
155
|
+
async def extrude(self, length: float, feedrate: int = 450) -> bool:
|
|
156
|
+
"""
|
|
157
|
+
Command the extruder to extrude a specific length of filament.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
length: The length of filament to extrude in millimeters
|
|
161
|
+
feedrate: The feedrate for extrusion in mm/min (default: 450)
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
True if the command was successful, False otherwise
|
|
165
|
+
"""
|
|
166
|
+
cmd = f"~G1 E{length} F{feedrate}"
|
|
167
|
+
return await self.client.send_cmd_ok(cmd)
|
|
168
|
+
|
|
169
|
+
async def set_extruder_temp(self, temp: int) -> bool:
|
|
170
|
+
"""
|
|
171
|
+
Set the target temperature for the extruder (M104).
|
|
172
|
+
|
|
173
|
+
To wait for the temperature, call ``wait_for_extruder_temp`` afterwards.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
temp: The target temperature in Celsius
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
True if the command was successful, False otherwise
|
|
180
|
+
"""
|
|
181
|
+
return await self.client.send_cmd_ok(f"~M104 S{temp}")
|
|
182
|
+
|
|
183
|
+
async def set_bed_temp(self, temp: int) -> bool:
|
|
184
|
+
"""
|
|
185
|
+
Set the target temperature for the print bed (M140).
|
|
186
|
+
|
|
187
|
+
To wait for the temperature, call ``wait_for_bed_temp`` afterwards.
|
|
188
|
+
|
|
189
|
+
Args:
|
|
190
|
+
temp: The target temperature in Celsius
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
True if the command was successful, False otherwise
|
|
194
|
+
"""
|
|
195
|
+
return await self.client.send_cmd_ok(f"~M140 S{temp}")
|
|
196
|
+
|
|
197
|
+
async def cancel_extruder_temp(self) -> bool:
|
|
198
|
+
"""
|
|
199
|
+
Cancel extruder heating and set its target temperature to 0.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
True if the command was successful, False otherwise
|
|
203
|
+
"""
|
|
204
|
+
cmd = "~M104 S0"
|
|
205
|
+
ok = await self.client.send_cmd_ok(cmd)
|
|
206
|
+
return ok
|
|
207
|
+
|
|
208
|
+
async def cancel_bed_temp(self, wait_for_cool: bool = False) -> bool:
|
|
209
|
+
"""
|
|
210
|
+
Cancel print bed heating and set its target temperature to 0.
|
|
211
|
+
|
|
212
|
+
Args:
|
|
213
|
+
wait_for_cool: If True, wait for the bed to cool down after canceling
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
True if the command was successful, False otherwise
|
|
217
|
+
"""
|
|
218
|
+
cmd = "~M140 S0"
|
|
219
|
+
ok = await self.client.send_cmd_ok(cmd)
|
|
220
|
+
if not ok:
|
|
221
|
+
return False
|
|
222
|
+
|
|
223
|
+
if wait_for_cool:
|
|
224
|
+
# Wait for bed to cool down to a reasonable temperature
|
|
225
|
+
return await self.wait_for_bed_temp(40, cooling=True)
|
|
226
|
+
|
|
227
|
+
return True
|
|
228
|
+
|
|
229
|
+
async def wait_for_bed_temp(
|
|
230
|
+
self, target_temp: int, cooling: bool = False, timeout: int = 600
|
|
231
|
+
) -> bool:
|
|
232
|
+
"""
|
|
233
|
+
Wait for the bed temperature to reach the target.
|
|
234
|
+
|
|
235
|
+
Args:
|
|
236
|
+
target_temp: The target temperature to wait for
|
|
237
|
+
cooling: If True, wait for temperature to drop below target; otherwise wait to reach target
|
|
238
|
+
timeout: Maximum time to wait in seconds (default: 600)
|
|
239
|
+
|
|
240
|
+
Returns:
|
|
241
|
+
True if target temperature was reached, False on timeout or error
|
|
242
|
+
"""
|
|
243
|
+
start_time = asyncio.get_event_loop().time()
|
|
244
|
+
timeout_time = start_time + timeout
|
|
245
|
+
|
|
246
|
+
while asyncio.get_event_loop().time() < timeout_time:
|
|
247
|
+
temp_info = await self.client.get_temp_info()
|
|
248
|
+
if temp_info:
|
|
249
|
+
bed_temp = temp_info.get_bed_temp()
|
|
250
|
+
if bed_temp:
|
|
251
|
+
current_temp = bed_temp.get_current()
|
|
252
|
+
if cooling:
|
|
253
|
+
if current_temp <= target_temp:
|
|
254
|
+
return True
|
|
255
|
+
else:
|
|
256
|
+
if abs(current_temp - target_temp) <= 2: # Within 2°C tolerance
|
|
257
|
+
return True
|
|
258
|
+
|
|
259
|
+
await asyncio.sleep(5) # Check every 5 seconds
|
|
260
|
+
|
|
261
|
+
logger.warning(
|
|
262
|
+
f"Timeout waiting for bed temperature {'cooling to' if cooling else 'heating to'} {target_temp}°C"
|
|
263
|
+
)
|
|
264
|
+
return False
|
|
265
|
+
|
|
266
|
+
async def wait_for_extruder_temp(self, target_temp: int, timeout: int = 600) -> bool:
|
|
267
|
+
"""
|
|
268
|
+
Wait for the extruder temperature to reach the target.
|
|
269
|
+
|
|
270
|
+
Args:
|
|
271
|
+
target_temp: The target temperature to wait for
|
|
272
|
+
timeout: Maximum time to wait in seconds (default: 600)
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
True if target temperature was reached, False on timeout or error
|
|
276
|
+
"""
|
|
277
|
+
start_time = asyncio.get_event_loop().time()
|
|
278
|
+
timeout_time = start_time + timeout
|
|
279
|
+
|
|
280
|
+
while asyncio.get_event_loop().time() < timeout_time:
|
|
281
|
+
temp_info = await self.client.get_temp_info()
|
|
282
|
+
if temp_info:
|
|
283
|
+
extruder_temp = temp_info.get_extruder_temp()
|
|
284
|
+
if extruder_temp:
|
|
285
|
+
current_temp = extruder_temp.get_current()
|
|
286
|
+
if abs(current_temp - target_temp) <= 2: # Within 2°C tolerance
|
|
287
|
+
return True
|
|
288
|
+
|
|
289
|
+
await asyncio.sleep(5) # Check every 5 seconds
|
|
290
|
+
|
|
291
|
+
logger.warning(f"Timeout waiting for extruder temperature to reach {target_temp}°C")
|
|
292
|
+
return False
|