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
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The HTTP-only family: Creator 5 and Creator 5 Pro.
|
|
3
|
+
|
|
4
|
+
These printers run no TCP server, so this backend has no TCP code at all. It is not a
|
|
5
|
+
subclass of the dual-API family. Temperatures go over ``temperatureCtl_cmd`` with a
|
|
6
|
+
4-entry ``nozzles`` array. Material matching happens at print start (``/printGcode``).
|
|
7
|
+
Only the Creator 5 Pro has a chamber heater.
|
|
8
|
+
|
|
9
|
+
The Creator 5 rules come from the API docs and the emulator. They are not yet confirmed on
|
|
10
|
+
real hardware by the maintainers (``capabilities.hardware_verified`` is False).
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from typing import Any
|
|
16
|
+
|
|
17
|
+
from ..api.constants.commands import Commands
|
|
18
|
+
from ..capabilities.models import BackendFamily, PrinterModelId
|
|
19
|
+
from ..exceptions import InvalidParameterError
|
|
20
|
+
from ..models.machine_info import FFMachineInfo
|
|
21
|
+
from .http_core import HttpCore
|
|
22
|
+
from .http_printer_backend import (
|
|
23
|
+
HttpPrinterBackend,
|
|
24
|
+
encode_material_mappings,
|
|
25
|
+
validate_material_mappings,
|
|
26
|
+
)
|
|
27
|
+
from .types import LocalJobParams, UploadJobParams
|
|
28
|
+
|
|
29
|
+
#: ``temperatureCtl_cmd``: leave this heater unchanged.
|
|
30
|
+
TEMP_NO_CHANGE = -200
|
|
31
|
+
#: ``temperatureCtl_cmd``: turn a scalar heater (platform, chamber) off.
|
|
32
|
+
TEMP_OFF = -100
|
|
33
|
+
#: Turns a tool off inside ``nozzles``. The firmware treats only a literal 0 as off; it
|
|
34
|
+
#: ignores -100 there and the tool keeps heating.
|
|
35
|
+
NOZZLE_OFF = 0
|
|
36
|
+
#: The firmware ignores the ``nozzles`` array unless it has exactly 4 entries.
|
|
37
|
+
NOZZLE_COUNT = 4
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Creator5Backend(HttpPrinterBackend):
|
|
41
|
+
"""Creator 5 and Creator 5 Pro."""
|
|
42
|
+
|
|
43
|
+
family = BackendFamily.HTTP_ONLY
|
|
44
|
+
|
|
45
|
+
def __init__(
|
|
46
|
+
self,
|
|
47
|
+
model: PrinterModelId,
|
|
48
|
+
http: HttpCore,
|
|
49
|
+
info: FFMachineInfo,
|
|
50
|
+
) -> None:
|
|
51
|
+
if model not in (PrinterModelId.CREATOR_5, PrinterModelId.CREATOR_5_PRO):
|
|
52
|
+
raise ValueError(f"{model} is not a Creator 5 model")
|
|
53
|
+
super().__init__(model, http, info)
|
|
54
|
+
|
|
55
|
+
# ---- Temperatures --------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
async def _send_temp(
|
|
58
|
+
self,
|
|
59
|
+
*,
|
|
60
|
+
platform: int | None = None,
|
|
61
|
+
chamber: int | None = None,
|
|
62
|
+
nozzles: list[int] | None = None,
|
|
63
|
+
) -> bool:
|
|
64
|
+
"""
|
|
65
|
+
Sends ``temperatureCtl_cmd``. Unset heaters are sent as TEMP_NO_CHANGE. The
|
|
66
|
+
``nozzles`` array is always present with 4 entries, so a bed or chamber change
|
|
67
|
+
leaves every tool alone.
|
|
68
|
+
"""
|
|
69
|
+
return await self.http.send_control_command(
|
|
70
|
+
Commands.TEMP_CONTROL_CMD,
|
|
71
|
+
{
|
|
72
|
+
"rightNozzle": TEMP_NO_CHANGE,
|
|
73
|
+
"leftNozzle": TEMP_NO_CHANGE,
|
|
74
|
+
"platform": TEMP_NO_CHANGE if platform is None else platform,
|
|
75
|
+
"chamber": TEMP_NO_CHANGE if chamber is None else chamber,
|
|
76
|
+
"nozzles": nozzles if nozzles is not None else [TEMP_NO_CHANGE] * NOZZLE_COUNT,
|
|
77
|
+
},
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def _nozzle_array(tool_index: int, value: int) -> list[int]:
|
|
82
|
+
if not isinstance(tool_index, int) or not 0 <= tool_index < NOZZLE_COUNT:
|
|
83
|
+
raise InvalidParameterError(
|
|
84
|
+
f"tool_index must be 0-{NOZZLE_COUNT - 1}, got {tool_index}."
|
|
85
|
+
)
|
|
86
|
+
nozzles = [TEMP_NO_CHANGE] * NOZZLE_COUNT
|
|
87
|
+
nozzles[tool_index] = value
|
|
88
|
+
return nozzles
|
|
89
|
+
|
|
90
|
+
async def set_extruder_temp(self, temp: int) -> bool:
|
|
91
|
+
"""
|
|
92
|
+
Sets tool 0. The firmware drives tools only through ``nozzles``; it never reads
|
|
93
|
+
rightNozzle/leftNozzle. Use :meth:`set_tool_temp` for another tool.
|
|
94
|
+
"""
|
|
95
|
+
return await self._send_temp(nozzles=self._nozzle_array(0, temp))
|
|
96
|
+
|
|
97
|
+
async def cancel_extruder_temp(self) -> bool:
|
|
98
|
+
return await self._send_temp(nozzles=self._nozzle_array(0, NOZZLE_OFF))
|
|
99
|
+
|
|
100
|
+
async def set_bed_temp(self, temp: int) -> bool:
|
|
101
|
+
return await self._send_temp(platform=temp)
|
|
102
|
+
|
|
103
|
+
async def cancel_bed_temp(self) -> bool:
|
|
104
|
+
return await self._send_temp(platform=TEMP_OFF)
|
|
105
|
+
|
|
106
|
+
async def set_tool_temp(self, tool_index: int, temp: int) -> bool:
|
|
107
|
+
return await self._send_temp(nozzles=self._nozzle_array(tool_index, temp))
|
|
108
|
+
|
|
109
|
+
async def set_tool_temps(self, temps: list[int]) -> bool:
|
|
110
|
+
"""Sets all 4 tools. TEMP_NO_CHANGE (-200) keeps a tool, NOZZLE_OFF (0) turns it off."""
|
|
111
|
+
if len(temps) != NOZZLE_COUNT:
|
|
112
|
+
raise InvalidParameterError(f"Expected {NOZZLE_COUNT} temperatures, got {len(temps)}.")
|
|
113
|
+
return await self._send_temp(nozzles=list(temps))
|
|
114
|
+
|
|
115
|
+
async def cancel_tool_temp(self, tool_index: int) -> bool:
|
|
116
|
+
return await self._send_temp(nozzles=self._nozzle_array(tool_index, NOZZLE_OFF))
|
|
117
|
+
|
|
118
|
+
async def set_chamber_temp(self, temp: int) -> bool:
|
|
119
|
+
"""Sets the chamber heater. Creator 5 Pro only. Keep the value in a safe range."""
|
|
120
|
+
if not self.capabilities.chamber.controllable:
|
|
121
|
+
self._unsupported("set_chamber_temp", self.capabilities.chamber.reason)
|
|
122
|
+
return await self._send_temp(chamber=temp)
|
|
123
|
+
|
|
124
|
+
async def cancel_chamber_temp(self) -> bool:
|
|
125
|
+
if not self.capabilities.chamber.controllable:
|
|
126
|
+
self._unsupported("cancel_chamber_temp", self.capabilities.chamber.reason)
|
|
127
|
+
return await self._send_temp(chamber=TEMP_OFF)
|
|
128
|
+
|
|
129
|
+
# ---- Files ---------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
async def get_local_files(self) -> list[str]:
|
|
132
|
+
"""No TCP file list on this printer: the names from ``/gcodeList`` (10 most recent)."""
|
|
133
|
+
return [entry.gcode_file_name for entry in await self.http.fetch_recent_files()]
|
|
134
|
+
|
|
135
|
+
# ---- Upload and print start ----------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
async def upload_file(self, params: UploadJobParams) -> bool:
|
|
138
|
+
"""
|
|
139
|
+
Uploads a file. There is no ``firstLayerInspection`` header on this printer.
|
|
140
|
+
Mappings are sent only with ``start_print=True`` (the firmware keeps upload mappings
|
|
141
|
+
until the next print ends). ``useMatlStation`` and ``gcodeToolCnt`` are sent for
|
|
142
|
+
parity with FlashForge's own clients; the firmware only logs them.
|
|
143
|
+
"""
|
|
144
|
+
if params.first_layer_inspection:
|
|
145
|
+
self._unsupported("upload_file", "The Creator 5 series has no first-layer inspection.")
|
|
146
|
+
mappings = params.material_mappings
|
|
147
|
+
headers = {
|
|
148
|
+
"printNow": str(params.start_print).lower(),
|
|
149
|
+
"levelingBeforePrint": str(params.leveling_before_print).lower(),
|
|
150
|
+
"flowCalibration": str(params.flow_calibration).lower(),
|
|
151
|
+
"timeLapseVideo": str(params.time_lapse_video).lower(),
|
|
152
|
+
"useMatlStation": str(bool(mappings)).lower(),
|
|
153
|
+
"gcodeToolCnt": str(len(mappings)),
|
|
154
|
+
}
|
|
155
|
+
if mappings:
|
|
156
|
+
if not params.start_print:
|
|
157
|
+
raise InvalidParameterError(
|
|
158
|
+
"Material mappings on a Creator 5 upload need start_print=True. Upload "
|
|
159
|
+
"without them and pass them to start_local_job instead."
|
|
160
|
+
)
|
|
161
|
+
validate_material_mappings(mappings)
|
|
162
|
+
headers["materialMappings"] = encode_material_mappings(mappings)
|
|
163
|
+
return await self.http.upload(params.file_path, headers)
|
|
164
|
+
|
|
165
|
+
async def start_local_job(self, params: LocalJobParams) -> bool:
|
|
166
|
+
"""
|
|
167
|
+
Starts a stored file with ``/printGcode``, sending only the fields the Creator 5
|
|
168
|
+
firmware reads. Give a mapping for every tool; mappings take effect only for a .3mf.
|
|
169
|
+
"""
|
|
170
|
+
if not params.file_name or not params.file_name.strip():
|
|
171
|
+
raise InvalidParameterError("file_name must not be empty.")
|
|
172
|
+
mappings = params.material_mappings
|
|
173
|
+
validate_material_mappings(mappings)
|
|
174
|
+
body: dict[str, Any] = {
|
|
175
|
+
"fileName": params.file_name,
|
|
176
|
+
"levelingBeforePrint": params.leveling_before_print,
|
|
177
|
+
"flowCalibration": params.flow_calibration,
|
|
178
|
+
"timeLapseVideo": params.time_lapse_video,
|
|
179
|
+
}
|
|
180
|
+
if mappings:
|
|
181
|
+
body["materialMappings"] = [m.to_wire() for m in mappings]
|
|
182
|
+
return await self.http.send_print_command(body)
|
|
183
|
+
|
|
184
|
+
# ---- Material station ----------------------------------------------------------------
|
|
185
|
+
|
|
186
|
+
async def configure_slot(self, slot_id: int, material_name: str, hex_color: str) -> bool:
|
|
187
|
+
"""
|
|
188
|
+
Sets per-tool material name and color (``msConfig_cmd``). The Creator 5 shows its 4
|
|
189
|
+
tool heads as the 4 slots. There is no load/unload (``ms_cmd``).
|
|
190
|
+
"""
|
|
191
|
+
return await self._send_slot_config(slot_id, material_name, hex_color)
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The dual-API family: Adventurer 5M, Adventurer 5M Pro and AD5X.
|
|
3
|
+
|
|
4
|
+
These printers have the HTTP API (port 8898) and the TCP command channel (port 8899). TCP
|
|
5
|
+
carries homing, raw G-code, extruder and bed temperatures, the filament-load flow, the
|
|
6
|
+
full file list. The light goes over HTTP like on every modern printer. Everything else goes over HTTP.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import TYPE_CHECKING, Any
|
|
12
|
+
|
|
13
|
+
from ..api.constants.commands import Commands
|
|
14
|
+
from ..capabilities.models import BackendFamily, PrinterModelId
|
|
15
|
+
from ..models.machine_info import FFMachineInfo
|
|
16
|
+
from ..tcp.ff_client import FlashForgeClient as TcpClient
|
|
17
|
+
from ..tcp.tcp_client import FlashForgeTcpClientOptions
|
|
18
|
+
from .http_core import HttpCore
|
|
19
|
+
from .http_printer_backend import HttpPrinterBackend
|
|
20
|
+
from .types import FiltrationMode, LocalJobParams, UploadJobParams
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from ..api.filament.filament import Filament
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def uses_new_job_format(firmware_version: str) -> bool:
|
|
27
|
+
"""
|
|
28
|
+
True when 5M-family firmware takes the extra upload headers and print-start fields
|
|
29
|
+
(firmware 3.1.3 and newer).
|
|
30
|
+
|
|
31
|
+
The printers report the version as "v3.1.3" or "3.2.0-1.0.1". A leading "v" and the
|
|
32
|
+
"-..." suffix are ignored. An unreadable or empty version reads as NEW: every current
|
|
33
|
+
firmware is new, and the old format drops fields that new firmware needs.
|
|
34
|
+
"""
|
|
35
|
+
text = firmware_version.strip().split("-")[0].strip().lstrip("vV")
|
|
36
|
+
parts = text.split(".")
|
|
37
|
+
if not text or not all(p.isdigit() for p in parts[:3]):
|
|
38
|
+
return True
|
|
39
|
+
minimum = (3, 1, 3)
|
|
40
|
+
for i in range(3):
|
|
41
|
+
current = int(parts[i]) if i < len(parts) else 0
|
|
42
|
+
if current > minimum[i]:
|
|
43
|
+
return True
|
|
44
|
+
if current < minimum[i]:
|
|
45
|
+
return False
|
|
46
|
+
return True
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class DualApiBackend(HttpPrinterBackend):
|
|
50
|
+
"""Base class of the dual-API family."""
|
|
51
|
+
|
|
52
|
+
family = BackendFamily.DUAL_API
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
model: PrinterModelId,
|
|
57
|
+
http: HttpCore,
|
|
58
|
+
info: FFMachineInfo,
|
|
59
|
+
*,
|
|
60
|
+
tcp_port: int | None = None,
|
|
61
|
+
tcp_client: TcpClient | None = None,
|
|
62
|
+
) -> None:
|
|
63
|
+
super().__init__(model, http, info)
|
|
64
|
+
#: The TCP command channel. It opens its socket on the first command.
|
|
65
|
+
self.tcp: TcpClient = tcp_client or TcpClient(
|
|
66
|
+
http.ip_address, FlashForgeTcpClientOptions(port=tcp_port)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
async def initialize(self) -> bool:
|
|
70
|
+
"""Reads ``/product``, then logs in to the TCP channel."""
|
|
71
|
+
if not await super().initialize():
|
|
72
|
+
return False
|
|
73
|
+
return await self.tcp.init_control()
|
|
74
|
+
|
|
75
|
+
async def dispose(self) -> None:
|
|
76
|
+
await super().dispose()
|
|
77
|
+
# dispose() logs out and stops the keep-alive.
|
|
78
|
+
await self.tcp.dispose()
|
|
79
|
+
|
|
80
|
+
# ---- Upload and print start (5M family format; the AD5X overrides) -------------------
|
|
81
|
+
|
|
82
|
+
def _uses_new_job_format(self) -> bool:
|
|
83
|
+
return uses_new_job_format(self.identity.firmware_version)
|
|
84
|
+
|
|
85
|
+
async def upload_file(self, params: UploadJobParams) -> bool:
|
|
86
|
+
if params.material_mappings:
|
|
87
|
+
self._unsupported("upload_file", self.capabilities.material_station.reason)
|
|
88
|
+
headers = {
|
|
89
|
+
"printNow": str(params.start_print).lower(),
|
|
90
|
+
"levelingBeforePrint": str(params.leveling_before_print).lower(),
|
|
91
|
+
}
|
|
92
|
+
if self._uses_new_job_format():
|
|
93
|
+
headers["flowCalibration"] = "false"
|
|
94
|
+
headers["useMatlStation"] = "false"
|
|
95
|
+
headers["gcodeToolCnt"] = "0"
|
|
96
|
+
headers["materialMappings"] = "W10=" # base64 of "[]"
|
|
97
|
+
return await self.http.upload(params.file_path, headers)
|
|
98
|
+
|
|
99
|
+
async def start_local_job(self, params: LocalJobParams) -> bool:
|
|
100
|
+
if params.material_mappings:
|
|
101
|
+
self._unsupported("start_local_job", self.capabilities.material_station.reason)
|
|
102
|
+
body: dict[str, Any] = {
|
|
103
|
+
"fileName": params.file_name,
|
|
104
|
+
"levelingBeforePrint": params.leveling_before_print,
|
|
105
|
+
}
|
|
106
|
+
if self._uses_new_job_format():
|
|
107
|
+
body["flowCalibration"] = False
|
|
108
|
+
body["useMatlStation"] = False
|
|
109
|
+
body["gcodeToolCnt"] = 0
|
|
110
|
+
body["materialMappings"] = []
|
|
111
|
+
return await self.http.send_print_command(body)
|
|
112
|
+
|
|
113
|
+
# ---- Files ---------------------------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
async def get_local_files(self) -> list[str]:
|
|
116
|
+
"""The full file list over TCP (M661)."""
|
|
117
|
+
return await self.tcp.get_file_list_async()
|
|
118
|
+
|
|
119
|
+
# ---- Motion and G-code ---------------------------------------------------------------
|
|
120
|
+
|
|
121
|
+
async def home_axes(self) -> bool:
|
|
122
|
+
return await self.tcp.home_axes()
|
|
123
|
+
|
|
124
|
+
async def home_axes_rapid(self) -> bool:
|
|
125
|
+
return await self.tcp.rapid_home()
|
|
126
|
+
|
|
127
|
+
async def send_gcode(self, command: str) -> str:
|
|
128
|
+
line = command.strip()
|
|
129
|
+
return await self.tcp.send_raw_cmd(line if line.startswith("~") else f"~{line}")
|
|
130
|
+
|
|
131
|
+
# ---- Temperatures (TCP M-codes) ------------------------------------------------------
|
|
132
|
+
|
|
133
|
+
async def set_extruder_temp(self, temp: int) -> bool:
|
|
134
|
+
return await self.tcp.set_extruder_temp(temp)
|
|
135
|
+
|
|
136
|
+
async def cancel_extruder_temp(self) -> bool:
|
|
137
|
+
return await self.tcp.cancel_extruder_temp()
|
|
138
|
+
|
|
139
|
+
async def set_bed_temp(self, temp: int) -> bool:
|
|
140
|
+
return await self.tcp.set_bed_temp(temp)
|
|
141
|
+
|
|
142
|
+
async def cancel_bed_temp(self) -> bool:
|
|
143
|
+
return await self.tcp.cancel_bed_temp()
|
|
144
|
+
|
|
145
|
+
# ---- Filament (TCP) ------------------------------------------------------------------
|
|
146
|
+
|
|
147
|
+
async def prepare_filament_load(self, filament: Filament) -> bool:
|
|
148
|
+
return await self.tcp.prepare_filament_load(filament)
|
|
149
|
+
|
|
150
|
+
async def load_filament(self) -> bool:
|
|
151
|
+
return await self.tcp.load_filament()
|
|
152
|
+
|
|
153
|
+
async def finish_filament_load(self) -> bool:
|
|
154
|
+
return await self.tcp.finish_filament_load()
|
|
155
|
+
|
|
156
|
+
# ---- Helpers for subclasses ----------------------------------------------------------
|
|
157
|
+
|
|
158
|
+
async def _send_filtration(self, mode: FiltrationMode) -> bool:
|
|
159
|
+
return await self.http.send_control_command(
|
|
160
|
+
Commands.CIRCULATION_CONTROL_CMD,
|
|
161
|
+
{
|
|
162
|
+
"internal": "open" if mode == "internal" else "close",
|
|
163
|
+
"external": "open" if mode == "external" else "close",
|
|
164
|
+
},
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
async def _send_camera_control(self, on: bool) -> bool:
|
|
168
|
+
return await self.http.send_control_command(
|
|
169
|
+
Commands.CAMERA_CONTROL_CMD, {"action": "open" if on else "close"}
|
|
170
|
+
)
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The dual-API model backends: Adventurer 5M, Adventurer 5M Pro and AD5X.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from ..api.constants.commands import Commands
|
|
8
|
+
from ..capabilities.models import PrinterModelId
|
|
9
|
+
from ..exceptions import InvalidParameterError
|
|
10
|
+
from ..models.machine_info import FFMachineInfo
|
|
11
|
+
from ..tcp.ff_client import FlashForgeClient as TcpClient
|
|
12
|
+
from .dual_api_backend import DualApiBackend
|
|
13
|
+
from .http_core import HttpCore
|
|
14
|
+
from .http_printer_backend import encode_material_mappings, validate_material_mappings
|
|
15
|
+
from .types import FiltrationMode, LocalJobParams, SlotAction, UploadJobParams
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class Adventurer5MBackend(DualApiBackend):
|
|
19
|
+
"""Adventurer 5M. The shared dual-API behavior with no model extras."""
|
|
20
|
+
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
http: HttpCore,
|
|
24
|
+
info: FFMachineInfo,
|
|
25
|
+
*,
|
|
26
|
+
tcp_port: int | None = None,
|
|
27
|
+
tcp_client: TcpClient | None = None,
|
|
28
|
+
) -> None:
|
|
29
|
+
super().__init__(
|
|
30
|
+
PrinterModelId.ADVENTURER_5M,
|
|
31
|
+
http,
|
|
32
|
+
info,
|
|
33
|
+
tcp_port=tcp_port,
|
|
34
|
+
tcp_client=tcp_client,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Adventurer5MProBackend(DualApiBackend):
|
|
39
|
+
"""Adventurer 5M Pro. The only model with API-controlled air filtration."""
|
|
40
|
+
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
http: HttpCore,
|
|
44
|
+
info: FFMachineInfo,
|
|
45
|
+
*,
|
|
46
|
+
tcp_port: int | None = None,
|
|
47
|
+
tcp_client: TcpClient | None = None,
|
|
48
|
+
) -> None:
|
|
49
|
+
super().__init__(
|
|
50
|
+
PrinterModelId.ADVENTURER_5M_PRO,
|
|
51
|
+
http,
|
|
52
|
+
info,
|
|
53
|
+
tcp_port=tcp_port,
|
|
54
|
+
tcp_client=tcp_client,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
async def set_filtration(self, mode: FiltrationMode) -> bool:
|
|
58
|
+
"""Sets the filtration mode (``circulateCtl_cmd``): internal, external or off."""
|
|
59
|
+
return await self._send_filtration(mode)
|
|
60
|
+
|
|
61
|
+
async def set_camera(self, on: bool) -> bool:
|
|
62
|
+
"""Turns the built-in camera stream on or off (``streamCtrl_cmd``)."""
|
|
63
|
+
return await self._send_camera_control(on)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class AD5XBackend(DualApiBackend):
|
|
67
|
+
"""AD5X (Adventurer 5X) with the 4-slot material station."""
|
|
68
|
+
|
|
69
|
+
def __init__(
|
|
70
|
+
self,
|
|
71
|
+
http: HttpCore,
|
|
72
|
+
info: FFMachineInfo,
|
|
73
|
+
*,
|
|
74
|
+
tcp_port: int | None = None,
|
|
75
|
+
tcp_client: TcpClient | None = None,
|
|
76
|
+
) -> None:
|
|
77
|
+
super().__init__(PrinterModelId.AD5X, http, info, tcp_port=tcp_port, tcp_client=tcp_client)
|
|
78
|
+
|
|
79
|
+
def _uses_new_job_format(self) -> bool:
|
|
80
|
+
# The AD5X always uses the new format; its version line is not the 5M's 3.x line.
|
|
81
|
+
return True
|
|
82
|
+
|
|
83
|
+
def _supports_left_cooling_fan(self) -> bool:
|
|
84
|
+
return True
|
|
85
|
+
|
|
86
|
+
async def upload_file(self, params: UploadJobParams) -> bool:
|
|
87
|
+
"""
|
|
88
|
+
Uploads a file. With material mappings the print uses the material station; the
|
|
89
|
+
mappings go in a base64 ``materialMappings`` header.
|
|
90
|
+
"""
|
|
91
|
+
mappings = params.material_mappings
|
|
92
|
+
validate_material_mappings(mappings)
|
|
93
|
+
return await self.http.upload(
|
|
94
|
+
params.file_path,
|
|
95
|
+
{
|
|
96
|
+
"printNow": str(params.start_print).lower(),
|
|
97
|
+
"levelingBeforePrint": str(params.leveling_before_print).lower(),
|
|
98
|
+
"flowCalibration": str(params.flow_calibration).lower(),
|
|
99
|
+
"firstLayerInspection": str(params.first_layer_inspection).lower(),
|
|
100
|
+
"timeLapseVideo": str(params.time_lapse_video).lower(),
|
|
101
|
+
"useMatlStation": str(bool(mappings)).lower(),
|
|
102
|
+
"gcodeToolCnt": str(len(mappings)),
|
|
103
|
+
"materialMappings": encode_material_mappings(mappings),
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
async def start_local_job(self, params: LocalJobParams) -> bool:
|
|
108
|
+
"""
|
|
109
|
+
Starts a stored file. With mappings it is a multi-color print from the material
|
|
110
|
+
station; without mappings it is a single-color print.
|
|
111
|
+
"""
|
|
112
|
+
if not params.file_name or not params.file_name.strip():
|
|
113
|
+
raise InvalidParameterError("file_name must not be empty.")
|
|
114
|
+
mappings = params.material_mappings
|
|
115
|
+
validate_material_mappings(mappings)
|
|
116
|
+
return await self.http.send_print_command(
|
|
117
|
+
{
|
|
118
|
+
"fileName": params.file_name,
|
|
119
|
+
"levelingBeforePrint": params.leveling_before_print,
|
|
120
|
+
"firstLayerInspection": False,
|
|
121
|
+
"flowCalibration": params.flow_calibration,
|
|
122
|
+
"timeLapseVideo": params.time_lapse_video,
|
|
123
|
+
"useMatlStation": bool(mappings),
|
|
124
|
+
"gcodeToolCnt": len(mappings),
|
|
125
|
+
"materialMappings": [m.to_wire() for m in mappings],
|
|
126
|
+
}
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
async def configure_slot(self, slot_id: int, material_name: str, hex_color: str) -> bool:
|
|
130
|
+
return await self._send_slot_config(slot_id, material_name, hex_color)
|
|
131
|
+
|
|
132
|
+
async def slot_action(self, slot_id: int, action: SlotAction) -> bool:
|
|
133
|
+
"""
|
|
134
|
+
Loads, unloads or cancels on a slot (``ms_cmd``). The operation runs on the printer
|
|
135
|
+
after the reply; poll ``get_status().material_station.state_action`` to follow it.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
slot_id: Native slot ID 1-4. The printer ignores it for CANCEL.
|
|
139
|
+
action: The slot action.
|
|
140
|
+
"""
|
|
141
|
+
if not isinstance(slot_id, int) or not 1 <= slot_id <= 4:
|
|
142
|
+
raise InvalidParameterError(f"slot_id must be 1-4, got {slot_id}.")
|
|
143
|
+
return await self.http.send_control_command(
|
|
144
|
+
Commands.MATERIAL_STATION_CMD, {"slot": slot_id, "action": int(action)}
|
|
145
|
+
)
|