diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index 0f297f7..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: @@ -85,14 +89,13 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, self.filamentSensor = EnclosureGPIO(self._settings.get_int(["filamentSensorPin"]),"filamentSensor",self._settings.get(["filamentSensorActiveLow"]), self._settings.get(["filamentSensorEnable"]),False,False,0,False) - self.io1.configureGPIO() self.io2.configureGPIO() self.io3.configureGPIO() self.io4.configureGPIO() self.heater.configureGPIO() self.filamentSensor.configureGPIO() - + self._settings.set(["useCelsius"],not self._settings.get(["useFahrenheit"])) def startTimer(self): @@ -107,46 +110,46 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, return 0 def checkEnclosureTemp(self): - if self._settings.get(["dhtModel"]) == 1820 or self._settings.get(["dhtModel"]) == '1820': - stdout = Popen("sudo "+self._settings.get(["getTempScript"])+" "+str(self._settings.get(["dhtModel"])), shell=True, stdout=PIPE).stdout - else: - stdout = Popen("sudo "+self._settings.get(["getTempScript"])+" "+str(self._settings.get(["dhtModel"]))+" "+str(self._settings.get(["dhtPin"])), shell=True, stdout=PIPE).stdout - sTemp = stdout.read() - if self._settings.get(["debug"]) == True and self._settings.get(["heaterEnable"]) == True: - self._logger.info("DEBUG -> Reading temperature stdout: %s",stdout) - sTemp.replace(" ", "") - fTemp = self.toFloat(sTemp) - if sTemp.find("Failed") != -1 or fTemp == 0: - if self._settings.get(["heaterEnable"]) == True: + if self._settings.get(["temperatureReadingEnable"]): + if self._settings.get(["dhtModel"]) == 1820 or self._settings.get(["dhtModel"]) == '1820': + stdout = Popen("sudo "+self._settings.get(["getTempScript"])+" "+str(self._settings.get(["dhtModel"])), shell=True, stdout=PIPE).stdout + else: + stdout = Popen("sudo "+self._settings.get(["getTempScript"])+" "+str(self._settings.get(["dhtModel"]))+" "+str(self._settings.get(["dhtPin"])), shell=True, stdout=PIPE).stdout + sTemp = stdout.read() + if self._settings.get(["debug"]) == True: + self._logger.info("DEBUG -> Reading temperature stdout: %s",stdout) + sTemp.replace(" ", "") + fTemp = self.toFloat(sTemp) + if sTemp.find("Failed") != -1 or fTemp == 0: self._logger.info("Failed to read Temperature") - else: - self.enclosureCurrentTemperature = fTemp*1.8 + 32 if self._settings.get(["useFahrenheit"]) else fTemp + else: + self.enclosureCurrentTemperature = fTemp*1.8 + 32 if self._settings.get(["useFahrenheit"]) else fTemp - if self._settings.get(["dhtModel"]) != '1820': - stdout = Popen("sudo "+self._settings.get(["getHumiScript"])+" "+str(self._settings.get(["dhtModel"]))+" "+str(self._settings.get(["dhtPin"])), shell=True, stdout=PIPE).stdout - sHum = stdout.read() - if self._settings.get(["debug"]) == True and self._settings.get(["heaterEnable"]) == True: - self._logger.info("DEBUG -> Reading humidity stdout: %s",stdout) + if self._settings.get(["dhtModel"]) != '1820': + stdout = Popen("sudo "+self._settings.get(["getHumiScript"])+" "+str(self._settings.get(["dhtModel"]))+" "+str(self._settings.get(["dhtPin"])), shell=True, stdout=PIPE).stdout + sHum = stdout.read() + if self._settings.get(["debug"]) == True: + self._logger.info("DEBUG -> Reading humidity stdout: %s",stdout) sHum.replace(" ", "") fHum = self.toFloat(sHum) if sHum.find("Failed") != -1 or fHum == 0: - if self._settings.get(["heaterEnable"]) == True: - self._logger.info("Failed to read Humidity") + self._logger.info("Failed to read Humidity") else: self.enclosureCurrentHumidity = fHum - self._plugin_manager.send_plugin_message(self._identifier, dict(enclosuretemp=self.enclosureCurrentTemperature,enclosureHumidity=self.enclosureCurrentHumidity)) - self.heaterHandler() + self._plugin_manager.send_plugin_message(self._identifier, dict(enclosuretemp=self.enclosureCurrentTemperature,enclosureHumidity=self.enclosureCurrentHumidity)) + self.heaterHandler() def heaterHandler(self): - self.currrentHeaterStatus = self.enclosureCurrentTemperature Filament detection active low: %s gpio status: %s",activeLow,gpioStatus) + if activeLow ^ gpioStatus: self._logger.info("Detected end of filament.") - self._printer.toggle_pause_print() - elif (not self._settings.get(["filamentSensorActiveLow"])) and GPIO.input(self.filamentSensor.pinNumber): - self._logger.info("Detected end of filament.") - self._printer.toggle_pause_print() + 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: @@ -232,13 +240,14 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, scheduler.enter(self.toFloat(self.io3.timeDelay), 1, self.io3.write, (True,)) if self.io4.autoStartup and self.io4.enable: scheduler.enter(self.toFloat(self.io4.timeDelay), 1, self.io4.write, (True,)) + scheduler.run() elif event in (Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED): if self.filamentSensor.enable: self.stopFilamentDetection() if self.heater.enable: - self.enclosureSetTemperature = 0 + self.enclosureSetTemperature = 0 if self.io1.autoShutDown and self.io1.enable: scheduler.enter(self.toFloat(self.io1.timeDelay), 1, self.io1.write, (False,)) @@ -258,6 +267,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, def get_settings_defaults(self): return dict( debug=False, + temperatureReadingEnable=False, heaterEnable=False, heaterPin=17, heaterActiveLow=True, @@ -268,6 +278,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, filamentSensorPin=24, filamentSensorEnable=True, filamentSensorActiveLow=True, + filamentSensorGcode="M600;", dhtModel=2302, io1Pin=18, io2Pin=23, diff --git a/octoprint_enclosure/static/js/enclosure.js b/octoprint_enclosure/static/js/enclosure.js index 29c7156..4cd7e8b 100644 --- a/octoprint_enclosure/static/js/enclosure.js +++ b/octoprint_enclosure/static/js/enclosure.js @@ -9,8 +9,8 @@ $(function() { self.enclosureSetTemperature = ko.observable(); self.enclosureHumidity = ko.observable(); - self.onBeforeBinding = function () { - + self.onStartupComplete = function () { + correctCheckBoxStatus(); }; self.onDataUpdaterPluginMessage = function(plugin, data) { @@ -90,7 +90,7 @@ $(function() { } ADDITIONAL_VIEWMODELS.push([ - EnclosureViewModel, + EnclosureViewModel, ["settingsViewModel","connectionViewModel"], [document.getElementById("tab_plugin_enclosure")] ]); @@ -100,3 +100,11 @@ function isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); } +function correctCheckBoxStatus() { + if($('#enableTemperatureReading').is(':checked')){ + $('#enableHeater').prop('disabled', false); + }else{ + $('#enableHeater').prop('disabled', true); + $('#enableHeater').prop('checked', false); + } +} diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2 index 8b9b0b2..6a85c9e 100644 --- a/octoprint_enclosure/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/templates/enclosure_settings.jinja2 @@ -1,29 +1,11 @@ -

{{ _('Heater') }}

-
-
-
- -
-
-
- -
- -
-
-
- -
-
- -

{{ _('Temperature Sensor') }}

Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS18B20 1-wire temperature sensor +
+ +
@@ -55,6 +37,28 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
+

{{ _('Heater') }}

+
+
+
+ +
+
+
+ +
+ +
+
+
+ +
+
+

{{ _('IO 1') }}

@@ -236,6 +240,12 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1 {{ _('Active Low') }}
+
+ +
+ +
+

{{ _('Debug / Other') }}

diff --git a/setup.py b/setup.py index 30a3e01..d36596a 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_package = "octoprint_enclosure" plugin_name = "OctoPrint-Enclosure" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "2.1" +plugin_version = "2.2" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module