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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
*.egg*
.DS_Store
*.zip
make.sh
45 changes: 29 additions & 16 deletions octoprint_filamentreload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class FilamentReloadedPlugin(octoprint.plugin.StartupPlugin,
octoprint.plugin.BlueprintPlugin):

def initialize(self):
self._logger.info("Running RPi.GPIO version '{0}'".format(GPIO.VERSION))
self._logger.info(
"Running RPi.GPIO version '{0}'".format(GPIO.VERSION))
if GPIO.VERSION < "0.6": # Need at least 0.6 for edge detection
raise Exception("RPi.GPIO must be greater than 0.6")
GPIO.setwarnings(False) # Disable GPIO warnings


@octoprint.plugin.BlueprintPlugin.route("/status", methods=["GET"])
def check_status(self):
status = "-1"
Expand Down Expand Up @@ -52,6 +52,10 @@ def no_filament_gcode(self):
def pause_print(self):
return self._settings.get_boolean(["pause_print"])

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

@property
def send_gcode_only_once(self):
return self._settings.get_boolean(["send_gcode_only_once"])
Expand All @@ -65,24 +69,27 @@ def _setup_sensor(self):
else:
self._logger.info("Using BCM Mode")
GPIO.setmode(GPIO.BCM)
self._logger.info("Filament Sensor active on GPIO Pin [%s]"%self.pin)
self._logger.info(
"Filament Sensor active on GPIO Pin [%s]" % self.pin)
GPIO.setup(self.pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
else:
self._logger.info("Pin not configured, won't work unless configured!")
self._logger.info(
"Pin not configured, won't work unless configured!")

def on_after_startup(self):
self._logger.info("Filament Sensor Reloaded started")
self._setup_sensor()

def get_settings_defaults(self):
return dict(
pin = -1, # Default is no pin
bounce = 250, # Debounce 250ms
switch = 0, # Normally Open
mode = 0, # Board Mode
no_filament_gcode = '',
pause_print = True,
send_gcode_only_once = False, # Default set to False for backward compatibility
pin=-1, # Default is no pin
bounce=250, # Debounce 250ms
switch=0, # Normally Open
mode=0, # Board Mode
no_filament_gcode='',
pause_print=True,
prevent_print=True,
send_gcode_only_once=False, # Default set to False for backward compatibility
)

def on_settings_save(self, data):
Expand All @@ -104,17 +111,21 @@ def get_template_configs(self):
def on_event(self, event, payload):
# Early abort in case of out ot filament when start printing, as we
# can't change with a cold nozzle
if event is Events.PRINT_STARTED and self.no_filament():
if event is Events.PRINT_STARTED and self.no_filament() and self.prevent_print:
self._logger.info("Printing aborted: no filament detected!")
self._printer.cancel_print()
# Enable sensor
if event in (
Events.PRINT_STARTED,
Events.PRINT_RESUMED
):
if self.prevent_print and self.no_filament():
self._logger.info(
"Printing paused: request to resume but no filament detected!")
self._printer.pause_print()
self._logger.info("%s: Enabling filament sensor." % (event))
if self.sensor_enabled():
self.triggered = 0 # reset triggered state
self.triggered = 0 # reset triggered state
GPIO.remove_event_detect(self.pin)
GPIO.add_event_detect(
self.pin, GPIO.BOTH,
Expand All @@ -134,7 +145,7 @@ def on_event(self, event, payload):
def sensor_callback(self, _):
sleep(self.bounce/1000)

# If we have previously triggered a state change we are still out
# If we have previously triggered a state change we are still out
# of filament. Log it and wait on a print resume or a new print job.
if self.sensor_triggered():
self._logger.info("Sensor callback but no trigger state change.")
Expand All @@ -158,7 +169,7 @@ def sensor_callback(self, _):
self._printer.commands(self.no_filament_gcode)
else:
self._logger.info("Filament detected!")

self.triggered = 0

def get_update_information(self):
return dict(
Expand All @@ -177,14 +188,16 @@ def get_update_information(self):
)
)


__plugin_name__ = "Filament Sensor Reloaded"
__plugin_version__ = "1.0.2"


def __plugin_load__():
global __plugin_implementation__
__plugin_implementation__ = FilamentReloadedPlugin()

global __plugin_hooks__
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@
<input type="checkbox" data-bind="checked: settings.plugins.filamentreload.pause_print"> {{ _('Pause print when out of filament') }}
</label>
</div>
<div class="controls" data-toggle="tooltip" title="{{ _('With this option checked, the plugin will not allow the print to start or resume if it does not detect that filament is present.') }}">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.filamentreload.prevent_print"> {{ _('Prevent start/resume when out of filament') }}
</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">
Expand Down