From bfdf8bfcedf6ad293ada3ecf706838749721af21 Mon Sep 17 00:00:00 2001 From: Vitor de Miranda Henrique Date: Thu, 9 Mar 2017 16:43:05 -0600 Subject: [PATCH] Features improvement --- octoprint_enclosure/__init__.py | 58 ++-- octoprint_enclosure/static/js/enclosure.js | 42 ++- .../templates/enclosure_settings.jinja2 | 310 +++++++++++++----- .../templates/enclosure_tab.jinja2 | 72 ++-- setup.py | 2 +- 5 files changed, 335 insertions(+), 149 deletions(-) diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index e1ee378..f37433a 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -13,7 +13,7 @@ import os scheduler = sched.scheduler(time.time, time.sleep) class EnclosureGPIO(): - def __init__(self, pinNumber, label, activeLow, enable, autoShutDown,isOutput,timeDelay,autoStartup): + def __init__(self, pinNumber, label, activeLow, enable,autoStartup, autoShutDown,isOutput,timeDelay,timeOffDelay): self.pinNumber = pinNumber self.label = label self.activeLow = activeLow @@ -22,6 +22,7 @@ class EnclosureGPIO(): self.autoStartup = autoStartup self.isOutput = isOutput self.timeDelay = timeDelay + self.timeOffDelay = timeOffDelay def configureGPIO(self): try: @@ -58,6 +59,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, enclosureSetTemperature=0.0 enclosureCurrentTemperature=0.0 enclosureCurrentHumidity=0.0 + lastFilamentEndDetected=0 def startGPIO(self): if self._settings.get(["useBoardPinNumber"]): GPIO.cleanup() @@ -68,26 +70,31 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, GPIO.setwarnings(False) self.io1 = EnclosureGPIO(self._settings.get_int(["io1Pin"]),self._settings.get(["io1Label"]),self._settings.get(["io1ActiveLow"]), - self._settings.get(["io1Enable"]),self._settings.get(["io1AutoShutDown"]),True,self._settings.get(["io1TimeDelay"]), - self._settings.get(["io1AutoStartup"])) + self._settings.get(["io1Enable"]),self._settings.get(["io1AutoStartup"]), + self._settings.get(["io1AutoShutDown"]),True,self._settings.get(["io1TimeDelay"]), + self._settings.get(["io1OffTimeDelay"])) self.io2 = EnclosureGPIO(self._settings.get_int(["io2Pin"]),self._settings.get(["io2Label"]),self._settings.get(["io2ActiveLow"]), - self._settings.get(["io2Enable"]),self._settings.get(["io2AutoShutDown"]),True,self._settings.get(["io2TimeDelay"]), - self._settings.get(["io2AutoStartup"])) + self._settings.get(["io2Enable"]),self._settings.get(["io2AutoStartup"]), + self._settings.get(["io2AutoShutDown"]),True,self._settings.get(["io2TimeDelay"]), + self._settings.get(["io2OffTimeDelay"])) self.io3 = EnclosureGPIO(self._settings.get_int(["io3Pin"]),self._settings.get(["io3Label"]),self._settings.get(["io3ActiveLow"]), - self._settings.get(["io3Enable"]),self._settings.get(["io3AutoShutDown"]),True,self._settings.get(["io3TimeDelay"]), - self._settings.get(["io3AutoStartup"])) + self._settings.get(["io3Enable"]),self._settings.get(["io3AutoStartup"]), + self._settings.get(["io3AutoShutDown"]),True,self._settings.get(["io3TimeDelay"]), + self._settings.get(["io3OffTimeDelay"])) self.io4 = EnclosureGPIO(self._settings.get_int(["io4Pin"]),self._settings.get(["io4Label"]),self._settings.get(["io4ActiveLow"]), - self._settings.get(["io4Enable"]),self._settings.get(["io4AutoShutDown"]),True,self._settings.get(["io4TimeDelay"]), - self._settings.get(["io4AutoStartup"])) + self._settings.get(["io4Enable"]),self._settings.get(["io4AutoStartup"]), + self._settings.get(["io4AutoShutDown"]),True,self._settings.get(["io4TimeDelay"]), + self._settings.get(["io4OffTimeDelay"])) self.heater = EnclosureGPIO(self._settings.get_int(["heaterPin"]),"heater",self._settings.get(["heaterActiveLow"]), - self._settings.get(["heaterEnable"]),True,True,0,False) + self._settings.get(["heaterEnable"]),False,True,True,0,0) - self.filamentSensor = EnclosureGPIO(self._settings.get_int(["filamentSensorPin"]),"filamentSensor",self._settings.get(["filamentSensorActiveLow"]), - self._settings.get(["filamentSensorEnable"]),False,False,0,False) + self.filamentSensor = EnclosureGPIO(self._settings.get_int(["filamentSensorPin"]),"filamentSensor", + self._settings.get(["filamentSensorActiveLow"]),self._settings.get(["filamentSensorEnable"]), + False,False,False,0,0) self.io1.configureGPIO() self.io2.configureGPIO() @@ -174,11 +181,15 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, 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()) + if time.time() - lastFilamentEndDetected > self._settings.get(["filamentSensorTimeout"]): + self._logger.info("Detected end of filament.") + lastFilamentEndDetected = time.time() + 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()) + else: + self._logger.info("Prevented end of filament detection, filament sensor timeout not elapsed.") def stopFilamentDetection(self): try: @@ -250,13 +261,13 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, self.enclosureSetTemperature = 0 if self.io1.autoShutDown and self.io1.enable: - scheduler.enter(self.toFloat(self.io1.timeDelay), 1, self.io1.write, (False,)) + scheduler.enter(self.toFloat(self.io1.timeOffDelay), 1, self.io1.write, (False,)) if self.io2.autoShutDown and self.io2.enable: - scheduler.enter(self.toFloat(self.io2.timeDelay), 1, self.io2.write, (False,)) + scheduler.enter(self.toFloat(self.io2.timeOffDelay), 1, self.io2.write, (False,)) if self.io3.autoShutDown and self.io3.enable: - scheduler.enter(self.toFloat(self.io3.timeDelay), 1, self.io3.write, (False,)) + scheduler.enter(self.toFloat(self.io3.timeOffDelay), 1, self.io3.write, (False,)) if self.io4.autoShutDown and self.io4.enable: - scheduler.enter(self.toFloat(self.io4.timeDelay), 1, self.io4.write, (False,)) + scheduler.enter(self.toFloat(self.io4.timeOffDelay), 1, self.io4.write, (False,)) scheduler.run() #~~ SettingsPlugin mixin @@ -279,6 +290,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, filamentSensorEnable=True, filamentSensorActiveLow=True, filamentSensorGcode="M600;", + filamentSensorTimeout=120, dhtModel=2302, io1Pin=18, io2Pin=23, @@ -308,6 +320,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, io2TimeDelay=0, io3TimeDelay=0, io4TimeDelay=0, + io1OffTimeDelay=0, + io2OffTimeDelay=0, + io3OffTimeDelay=0, + io4OffTimeDelay=0, getTempScript="~/.octoprint/plugins/OctoPrint-Enclosure/extras/GetTemperature.py", getHumiScript="~/.octoprint/plugins/OctoPrint-Enclosure/extras/GetHumidity.py" ) diff --git a/octoprint_enclosure/static/js/enclosure.js b/octoprint_enclosure/static/js/enclosure.js index 4cd7e8b..4569425 100644 --- a/octoprint_enclosure/static/js/enclosure.js +++ b/octoprint_enclosure/static/js/enclosure.js @@ -10,7 +10,7 @@ $(function() { self.enclosureHumidity = ko.observable(); self.onStartupComplete = function () { - correctCheckBoxStatus(); + fixUI(); }; self.onDataUpdaterPluginMessage = function(plugin, data) { @@ -100,11 +100,49 @@ function isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); } -function correctCheckBoxStatus() { +function fixUI() { if($('#enableTemperatureReading').is(':checked')){ $('#enableHeater').prop('disabled', false); + $('#temperature_reading_content').show("blind"); }else{ $('#enableHeater').prop('disabled', true); $('#enableHeater').prop('checked', false); + $('#temperature_reading_content').hide("blind"); + } + + if($('#enableHeater').is(':checked')){ + $('#heater_content').show("blind"); + }else{ + $('#heater_content').hide("blind"); + } + + if($('#io1_enabled').is(':checked')){ + $('#io1_content').show("blind"); + }else{ + $('#io1_content').hide("blind"); + } + + if($('#io2_enabled').is(':checked')){ + $('#io2_content').show("blind"); + }else{ + $('#io2_content').hide("blind"); + } + + if($('#io3_enabled').is(':checked')){ + $('#io3_content').show("blind"); + }else{ + $('#io3_content').hide("blind"); + } + + if($('#io4_enabled').is(':checked')){ + $('#io4_content').show("blind"); + }else{ + $('#io4_content').hide("blind"); + } + + if($('#filament_sensor_enable').is(':checked')){ + $('#filament_sensor_content').show("blind"); + }else{ + $('#filament_sensor_content').hide("blind"); } } diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2 index 6a85c9e..dc2a759 100644 --- a/octoprint_enclosure/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/templates/enclosure_settings.jinja2 @@ -1,39 +1,45 @@

{{ _('Temperature Sensor') }}

-Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS18B20 1-wire temperature sensor
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- +
+
+ +
+ + GPIO pin for temperature sensor, recommended to use 4 as DS18B20 only works on pin 4 +
+
+
+ +
+ + Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS18B20 1-wire temperature sensor +
+
+
+ +
+ + Location of script that reads temperature +
+
+
+ +
+ + Location of script that reads humidity +
+
+
+ + Choose if you want to work with Celsius or Fahrenheit +
@@ -42,20 +48,24 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
-
- -
- -
-
-
- +
+
+ +
+ + GPIO pin used to control Heater. You can not use GPIO 4 here +
+
+
+ + Active low means that the heater will turn on when receive a low signal (groud) from Raspbery PI +
@@ -64,38 +74,63 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
-
+
+
+ Name displayed on Enclosure Tab
+
+
+ GPIO number that will be controlled. You can not use GPIO 4 here
+
+
+ Active low means that the GPIO will turn on when receive a low signal (groud) from Raspbery PI
+
+
+ Choose if GPIO should turn on automatomatically when print starts
+
+
+ +
+ + Time delay to turn on GPIO when print starts +
+
+
+ Choose if GPIO should turn off automatomatically when print finishes
- +
+
+
- + + Time delay to turn off GPIO when print finishes
+
@@ -104,78 +139,129 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
-
+
+
+ Name displayed on Enclosure Tab
+
+
+ GPIO number that will be controlled. You can not use GPIO 4 here
+
+
+ Active low means that the GPIO will turn on when receive a low signal (groud) from Raspbery PI
+
+
+ Choose if GPIO should turn on automatomatically when print starts
+
+
+ +
+ + Time delay to turn on GPIO when print starts +
+
+
+ Choose if GPIO should turn off automatomatically when print finishes
- +
+
+
- + + Time delay to turn off GPIO when print finishes
+
+

{{ _('IO 3') }}

-
+
+
+ Name displayed on Enclosure Tab
+
+
+ GPIO number that will be controlled. You can not use GPIO 4 here
+
+
+ Active low means that the GPIO will turn on when receive a low signal (groud) from Raspbery PI
+
+
+ Choose if GPIO should turn on automatomatically when print starts
+
+
+ +
+ + Time delay to turn on GPIO when print starts +
+
+
+ Choose if GPIO should turn off automatomatically when print finishes
- +
+
+
- + + Time delay to turn off GPIO when print finishes
+
@@ -184,84 +270,128 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
-
+
+
+ Name displayed on Enclosure Tab
+
+
+ GPIO number that will be controlled. You can not use GPIO 4 here
+
+
+ Active low means that the GPIO will turn on when receive a low signal (groud) from Raspbery PI
+
+
+ Choose if GPIO should turn on automatomatically when print starts
+
+
+ +
+ + Time delay to turn on GPIO when print starts +
+
+
+ Choose if GPIO should turn off automatomatically when print finishes
- +
+
+
- + + Time delay to turn off GPIO when print finishes
+
-

{{ _('Filament Sensor') }}

-
- -
- -
-
-
- -
-
- +
+
+ +
+ + GPIO number that will be used to sense end of filament. You can not use GPIO 4 here +
+
- + + Active low means that end of the filament was detected when receive a low signal (groud) from filament sensor +
+
+ +
+ + GCODE that will be sent to the printer to pause and allow filament to be changed. + You should add ; on the end of every line sent to the printer +
-

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

-
-
-
- -
-
-
-
- -
-
-
+ + + +
+
+
+
+ + Log adcitional information on octoprint log to help trouble shoot the plugin +
+
+
+
+ + Use BOARD pin numbers instead of BCM pin numbers +
+
+ +
+ + Time that filament sensor will be inactive after sensing end of filament. This is to avoid sending multiple M600 + commands to the printer. +
+
+
diff --git a/octoprint_enclosure/templates/enclosure_tab.jinja2 b/octoprint_enclosure/templates/enclosure_tab.jinja2 index 6f46508..d1b6c66 100644 --- a/octoprint_enclosure/templates/enclosure_tab.jinja2 +++ b/octoprint_enclosure/templates/enclosure_tab.jinja2 @@ -1,38 +1,40 @@ -

{{ _('Heater') }}

- - - - - - - - - - - - - - - - -
{{ _('Actual') }}{{ _('Target') }}
{{ _('Enclosure') }} -
- - °C - °F -
- - - -
-
-
{{ _('Humidity') }}
+
+

{{ _('Heater') }}

+ + + + + + + + + + + + + + + + +
{{ _('Actual') }}{{ _('Target') }}
{{ _('Enclosure') }} +
+ + °C + °F +
+ + + +
+
+
{{ _('Humidity') }}
+

diff --git a/setup.py b/setup.py index d36596a..064ec63 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.2" +plugin_version = "2.3" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module