Skip to content

Commit 4d1eefe

Browse files
committed
Add an option to only send a print pause to the printer once as per #1.
1 parent 596d374 commit 4d1eefe

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

octoprint_filamentsensorng/__init__.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from __future__ import absolute_import
33
from flask import jsonify
44

5+
import time
56
import octoprint.plugin
67
from octoprint.events import Events
78
import RPi.GPIO as GPIO
8-
from time import sleep
99

1010

1111
class filamentsensorngPlugin(octoprint.plugin.StartupPlugin,
@@ -41,6 +41,10 @@ def mode(self):
4141
def confirmations(self):
4242
return int(self._settings.get(["confirmations"]))
4343

44+
@property
45+
def send_once(self):
46+
return int(self._settings.get(["send_once"]))
47+
4448
@property
4549
def debug_mode(self):
4650
return int(self._settings.get(["debug_mode"]))
@@ -79,6 +83,7 @@ def get_settings_defaults(self):
7983
'mode':0, # Board Mode
8084
'confirmations':5,# Confirm that we're actually out of filament
8185
'no_filament_gcode':'',
86+
'send_once':0,
8287
'debug_mode':0, # Debug off!
8388
'pause_print':True,
8489
})
@@ -137,24 +142,26 @@ def check_status(self):
137142
return jsonify( status = status )
138143

139144
def sensor_callback(self, _):
140-
sleep(self.poll_time/1000)
145+
time.sleep(self.poll_time/1000)
141146
self.debug_only_output('Pin: '+str(GPIO.input(self.pin)))
142147
if self.no_filament():
143148
self.confirmations_tracking+=1
144149
self.debug_only_output('Confirmations: '+str(self.confirmations_tracking))
145150
if self.confirmations<=self.confirmations_tracking:
146151
self._logger.info("Out of filament!")
147-
if self.pause_print:
148-
self._logger.info("Pausing print.")
149-
self._printer.pause_print()
150-
self.turn_off_tracking = False
151-
GPIO.remove_event_detect(self.pin)
152-
if self.no_filament_gcode:
153-
self._logger.info("Sending out of filament GCODE")
154-
self._printer.commands(self.no_filament_gcode)
152+
if self.filamentsensorngPlugin_send_once_tracking==0 or self.send_once==0:
153+
if self.pause_print:
154+
self._logger.info("Pausing print.")
155+
self._printer.pause_print()
156+
self.turn_off_tracking = False
157+
GPIO.remove_event_detect(self.pin)
158+
if self.no_filament_gcode:
159+
self._logger.info("Sending out of filament GCODE")
160+
self._printer.commands(self.no_filament_gcode)
155161
self.confirmations_tracking = 0
156162
else:
157163
self.confirmations_tracking = 0
164+
self.filamentsensorngPlugin_send_once_tracking = 0
158165

159166
def get_update_information(self):
160167
return dict(
@@ -174,7 +181,7 @@ def get_update_information(self):
174181
)
175182

176183
__plugin_name__ = "Filament Sensor NG"
177-
__plugin_version__ = "1.0.2"
184+
__plugin_version__ = "1.0.3"
178185

179186
def __plugin_load__():
180187
global __plugin_implementation__

octoprint_filamentsensorng/templates/filamentsensorng_settings.jinja2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
<input type="number" step="any" min="0" class="input-mini text-right" data-bind="value: settings.plugins.filamentsensorng.confirmations">
2020
</div>
2121
</div>
22+
<div class="control-group">
23+
<label class="control-label">{{ _('Send Pause Once?') }}</label>
24+
<div class="controls" data-toggle="tooltip" title="{{ _('Only send a pause once if a confirmation is triggered. This does not mean the pause is sent once for the entire print. WARNING: THIS CAN ALLOW YOU TO START A PRINT WITHOUT FILAMENT LOADED!') }}">
25+
<select class="select-mini" data-bind="value: settings.plugins.filamentsensorng.send_once">
26+
<option value=0>{{ _('No') }}</option>
27+
<option value=1>{{ _('Yes') }}</option>
28+
</select>
29+
</div>
30+
</div>
2231
<div class="control-group">
2332
<label class="control-label">{{ _('Switch Type:') }}</label>
2433
<div class="controls" data-toggle="tooltip" title="{{ _('Whether the sensor should trip when the switch goes HIGH or LOW, Normally Open is LOW when filament is present, and Normally Closed is HIGH when filament is present.') }}">

0 commit comments

Comments
 (0)