Skip to content

Instantly share code, notes, and snippets.

@cp2004
Last active November 7, 2020 18:54
Show Gist options
  • Save cp2004/1a2cd865f62e59e18aa02d072055b0a2 to your computer and use it in GitHub Desktop.
Save cp2004/1a2cd865f62e59e18aa02d072055b0a2 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import re
import octoprint.plugin
TIME_REMAINING_THRESHOLD = 2 # mins
COOLDOWN_COMMAND = "M140 S0"
M73_R_REGEX = re.compile(r"R(\d*)")
class CooldownTimeRemainingPlugin(octoprint.plugin):
def on_gcode_sending(
self, comm, phase, cmd, cmd_type, gcode, subcode=None, tags=None, *args, **kwargs
):
if gcode != 'M73':
return
match = M73_R_REGEX.match(cmd)
if match:
time_remaining = match.group(1)
if int(time_remaining) <= TIME_REMAINING_THRESHOLD:
self.send_cooldown_command()
def send_cooldown_command(self):
self._printer.commands(COOLDOWN_COMMAND)
__plugin_name__ = "Cooldown after Time Remaining"
__plugin_version__ = "1.0.0"
__plugin_description__ = "Waits for an M73 R<time> command to indicate there is less than {} time remaining, too begin cooling the bed"
__plugin_pythoncompat__ = ">=2.7,<4"
__plugin_implementation__ = CooldownTimeRemainingPlugin()
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.on_gcode_sending,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment