Skip to content

Commit da8aedf

Browse files
committed
Fix bouncing and double PRINT_STARTED
1 parent 38e5527 commit da8aedf

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

octoprint_filamentreload/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from octoprint.events import eventManager, Events
66
from flask import jsonify, make_response
77
import RPi.GPIO as GPIO
8+
from time import sleep
89

910
class FilamentReloadedPlugin(octoprint.plugin.StartupPlugin,
1011
octoprint.plugin.EventHandlerPlugin,
@@ -42,6 +43,7 @@ def on_event(self, event, payload):
4243
if event == Events.PRINT_STARTED: # If a new print is beginning
4344
self._logger.info("Printing started: Filament sensor enabled")
4445
if self.pin != -1:
46+
GPIO.remove_event_detect(self.pin)
4547
GPIO.add_event_detect(self.pin, GPIO.BOTH, callback=self.check_gpio, bouncetime=self.bounce)
4648
elif event in (Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED):
4749
self._logger.info("Printing stopped: Filament sensor disabled")
@@ -51,6 +53,7 @@ def on_event(self, event, payload):
5153
pass
5254

5355
def check_gpio(self, channel):
56+
sleep(self.bounce/1000)
5457
state = GPIO.input(self.pin)
5558
self._logger.debug("Detected sensor [%s] state [%s]"%(channel, state))
5659
if state != self.switch: # If the sensor is tripped

0 commit comments

Comments
 (0)