Skip to content

Commit 1052cb8

Browse files
authored
Merge pull request #44 from willindiana/master
implemented cooldown loop
2 parents ad72251 + 3219614 commit 1052cb8

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ This plugin automates your printing!
1111

1212
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.
1313

14-
1514
# Documentation
1615

1716
See https://smartin015.github.io/continuousprint/ for all documentation on installation, setup, queueing strategies, and development.

continuousprint/__init__.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from __future__ import absolute_import
33

44
import octoprint.plugin
5+
import octoprint.util
56
import flask
67
import json
8+
import time
79
from io import BytesIO
810
from octoprint.server.util.flask import restricted_access
911
from octoprint.events import Events
@@ -15,7 +17,6 @@
1517
from .print_queue import PrintQueue, QueueItem
1618
from .driver import ContinuousPrintDriver
1719

18-
1920
QUEUE_KEY = "cp_queue"
2021
CLEARING_SCRIPT_KEY = "cp_bed_clearing_script"
2122
FINISHED_SCRIPT_KEY = "cp_queue_finished_script"
@@ -25,7 +26,10 @@
2526
RESTART_MAX_RETRIES_KEY = "cp_restart_on_pause_max_restarts"
2627
RESTART_ON_PAUSE_KEY = "cp_restart_on_pause_enabled"
2728
RESTART_MAX_TIME_KEY = "cp_restart_on_pause_max_seconds"
28-
29+
BED_COOLDOWN_ENABLED_KEY = "bed_cooldown_enabled"
30+
BED_COOLDOWN_SCRIPT_KEY = "cp_bed_cooldown_script"
31+
BED_COOLDOWN_THRESHOLD_KEY = "bed_cooldown_threshold"
32+
BED_COOLDOWN_TIMEOUT_KEY = "bed_cooldown_timeout"
2933

3034
class ContinuousprintPlugin(
3135
octoprint.plugin.SettingsPlugin,
@@ -73,6 +77,10 @@ def get_settings_defaults(self):
7377
d[RESTART_MAX_RETRIES_KEY] = 3
7478
d[RESTART_ON_PAUSE_KEY] = False
7579
d[RESTART_MAX_TIME_KEY] = 60 * 60
80+
d[BED_COOLDOWN_ENABLED_KEY] = False
81+
d[BED_COOLDOWN_SCRIPT_KEY] = "; Put script to run before bed cools here\n"
82+
d[BED_COOLDOWN_THRESHOLD_KEY] = 30
83+
d[BED_COOLDOWN_TIMEOUT_KEY] = 60
7684
return d
7785

7886
def _rm_temp_files(self):
@@ -219,7 +227,30 @@ def cancel_print(self):
219227
self._msg("Print cancelled", type="error")
220228
self._printer.cancel_print()
221229

230+
def wait_for_bed_cooldown(self):
231+
self._logger.info("Running bed cooldown script")
232+
bed_cooldown_script = self._settings.get(["cp_bed_cooldown_script"]).split("\n")
233+
self._printer.commands(bed_cooldown_script, force=True)
234+
self._logger.info("Preparing for Bed Cooldown")
235+
self._printer.set_temperature("bed", 0) # turn bed off
236+
start_time = time.time()
237+
238+
while (time.time() - start_time) <= (60 * float(self._settings.get(["bed_cooldown_timeout"]))): # timeout converted to seconds
239+
bed_temp = self._printer.get_current_temperatures()["bed"]["actual"]
240+
if bed_temp <= float(self._settings.get(["bed_cooldown_threshold"])):
241+
self._logger.info(
242+
f"Cooldown threshold of {self._settings.get(['bed_cooldown_threshold'])} has been met"
243+
)
244+
return
245+
246+
self._logger.info(
247+
f"Timeout of {self._settings.get(['bed_cooldown_timeout'])} minutes exceeded"
248+
)
249+
return
250+
222251
def clear_bed(self):
252+
if self._settings.get(["bed_cooldown_enabled"]):
253+
self.wait_for_bed_cooldown()
223254
path = self._write_temp_gcode(CLEARING_SCRIPT_KEY)
224255
self._printer.select_file(path, sd=False, printAfterSelect=True)
225256

@@ -539,5 +570,6 @@ def __plugin_load__():
539570
__plugin_hooks__ = {
540571
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
541572
"octoprint.access.permissions": __plugin_implementation__.add_permissions,
542-
"octoprint.comm.protocol.action": __plugin_implementation__.resume_action_handler, # register to listen for "M118 //action:" commands
573+
"octoprint.comm.protocol.action": __plugin_implementation__.resume_action_handler,
574+
# register to listen for "M118 //action:" commands
543575
}

continuousprint/templates/continuousprint_settings.jinja2

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,43 @@
11
<h3>Continuous Print Settings</h3>
22

33
<form class="form-horizontal">
4+
<h5>Bed Cooldown Settings</h5>
5+
<p>
6+
If enabled, when print in queue is finished OctoPrint will run <b>Bed Cooldown Script</b>,
7+
turn the heated bed off and monitor the bed temperature.
8+
After either the <b>Bed Cooldown Threshold</b> or <b>Bed Cooldown Timeout</b> is
9+
met the Bed clearing routine will continue.
10+
</p>
11+
12+
<div class="control-group">
13+
<label class="control-label">Enable Managed Bed Cooldown</label>
14+
<div class="controls">
15+
<input type=checkbox data-bind="checked: settings.plugins.continuousprint.bed_cooldown_enabled">
16+
</div>
17+
</div>
18+
19+
<div id="cooldownSettings">
20+
<div class="control-group">
21+
<label class="control-label">Bed Cooldown Script</label>
22+
<div class="controls">
23+
<textarea rows="8" class="input-block-level" data-bind="value: settings.plugins.continuousprint.cp_bed_cooldown_script"></textarea>
24+
</div>
25+
</div>
26+
27+
<div class="control-group">
28+
<label class="control-label">Bed Cooldown Threshold (Celsius)</label>
29+
<div class="controls">
30+
<textarea rows="1" class="temperature-input" data-bind="value: settings.plugins.continuousprint.bed_cooldown_threshold"></textarea>
31+
</div>
32+
</div>
33+
<div class="control-group">
34+
<label class="control-label">Bed Cooldown Timeout (Minutes)</label>
35+
<div class="controls">
36+
<textarea rows="1" class="temperature-input" data-bind="value: settings.plugins.continuousprint.bed_cooldown_timeout"></textarea>
37+
</div>
38+
</div>
39+
</div>
40+
441
<h3>Basic Scripts</h3>
542
<p>
643
For examples and best practices, see the <a href="https://smartin015.github.io/continuousprint/gcode-scripting/" target="_blank">GCODE scripting guide</a>.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plugin_name = "continuousprint"
1515

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

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

0 commit comments

Comments
 (0)