Skip to content

Commit

Permalink
gcode parsing: Set the active tool number only on T0/T1/.../Tn commands
Browse files Browse the repository at this point in the history
Previously, any command with a T parameter (e.g. "M204 P500 R5000 T500")
would match and confuse the plugin.
  • Loading branch information
[email protected] committed May 2, 2020
1 parent bae0505 commit c670a92
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions octoprint_smartpreheat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def get_temps_from_file(self, selected_file):
path_on_disk = octoprint.server.fileManager.path_on_disk(octoprint.filemanager.FileDestinations.LOCAL, selected_file)

temps = dict(tools=dict(), bed=None)
toolNum = 0
currentToolNum = 0
lineNum = 0
self._logger.debug("Parsing g-code file, Path=%s", path_on_disk)
with open(path_on_disk, "r") as file:
Expand All @@ -86,14 +86,21 @@ def get_temps_from_file(self, selected_file):
self._logger.debug("Line %d: Detected first extrusion. Read complete.", lineNum)
break

toolMatch = octoprint.util.comm.regexes_parameters["intT"].search(line)
if toolMatch:
self._logger.debug("Line %d: Detected SetTool. Line=%s", lineNum, line)
toolNum = int(toolMatch.group("value"))
if gcode and gcode.startswith("T"):
toolMatch = octoprint.util.comm.regexes_parameters["intT"].search(line)
if toolMatch:
self._logger.debug("Line %d: Detected SetTool. Line=%s", lineNum, line)
currentToolNum = int(toolMatch.group("value"))

if gcode in ('M104', 'M109', 'M140', 'M190'):
self._logger.debug("Line %d: Detected SetTemp. Line=%s", lineNum, line)

toolMatch = octoprint.util.comm.regexes_parameters["intT"].search(line)
if toolMatch:
toolNum = int(toolMatch.group("value"))
else:
toolNum = currentToolNum

tempMatch = octoprint.util.comm.regexes_parameters["floatS"].search(line)
if tempMatch:
temp = int(tempMatch.group("value"))
Expand Down

0 comments on commit c670a92

Please sign in to comment.