From 3c75a39e322afb73acf5521e9dc02cc9d3070802 Mon Sep 17 00:00:00 2001 From: Vitor de Miranda Henrique Date: Sat, 4 Mar 2017 20:49:34 -0600 Subject: [PATCH] bug fix --- octoprint_enclosure/__init__.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index 554b3d4..e1ee378 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -24,17 +24,21 @@ class EnclosureGPIO(): self.timeDelay = timeDelay def configureGPIO(self): - if self.enable: - if self.isOutput: - if self.activeLow: #if is active low, we start disabelling it by making it high! - GPIO.setup(self.pinNumber, GPIO.OUT, initial=GPIO.HIGH) + try: + if self.enable: + if self.isOutput: + if self.activeLow: #if is active low, we start disabelling it by making it high! + GPIO.setup(self.pinNumber, GPIO.OUT, initial=GPIO.HIGH) + else: + GPIO.setup(self.pinNumber, GPIO.OUT, initial=GPIO.LOW) else: - GPIO.setup(self.pinNumber, GPIO.OUT, initial=GPIO.LOW) - else: - if self.activeLow: - GPIO.setup(self.pinNumber, GPIO.IN, pull_up_down=GPIO.PUD_UP) - else: - GPIO.setup(self.pinNumber, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) + if self.activeLow: + GPIO.setup(self.pinNumber, GPIO.IN, pull_up_down=GPIO.PUD_UP) + else: + GPIO.setup(self.pinNumber, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) + except: + self._logger.info("Error while configuring GPIO: %s",self.pinNumber) + pass def write(self,active): if self.activeLow: @@ -164,15 +168,18 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, def handleFilamentDetection(self,channel): if self._printer.is_printing(): - #if self._settings.get(["filamentSensorActiveLow"]) and (not GPIO.input(self.filamentSensor.pinNumber)): - if self._settings.get(["filamentSensorActiveLow"]) ^ GPIO.input(self.filamentSensor.pinNumber): + activeLow = self._settings.get(["filamentSensorActiveLow"]) + gpioStatus = GPIO.input(self.filamentSensor.pinNumber) + + if self._settings.get(["debug"]) == True: + self._logger.info("DEBUG -> Filament detection active low: %s gpio status: %s",activeLow,gpioStatus) + if activeLow ^ gpioStatus: self._logger.info("Detected end of filament.") for line in self._settings.get(["filamentSensorGcode"]).split(';'): if line: self._printer.commands(line.strip().capitalize()) self._logger.info("Sending GCODE command: %s",line.strip().capitalize()) - def stopFilamentDetection(self): try: GPIO.remove_event_detect(self.filamentSensor.pinNumber)