Skip to content

Commit

Permalink
Merge pull request #44 from willindiana/master
Browse files Browse the repository at this point in the history
implemented cooldown loop
  • Loading branch information
smartin015 authored Apr 11, 2022
2 parents ad72251 + 3219614 commit 1052cb8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ This plugin automates your printing!

WARNING: Your printer must have a method of clearing the bed automatically, with correct GCODE instructions set up in this plugin's settings page - damage to your printer may occur if this is not done correctly. If you want to manually remove prints, look in the plugin settings for details on how to use `@pause` so the queue is paused before another print starts.


# Documentation

See https://smartin015.github.io/continuousprint/ for all documentation on installation, setup, queueing strategies, and development.
Expand Down
38 changes: 35 additions & 3 deletions continuousprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from __future__ import absolute_import

import octoprint.plugin
import octoprint.util
import flask
import json
import time
from io import BytesIO
from octoprint.server.util.flask import restricted_access
from octoprint.events import Events
Expand All @@ -15,7 +17,6 @@
from .print_queue import PrintQueue, QueueItem
from .driver import ContinuousPrintDriver


QUEUE_KEY = "cp_queue"
CLEARING_SCRIPT_KEY = "cp_bed_clearing_script"
FINISHED_SCRIPT_KEY = "cp_queue_finished_script"
Expand All @@ -25,7 +26,10 @@
RESTART_MAX_RETRIES_KEY = "cp_restart_on_pause_max_restarts"
RESTART_ON_PAUSE_KEY = "cp_restart_on_pause_enabled"
RESTART_MAX_TIME_KEY = "cp_restart_on_pause_max_seconds"

BED_COOLDOWN_ENABLED_KEY = "bed_cooldown_enabled"
BED_COOLDOWN_SCRIPT_KEY = "cp_bed_cooldown_script"
BED_COOLDOWN_THRESHOLD_KEY = "bed_cooldown_threshold"
BED_COOLDOWN_TIMEOUT_KEY = "bed_cooldown_timeout"

class ContinuousprintPlugin(
octoprint.plugin.SettingsPlugin,
Expand Down Expand Up @@ -73,6 +77,10 @@ def get_settings_defaults(self):
d[RESTART_MAX_RETRIES_KEY] = 3
d[RESTART_ON_PAUSE_KEY] = False
d[RESTART_MAX_TIME_KEY] = 60 * 60
d[BED_COOLDOWN_ENABLED_KEY] = False
d[BED_COOLDOWN_SCRIPT_KEY] = "; Put script to run before bed cools here\n"
d[BED_COOLDOWN_THRESHOLD_KEY] = 30
d[BED_COOLDOWN_TIMEOUT_KEY] = 60
return d

def _rm_temp_files(self):
Expand Down Expand Up @@ -219,7 +227,30 @@ def cancel_print(self):
self._msg("Print cancelled", type="error")
self._printer.cancel_print()

def wait_for_bed_cooldown(self):
self._logger.info("Running bed cooldown script")
bed_cooldown_script = self._settings.get(["cp_bed_cooldown_script"]).split("\n")
self._printer.commands(bed_cooldown_script, force=True)
self._logger.info("Preparing for Bed Cooldown")
self._printer.set_temperature("bed", 0) # turn bed off
start_time = time.time()

while (time.time() - start_time) <= (60 * float(self._settings.get(["bed_cooldown_timeout"]))): # timeout converted to seconds
bed_temp = self._printer.get_current_temperatures()["bed"]["actual"]
if bed_temp <= float(self._settings.get(["bed_cooldown_threshold"])):
self._logger.info(
f"Cooldown threshold of {self._settings.get(['bed_cooldown_threshold'])} has been met"
)
return

self._logger.info(
f"Timeout of {self._settings.get(['bed_cooldown_timeout'])} minutes exceeded"
)
return

def clear_bed(self):
if self._settings.get(["bed_cooldown_enabled"]):
self.wait_for_bed_cooldown()
path = self._write_temp_gcode(CLEARING_SCRIPT_KEY)
self._printer.select_file(path, sd=False, printAfterSelect=True)

Expand Down Expand Up @@ -539,5 +570,6 @@ def __plugin_load__():
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
"octoprint.access.permissions": __plugin_implementation__.add_permissions,
"octoprint.comm.protocol.action": __plugin_implementation__.resume_action_handler, # register to listen for "M118 //action:" commands
"octoprint.comm.protocol.action": __plugin_implementation__.resume_action_handler,
# register to listen for "M118 //action:" commands
}
37 changes: 37 additions & 0 deletions continuousprint/templates/continuousprint_settings.jinja2
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
<h3>Continuous Print Settings</h3>

<form class="form-horizontal">
<h5>Bed Cooldown Settings</h5>
<p>
If enabled, when print in queue is finished OctoPrint will run <b>Bed Cooldown Script</b>,
turn the heated bed off and monitor the bed temperature.
After either the <b>Bed Cooldown Threshold</b> or <b>Bed Cooldown Timeout</b> is
met the Bed clearing routine will continue.
</p>

<div class="control-group">
<label class="control-label">Enable Managed Bed Cooldown</label>
<div class="controls">
<input type=checkbox data-bind="checked: settings.plugins.continuousprint.bed_cooldown_enabled">
</div>
</div>

<div id="cooldownSettings">
<div class="control-group">
<label class="control-label">Bed Cooldown Script</label>
<div class="controls">
<textarea rows="8" class="input-block-level" data-bind="value: settings.plugins.continuousprint.cp_bed_cooldown_script"></textarea>
</div>
</div>

<div class="control-group">
<label class="control-label">Bed Cooldown Threshold (Celsius)</label>
<div class="controls">
<textarea rows="1" class="temperature-input" data-bind="value: settings.plugins.continuousprint.bed_cooldown_threshold"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">Bed Cooldown Timeout (Minutes)</label>
<div class="controls">
<textarea rows="1" class="temperature-input" data-bind="value: settings.plugins.continuousprint.bed_cooldown_timeout"></textarea>
</div>
</div>
</div>

<h3>Basic Scripts</h3>
<p>
For examples and best practices, see the <a href="https://smartin015.github.io/continuousprint/gcode-scripting/" target="_blank">GCODE scripting guide</a>.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "continuousprint"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "1.5.0rc2"
plugin_version = "1.5.0rc3"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 1052cb8

Please sign in to comment.