Skip to content

Instantly share code, notes, and snippets.

@foosel
Created October 14, 2016 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foosel/6889c0b55408faa1a9298e8c3be3d955 to your computer and use it in GitHub Desktop.
Save foosel/6889c0b55408faa1a9298e8c3be3d955 to your computer and use it in GitHub Desktop.
from __future__ import absolute_import
import octoprint.plugin
import threading
import time
class Test1543Plugin(octoprint.plugin.OctoPrintPlugin):
def __init__(self):
self._worker = None
def hook(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
if gcode is not None or cmd != "test1543" or self._worker is not None:
return
self._worker = threading.Thread(target=self.worker)
self._worker.daemon = True
self._worker.start()
def worker(self):
self._logger.info("START TEMPS: " + str(self._printer.get_current_temperatures()))
self._bed_temperature(70)
self._tool_temperature(220)
self._worker = None
def _bed_temperature(self, temp):
self._target_temperature("bed", temp)
def _tool_temperature(self, temp):
self._target_temperature("tool0", temp)
def _target_temperature(self, tool, temp):
self._printer.set_temperature(tool, temp)
self._logger.info("{} set to {}".format(tool, temp))
curr = self._printer.get_current_temperatures()
while curr[tool]['target'] < 10:
self._logger.info(repr(curr))
curr = self._printer.get_current_temperatures()
time.sleep(.1)
self._logger.info(repr(curr))
def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = Test1543Plugin()
global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.queuing": __plugin_implementation__.hook
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment