Skip to content

Commit 3bb69d0

Browse files
committed
Initial Commit
0 parents  commit 3bb69d0

File tree

9 files changed

+265
-0
lines changed

9 files changed

+265
-0
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
end_of_line = lf
8+
charset = utf-8
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[**.py]
13+
indent_style = tab
14+
15+
[**.js]
16+
indent_style = space
17+
indent_size = 4

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.pyc
2+
*.swp
3+
.idea
4+
*.iml
5+
build
6+
dist
7+
*.egg*
8+
.DS_Store
9+
*.zip

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include README.md

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# OctoPrint-FilamentReloaded
2+
3+
Based on the Octoprint-Filament plugin by MoonshineSG (https://github.com/MoonshineSG/Octoprint-Filament), this modification adds the ability to modify your configuration through OctoPrint settings, as well as adding configurations for both NO and NC switches.
4+
5+
Future developments are planned to include multiple filament sensors, pop-ups, pre-print validation and custom filament run-out scripting.
6+
7+
## Setup
8+
9+
Install via the bundled [Plugin Manager](https://github.com/foosel/OctoPrint/wiki/Plugin:-Plugin-Manager)
10+
or manually using this URL:
11+
12+
https://github.com/kontakt/Octoprint-Filament-Reloaded/archive/master.zip
13+
14+
Using this plugin requires a filament sensor. The code is set to use the Raspberry Pi's internal Pull-Up resistors, so the switch should be between your detection pin and a ground pin.

babel.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[python: */**.py]
2+
[jinja2: */**.jinja2]
3+
extensions=jinja2.ext.autoescape, jinja2.ext.with_
4+
5+
[javascript: */**.js]
6+
extract_messages = gettext, ngettext
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# coding=utf-8
2+
from __future__ import absolute_import
3+
4+
import octoprint.plugin
5+
from octoprint.events import eventManager, Events
6+
from flask import jsonify, make_response
7+
import RPi.GPIO as GPIO
8+
9+
class FilamentReloadedPlugin(octoprint.plugin.StartupPlugin,
10+
octoprint.plugin.EventHandlerPlugin,
11+
octoprint.plugin.TemplatePlugin,
12+
octoprint.plugin.SettingsPlugin):
13+
14+
def initialize(self):
15+
self._logger.info("Running RPi.GPIO version '{0}'".format(GPIO.VERSION))
16+
if GPIO.VERSION < "0.6": # Need at least 0.6 for edge detection
17+
raise Exception("RPi.GPIO must be greater than 0.6")
18+
GPIO.setmode(GPIO.BOARD) # Use the board numbering scheme
19+
GPIO.setwarnings(False) # Disable GPIO warnings
20+
21+
def on_after_startup(self):
22+
self._logger.info("Filament Sensor Reloaded started")
23+
self.pin = int(self._settings.get(["pin"]))
24+
self.bounce = int(self._settings.get(["bounce"]))
25+
self.switch = int(self._settings.get(["switch"]))
26+
27+
if self._settings.get(["pin"]) != -1: # If a pin is defined
28+
self._logger.info("Filament Sensor active on GPIO Pin [%s]"%self.pin)
29+
GPIO.setup(self.pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Initialize GPIO as INPUT
30+
31+
def get_settings_defaults(self):
32+
return dict(
33+
pin = -1, # Default is no pin
34+
bounce = 250, # Debounce 250ms
35+
switch = 0 # Normally Open
36+
)
37+
38+
def get_template_configs(self):
39+
return [dict(type="settings", custom_bindings=False)]
40+
41+
def on_event(self, event, payload):
42+
if event == Events.PRINT_STARTED: # If a new print is beginning
43+
self._logger.info("Printing started: Filament sensor enabled")
44+
if self.pin != -1:
45+
GPIO.add_event_detect(self.pin, GPIO.BOTH, callback=self.check_gpio, bouncetime=self.bounce)
46+
elif event in (Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED):
47+
self._logger.info("Printing stopped: Filament sensor disabled")
48+
try:
49+
GPIO.remove_event_detect(self.pin)
50+
except Exception:
51+
pass
52+
53+
def check_gpio(self, channel):
54+
state = GPIO.input(self.pin)
55+
self._logger.debug("Detected sensor [%s] state [%s]"%(channel, state))
56+
if state != self.switch: # If the sensor is tripped
57+
self._logger.debug("Sensor [%s]"%state)
58+
if self._printer.is_printing():
59+
self._printer.toggle_pause_print()
60+
61+
def get_update_information(self):
62+
return dict(
63+
octoprint_filament=dict(
64+
displayName="Filament Sensor Reloaded",
65+
displayVersion=self._plugin_version,
66+
67+
# version check: github repository
68+
type="github_release",
69+
user="kontakt",
70+
repo="Octoprint-Filament-Reloaded",
71+
current=self._plugin_version,
72+
73+
# update method: pip
74+
pip="https://github.com/kontakt/Octoprint-Filament-Reloaded/archive/{target_version}.zip"
75+
)
76+
)
77+
78+
__plugin_name__ = "Filament Sensor Reloaded"
79+
__plugin_version__ = "1.0.0"
80+
81+
def __plugin_load__():
82+
global __plugin_implementation__
83+
__plugin_implementation__ = FilamentReloadedPlugin()
84+
85+
global __plugin_hooks__
86+
__plugin_hooks__ = {
87+
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
88+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<h4>{{ _('Filament Sensor') }}</h4>
2+
Define the pin used by your sensor and the debounce timing for false positive prevention.
3+
<br>
4+
<form class="form-horizontal">
5+
<div class="control-group">
6+
<label class="control-label">{{ _('Pin:') }}</label>
7+
<div class="controls" data-toggle="tooltip" title="{{ _('Which GPIO pin your switch is attached to') }}">
8+
<input type="number" step="any" min="0" class="input-mini text-right" data-bind="value: settings.plugins.filamentreload.pin">
9+
</div>
10+
</div>
11+
<div class="control-group">
12+
<label class="control-label">{{ _('Debounce Time:') }}</label>
13+
<div class="controls" data-toggle="tooltip" title="{{ _('The amount of time a signal needs to stay constant to be considered valid') }}">
14+
<input type="number" step="any" min="0" class="input-mini text-right" data-bind="value: settings.plugins.filamentreload.bounce">
15+
<span class="add-on">ms</span>
16+
</div>
17+
</div>
18+
<div class="control-group">
19+
<label class="control-label">{{ _('Switch Type:') }}</label>
20+
<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') }}">
21+
<select class="select-mini" data-bind="value: settings.plugins.filamentreload.switch">
22+
<option value=0>{{ _('Normally Open') }}</option>
23+
<option value=1>{{ _('Normally Closed') }}</option>
24+
</select>
25+
</div>
26+
</div>
27+
</form>

requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
###
2+
# This file is only here to make sure that something like
3+
#
4+
# pip install -e .
5+
#
6+
# works as expected. Requirements can be found in setup.py.
7+
###
8+
9+
.

setup.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# coding=utf-8
2+
3+
########################################################################################################################
4+
### Do not forget to adjust the following variables to your own plugin.
5+
6+
# The plugin's identifier, has to be unique
7+
plugin_identifier = "filamentreload"
8+
9+
# The plugin's python package, should be "octoprint_<plugin identifier>", has to be unique
10+
plugin_package = "octoprint_filamentreload"
11+
12+
# The plugin's human readable name. Can be overwritten within OctoPrint's internal data via __plugin_name__ in the
13+
# plugin module
14+
plugin_name = "Octoprint-FilamentReload"
15+
16+
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
17+
plugin_version = "1.0.0"
18+
19+
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
20+
# module
21+
plugin_description = """A revamped and rewritten filament monitor that pauses the print when your filament runs out"""
22+
23+
# The plugin's author. Can be overwritten within OctoPrint's internal data via __plugin_author__ in the plugin module
24+
plugin_author = "Connor Huffine"
25+
26+
# The plugin's author's mail address.
27+
plugin_author_email = "[email protected]"
28+
29+
# The plugin's homepage URL. Can be overwritten within OctoPrint's internal data via __plugin_url__ in the plugin module
30+
plugin_url = "https://github.com/kontakt/Octoprint-Filament-Reloaded"
31+
32+
# The plugin's license. Can be overwritten within OctoPrint's internal data via __plugin_license__ in the plugin module
33+
plugin_license = "AGPLv3"
34+
35+
# Any additional requirements besides OctoPrint should be listed here
36+
plugin_requires = []
37+
38+
### --------------------------------------------------------------------------------------------------------------------
39+
### More advanced options that you usually shouldn't have to touch follow after this point
40+
### --------------------------------------------------------------------------------------------------------------------
41+
42+
# Additional package data to install for this plugin. The subfolders "templates", "static" and "translations" will
43+
# already be installed automatically if they exist.
44+
plugin_additional_data = []
45+
46+
# Any additional python packages you need to install with your plugin that are not contains in <plugin_package>.*
47+
plugin_addtional_packages = []
48+
49+
# Any python packages within <plugin_package>.* you do NOT want to install with your plugin
50+
plugin_ignored_packages = []
51+
52+
# Additional parameters for the call to setuptools.setup. If your plugin wants to register additional entry points,
53+
# define dependency links or other things like that, this is the place to go. Will be merged recursively with the
54+
# default setup parameters as provided by octoprint_setuptools.create_plugin_setup_parameters using
55+
# octoprint.util.dict_merge.
56+
#
57+
# Example:
58+
# plugin_requires = ["someDependency==dev"]
59+
# additional_setup_parameters = {"dependency_links": ["https://github.com/someUser/someRepo/archive/master.zip#egg=someDependency-dev"]}
60+
additional_setup_parameters = {}
61+
62+
########################################################################################################################
63+
64+
from setuptools import setup
65+
66+
try:
67+
import octoprint_setuptools
68+
except:
69+
print("Could not import OctoPrint's setuptools, are you sure you are running that under "
70+
"the same python installation that OctoPrint is installed under?")
71+
import sys
72+
sys.exit(-1)
73+
74+
setup_parameters = octoprint_setuptools.create_plugin_setup_parameters(
75+
identifier=plugin_identifier,
76+
package=plugin_package,
77+
name=plugin_name,
78+
version=plugin_version,
79+
description=plugin_description,
80+
author=plugin_author,
81+
mail=plugin_author_email,
82+
url=plugin_url,
83+
license=plugin_license,
84+
requires=plugin_requires,
85+
additional_packages=plugin_addtional_packages,
86+
ignored_packages=plugin_ignored_packages,
87+
additional_data=plugin_additional_data
88+
)
89+
90+
if len(additional_setup_parameters):
91+
from octoprint.util import dict_merge
92+
setup_parameters = dict_merge(setup_parameters, additional_setup_parameters)
93+
94+
setup(**setup_parameters)

0 commit comments

Comments
 (0)