Skip to content

Commit

Permalink
[Feature] Add support for custom before and after GCodes.
Browse files Browse the repository at this point in the history
fixes #33

Signed-off-by: Juri Berlanda <[email protected]>
  • Loading branch information
j-be committed Apr 11, 2022
1 parent 856d316 commit 9ba0095
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
29 changes: 29 additions & 0 deletions octoprint_autobim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def get_settings_defaults(self):
next_point_delay=0.0,
first_corner_is_reference=False,
g30_regex="",
before_gcode=None,
after_gcode=None,
)

##~~ Gcode received hook
Expand Down Expand Up @@ -224,6 +226,11 @@ def autobim(self):
# Jettison saved mesh
self._clear_saved_mesh()

# Custom GCode
before_gcode = self._settings.get(["before_gcode"])
if before_gcode:
self._printer.commands(self._filter_commands(before_gcode))

changed = True
threshold = self._settings.get_float(["threshold"])
multipass = self._settings.get_boolean(["multipass"])
Expand Down Expand Up @@ -278,6 +285,12 @@ def autobim(self):

self._printer.commands("M117 done")
self.running = False

# Custom GCode
after_gcode = self._settings.get(["after_gcode"])
if after_gcode:
self._printer.commands(self._filter_commands(after_gcode))

self._plugin_manager.send_plugin_message(self._identifier, dict(type="completed"))

def get_probe_points(self):
Expand All @@ -301,6 +314,12 @@ def abort_now(self, msg):
self.running = False
for handler in self.handlers:
handler.abort()

# Custom GCode
after_gcode = self._settings.get(["after_gcode"])
if after_gcode:
self._printer.commands(self._filter_commands(after_gcode))

self._plugin_manager.send_plugin_message(self._identifier, dict(type="aborted", message=msg))

def _clear_saved_mesh(self):
Expand All @@ -309,6 +328,16 @@ def _clear_saved_mesh(self):
else:
self._printer.commands("G29 J")

def _filter_commands(self, gcode):
if not gcode:
return []

ret = []
for command in gcode.split("\n"):
if command and command.strip():
ret.append(command.strip())
return ret

__plugin_name__ = "AutoBim"
__plugin_pythoncompat__ = ">=2.7,<4" # python 2 and 3

Expand Down
18 changes: 18 additions & 0 deletions octoprint_autobim/templates/autobim_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@
</div>
</div>

<div class="control-group">
<legend>Custom GCode</legend>
<label class="control-label">
You can add custom GCode. This will be executed before AutoBim does its thing (right after homing) and when
AutoBim completes - regardless on if it was successful, error, or was aborted by the user.
</label>

<label class="control-label">Before</label>
<div class="controls">
<textarea class="input-block-level" data-bind="value: settings.settings.plugins.autobim.before_gcode"></textarea>
</div>

<label class="control-label">After</label>
<div class="controls">
<textarea class="input-block-level" data-bind="value: settings.settings.plugins.autobim.after_gcode"></textarea>
</div>
</div>

<div class="control-group">
<legend>Danger Zone - only touch if you know what you are doing!</legend>
<div class="row">
Expand Down

0 comments on commit 9ba0095

Please sign in to comment.