Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions octoprint_filamentsensorng/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import octoprint.plugin
from octoprint.events import Events
import RPi.GPIO as GPIO
from time import sleep

from time import sleep, time

class filamentsensorngPlugin(octoprint.plugin.StartupPlugin,
octoprint.plugin.EventHandlerPlugin,
Expand Down Expand Up @@ -52,6 +51,22 @@ def no_filament_gcode(self):
def pause_print(self):
return self._settings.get_boolean(["pause_print"])

@property
def send_gcode_only_once(self):
return self._settings.get_boolean(["send_gcode_only_once"])

@property
def trigger_timeout(self):
return int(self._settings.get(["trigger_timeout"]))

@property
def triggered_at(self):
return self._triggered_at

@triggered_at.setter
def triggered_at(self, value):
self._triggered_at = int(value)

def _setup_sensor(self):
if self.sensor_enabled():
self._logger.info("Setting up sensor.")
Expand Down Expand Up @@ -80,6 +95,8 @@ def get_settings_defaults(self):
'no_filament_gcode':'',
'debug_mode':0, # Debug off!
'pause_print':True,
'send_gcode_only_once':False,
'trigger_timeout':300,
})

def debug_only_output(self, string):
Expand Down Expand Up @@ -112,6 +129,7 @@ def on_event(self, event, payload):
):
self._logger.info("%s: Enabling filament sensor." % (event))
if self.sensor_enabled():
self.triggered_at = 0
GPIO.remove_event_detect(self.pin)
GPIO.add_event_detect(
self.pin, GPIO.BOTH,
Expand All @@ -138,14 +156,26 @@ def check_status(self):
def sensor_callback(self, _):
sleep(self.poll_time/1000)
self.debug_only_output('Pin: '+str(GPIO.input(self.pin)))

if self.no_filament():
self.filamentsensorngPlugin_confirmations_tracking+=1
self.filamentsensorngPlugin_confirmations_tracking += 1
self.debug_only_output('Confirmations: '+str(self.filamentsensorngPlugin_confirmations_tracking))
if self.confirmations<=self.filamentsensorngPlugin_confirmations_tracking:

if self.confirmations <= self.filamentsensorngPlugin_confirmations_tracking:
self._logger.info("Out of filament!")

# Check if we want to just end it once
if self.send_gcode_only_once:
if self.triggered_at > time() - self.trigger_timeout:
self._logger.info("Sensor callback already executed, waiting for timeout")
return
else:
self.triggered_at = time()

if self.pause_print:
self._logger.info("Pausing print.")
self._printer.pause_print()

if self.no_filament_gcode:
self._logger.info("Sending out of filament GCODE")
self._printer.commands(self.no_filament_gcode)
Expand All @@ -171,7 +201,7 @@ def get_update_information(self):
)

__plugin_name__ = "Filament Sensor NG"
__plugin_version__ = "1.0.2"
__plugin_version__ = "1.0.3"

def __plugin_load__():
global __plugin_implementation__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@
</label>
</div>
</div>
<div class="control-group">
<div class="controls" data-toggle="tooltip" title="{{ _('With this option checked, the plugin will ignore subsequent reports of out of filament until the print is resumed again.') }}">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.filamentsensorng.send_gcode_only_once"> {{ _('Send GCODE only once when out of filament. This flag resets every 5 minutes') }}
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Trigger timeout:') }}</label>
<div class="controls" data-toggle="tooltip" title="{{ _('How long (in seconds) ignore subsequent triggers') }}">
<input type="number" step="any" min="0" class="input-mini text-right" data-bind="value: settings.plugins.filamentsensorng.trigger_timeout">
</div>
</div>
</form>
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 = "Octoprint-FilamentSensor-ng"

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

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