Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
3e7708429d | |||
908173214f | |||
df4bd6cf44 |
@ -4,6 +4,7 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agp
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
import datetime
|
import datetime
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
import re
|
import re
|
||||||
@ -162,13 +163,14 @@ class BambuPrinter:
|
|||||||
|
|
||||||
# self._logger.debug(device_data)
|
# self._logger.debug(device_data)
|
||||||
|
|
||||||
|
self.lastTempAt = time.monotonic()
|
||||||
self.temp[0] = temperatures.get("nozzle_temp", 0.0)
|
self.temp[0] = temperatures.get("nozzle_temp", 0.0)
|
||||||
self.targetTemp[0] = temperatures.get("target_nozzle_temp", 0.0)
|
self.targetTemp[0] = temperatures.get("target_nozzle_temp", 0.0)
|
||||||
self.bedTemp = temperatures.get("bed_temp", 0.0)
|
self.bedTemp = temperatures.get("bed_temp", 0.0)
|
||||||
self.bedTargetTemp = temperatures.get("target_bed_temp", 0.0)
|
self.bedTargetTemp = temperatures.get("target_bed_temp", 0.0)
|
||||||
self.chamberTemp = temperatures.get("chamber_temp", 0.0)
|
self.chamberTemp = temperatures.get("chamber_temp", 0.0)
|
||||||
|
|
||||||
if print_job.get("gcode_state") == "RUNNING" or print_job.get("gcode_state") == "PREPARE":
|
if print_job.get("gcode_state") == "RUNNING":
|
||||||
if not self._sdPrintingSemaphore.is_set():
|
if not self._sdPrintingSemaphore.is_set():
|
||||||
self._sdPrintingSemaphore.set()
|
self._sdPrintingSemaphore.set()
|
||||||
if self._sdPrintingPausedSemaphore.is_set():
|
if self._sdPrintingPausedSemaphore.is_set():
|
||||||
@ -181,6 +183,8 @@ class BambuPrinter:
|
|||||||
filename = f"{filename.lower()}.3mf"
|
filename = f"{filename.lower()}.3mf"
|
||||||
elif self._sdFileListCache.get(f"{filename.lower()}.gcode.3mf"):
|
elif self._sdFileListCache.get(f"{filename.lower()}.gcode.3mf"):
|
||||||
filename = f"{filename.lower()}.gcode.3mf"
|
filename = f"{filename.lower()}.gcode.3mf"
|
||||||
|
else:
|
||||||
|
self._logger.debug(f"No 3mf file found for {print_job}")
|
||||||
|
|
||||||
self._selectSdFile(filename)
|
self._selectSdFile(filename)
|
||||||
self._startSdPrint(from_printer=True)
|
self._startSdPrint(from_printer=True)
|
||||||
@ -196,7 +200,7 @@ class BambuPrinter:
|
|||||||
self._send("// action:paused")
|
self._send("// action:paused")
|
||||||
self._sendPaused()
|
self._sendPaused()
|
||||||
|
|
||||||
if ( print_job.get("gcode_state") == "FINISH" or print_job.get("gcode_state") == "FAILED" ):
|
if print_job.get("gcode_state") == "FINISH" or print_job.get("gcode_state") == "FAILED":
|
||||||
if self._sdPrintStarting is False:
|
if self._sdPrintStarting is False:
|
||||||
self._sdPrinting = False
|
self._sdPrinting = False
|
||||||
if self._sdPrintingSemaphore.is_set():
|
if self._sdPrintingSemaphore.is_set():
|
||||||
@ -211,7 +215,16 @@ class BambuPrinter:
|
|||||||
):
|
):
|
||||||
asyncio.run(self._create_connection_async())
|
asyncio.run(self._create_connection_async())
|
||||||
|
|
||||||
|
def on_disconnect(self, on_disconnect):
|
||||||
|
self._logger.debug(f"on disconnect called")
|
||||||
|
return on_disconnect
|
||||||
|
|
||||||
|
def on_connect(self, on_connect):
|
||||||
|
self._logger.debug(f"on connect called")
|
||||||
|
return on_connect
|
||||||
|
|
||||||
async def _create_connection_async(self):
|
async def _create_connection_async(self):
|
||||||
|
self._logger.debug(f"connecting via local mqtt: {self._settings.get_boolean(['local_mqtt'])}")
|
||||||
self.bambu = BambuClient(device_type=self._settings.get(["device_type"]),
|
self.bambu = BambuClient(device_type=self._settings.get(["device_type"]),
|
||||||
serial=self._settings.get(["serial"]),
|
serial=self._settings.get(["serial"]),
|
||||||
host=self._settings.get(["host"]),
|
host=self._settings.get(["host"]),
|
||||||
@ -222,13 +235,11 @@ class BambuPrinter:
|
|||||||
email=self._settings.get(["email"]),
|
email=self._settings.get(["email"]),
|
||||||
auth_token=self._settings.get(["auth_token"])
|
auth_token=self._settings.get(["auth_token"])
|
||||||
)
|
)
|
||||||
|
self.bambu.on_disconnect = self.on_disconnect(self.bambu.on_disconnect)
|
||||||
|
self.bambu.on_connect = self.on_connect(self.bambu.on_connect)
|
||||||
self.bambu.connect(callback=self.new_update)
|
self.bambu.connect(callback=self.new_update)
|
||||||
self._logger.info(f"bambu connection status: {self.bambu.connected}")
|
self._logger.info(f"bambu connection status: {self.bambu.connected}")
|
||||||
self._sendOk()
|
self._sendOk()
|
||||||
# while True:
|
|
||||||
# await asyncio.sleep(self.tick_rate)
|
|
||||||
# self._processTemperatureQuery()
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "BAMBU(read_timeout={read_timeout},write_timeout={write_timeout},options={options})".format(
|
return "BAMBU(read_timeout={read_timeout},write_timeout={write_timeout},options={options})".format(
|
||||||
@ -554,8 +565,7 @@ class BambuPrinter:
|
|||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def _gcode_M105(self, data: str) -> bool:
|
def _gcode_M105(self, data: str) -> bool:
|
||||||
self._processTemperatureQuery()
|
return self._processTemperatureQuery()
|
||||||
return True
|
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def _gcode_M115(self, data: str) -> bool:
|
def _gcode_M115(self, data: str) -> bool:
|
||||||
@ -588,6 +598,26 @@ class BambuPrinter:
|
|||||||
self._send(text)
|
self._send(text)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# noinspection PyUnusedLocal
|
||||||
|
def _gcode_M220(self, data: str) -> bool:
|
||||||
|
if self.bambu.connected:
|
||||||
|
gcode_command = commands.SEND_GCODE_TEMPLATE
|
||||||
|
percent = int(data[1:])
|
||||||
|
|
||||||
|
if percent is None or percent < 1 or percent > 166:
|
||||||
|
return True
|
||||||
|
|
||||||
|
speed_fraction = 100 / percent
|
||||||
|
acceleration = math.exp((speed_fraction - 1.0191) / -0.814)
|
||||||
|
feed_rate = (2.1645 * (acceleration ** 3) - 5.3247 * (acceleration ** 2) + 4.342 * acceleration - 0.181)
|
||||||
|
speed_level = 1.539 * (acceleration ** 2) - 0.7032 * acceleration + 4.0834
|
||||||
|
speed_command = f"M204.2 K${acceleration:.2f} \nM220 K${feed_rate:.2f} \nM73.2 R${speed_fraction:.2f} \nM1002 set_gcode_claim_speed_level ${speed_level:.0f}\n"
|
||||||
|
|
||||||
|
gcode_command['print']['param'] = speed_command
|
||||||
|
if self.bambu.publish(gcode_command):
|
||||||
|
self._logger.info(f"{percent}% speed adjustment command sent successfully")
|
||||||
|
return True
|
||||||
|
|
||||||
# noinspection PyUnusedLocal
|
# noinspection PyUnusedLocal
|
||||||
def _gcode_M400(self, data: str) -> bool:
|
def _gcode_M400(self, data: str) -> bool:
|
||||||
return True
|
return True
|
||||||
@ -698,16 +728,20 @@ class BambuPrinter:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def _getSdFileData(self, filename: str) -> Optional[Dict[str, Any]]:
|
def _getSdFileData(self, filename: str) -> Optional[Dict[str, Any]]:
|
||||||
|
self._logger.debug(f"_getSdFileData: {filename}")
|
||||||
data = self._sdFileListCache.get(filename.lower())
|
data = self._sdFileListCache.get(filename.lower())
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
data = self._sdFileListCache.get(data.lower())
|
data = self._sdFileListCache.get(data.lower())
|
||||||
|
self._logger.debug(f"_getSdFileData: {data}")
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _getSdFiles(self) -> List[Dict[str, Any]]:
|
def _getSdFiles(self) -> List[Dict[str, Any]]:
|
||||||
self._sdFileListCache = self._mappedSdList()
|
self._sdFileListCache = self._mappedSdList()
|
||||||
|
self._logger.debug(f"_getSdFiles return: {self._sdFileListCache}")
|
||||||
return [x for x in self._sdFileListCache.values() if isinstance(x, dict)]
|
return [x for x in self._sdFileListCache.values() if isinstance(x, dict)]
|
||||||
|
|
||||||
def _selectSdFile(self, filename: str, check_already_open: bool = False) -> None:
|
def _selectSdFile(self, filename: str, check_already_open: bool = False) -> None:
|
||||||
|
self._logger.debug(f"_selectSdFile: {filename}, check_already_open={check_already_open}")
|
||||||
if filename.startswith("/"):
|
if filename.startswith("/"):
|
||||||
filename = filename[1:]
|
filename = filename[1:]
|
||||||
|
|
||||||
@ -729,6 +763,7 @@ class BambuPrinter:
|
|||||||
self._send("File selected")
|
self._send("File selected")
|
||||||
|
|
||||||
def _startSdPrint(self, from_printer: bool = False) -> None:
|
def _startSdPrint(self, from_printer: bool = False) -> None:
|
||||||
|
self._logger.debug(f"_startSdPrint: from_printer={from_printer}")
|
||||||
if self._selectedSdFile is not None:
|
if self._selectedSdFile is not None:
|
||||||
if self._sdPrinter is None:
|
if self._sdPrinter is None:
|
||||||
self._sdPrinting = True
|
self._sdPrinting = True
|
||||||
@ -788,10 +823,14 @@ class BambuPrinter:
|
|||||||
output += " @:64\n"
|
output += " @:64\n"
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def _processTemperatureQuery(self):
|
def _processTemperatureQuery(self) -> bool:
|
||||||
# includeOk = not self._okBeforeCommandOutput
|
# includeOk = not self._okBeforeCommandOutput
|
||||||
output = self._generateTemperatureOutput()
|
if self.bambu.connected:
|
||||||
self._send(output)
|
output = self._generateTemperatureOutput()
|
||||||
|
self._send(output)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def _writeSdFile(self, filename: str) -> None:
|
def _writeSdFile(self, filename: str) -> None:
|
||||||
self._send(f"Writing to file: {filename}")
|
self._send(f"Writing to file: {filename}")
|
||||||
@ -820,7 +859,13 @@ class BambuPrinter:
|
|||||||
print_command = {"print": {"sequence_id": 0,
|
print_command = {"print": {"sequence_id": 0,
|
||||||
"command": "project_file",
|
"command": "project_file",
|
||||||
"param": "Metadata/plate_1.gcode",
|
"param": "Metadata/plate_1.gcode",
|
||||||
|
"md5": "",
|
||||||
|
"profile_id": "0",
|
||||||
|
"project_id": "0",
|
||||||
|
"subtask_id": "0",
|
||||||
|
"task_id": "0",
|
||||||
"subtask_name": f"{self._selectedSdFile}",
|
"subtask_name": f"{self._selectedSdFile}",
|
||||||
|
"file": f"{self._selectedSdFile}",
|
||||||
"url": f"file:///mnt/sdcard/{self._selectedSdFile}" if self._settings.get_boolean(["device_type"]) in ["X1", "X1C"] else f"file:///sdcard/{self._selectedSdFile}",
|
"url": f"file:///mnt/sdcard/{self._selectedSdFile}" if self._settings.get_boolean(["device_type"]) in ["X1", "X1C"] else f"file:///sdcard/{self._selectedSdFile}",
|
||||||
"timelapse": self._settings.get_boolean(["timelapse"]),
|
"timelapse": self._settings.get_boolean(["timelapse"]),
|
||||||
"bed_leveling": self._settings.get_boolean(["bed_leveling"]),
|
"bed_leveling": self._settings.get_boolean(["bed_leveling"]),
|
||||||
|
2
setup.py
2
setup.py
@ -14,7 +14,7 @@ plugin_package = "octoprint_bambu_printer"
|
|||||||
plugin_name = "OctoPrint-BambuPrinter"
|
plugin_name = "OctoPrint-BambuPrinter"
|
||||||
|
|
||||||
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
||||||
plugin_version = "0.0.17"
|
plugin_version = "0.0.19"
|
||||||
|
|
||||||
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
||||||
# module
|
# module
|
||||||
|
Reference in New Issue
Block a user