From cf17cfb5bb4cbe8388e02def603c581e1e3e35eb Mon Sep 17 00:00:00 2001 From: Vitor de Miranda Henrique Date: Tue, 17 Nov 2015 00:46:10 -0600 Subject: [PATCH] version 1.0 --- README.md | 6 ++-- octoprint_enclosure/__init__.py | 10 ++++-- octoprint_enclosure/static/css/README.txt | 1 - octoprint_enclosure/static/js/README.txt | 1 - octoprint_enclosure/static/js/enclosure.js | 35 ++++++++++++++----- octoprint_enclosure/static/less/README.txt | 1 - .../templates/enclosure_settings.jinja2 | 14 +++++--- .../templates/enclosure_tab.jinja2 | 8 ++--- translations/README.txt | 28 --------------- 9 files changed, 50 insertions(+), 54 deletions(-) delete mode 100644 octoprint_enclosure/static/css/README.txt delete mode 100644 octoprint_enclosure/static/js/README.txt delete mode 100644 octoprint_enclosure/static/less/README.txt delete mode 100644 translations/README.txt diff --git a/README.md b/README.md index 56d4e85..3c47650 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ I used relays connected to the raspberry pi to control my heaters, fan and light For heating my enclosure I got a $15 [lasko](http://www.amazon.com/gp/product/B003XDTWN2?psc=1&redirect=true&ref_=oh_aui_search_detailpage) inside my encosure. I opened it and added a relay to the mains wire. -**CAUTION: VOLTAGE ON MAINS WIRE CAN KILL YOU, ONLY ATTEMPT TO DO THIS IF YOU KNOW WHAT YOU ARE DOING, AND DO AT YOUR OWN RISK** +**CAUTION: VOLTAGE ON MAINS WIRE CAN KILL YOU, ONLY ATTEMPT TO DO THIS IF YOU KNOW WHAT YOU ARE DOING, AND DO AT YOUR OWN RISK ** **CAUTION 2: THIS HEATER IS NOT INTENDED TO FUNCTION THIS WAY AND IT MIGHT BE A FIRE HAZARD. DO IT AT YOUR OWN RISK** -The relays module that I used can be found [here](http://www.amazon.com/gp/product/B0057OC6D8?psc=1&redirect=true&ref_=oh_aui_search_detailpage). You need active-low configuration on it (jumper between JD-VCC). +The relays module that I used can be found [here](http://www.amazon.com/gp/product/B0057OC6D8?psc=1&redirect=true&ref_=oh_aui_search_detailpage). Those relays are active low, that means that they will turn on when you put LOW on the output of your pin. In orther to not fry your r-pi connect 3.3v to VCC, 5V to JD-VCC and Ground to GND. ## Setup @@ -60,4 +60,4 @@ Pin 18 connected to the relay that controls the heater Those settings are configurable, as well the location of the python scripts to read temperature and humidity. -You can also enable and disable features off the plugin. For example disable the heater feature. +You can also enable and disable features off the plugin. For example disable the heater feature. \ No newline at end of file diff --git a/octoprint_enclosure/__init__.py b/octoprint_enclosure/__init__.py index c2ea2e5..2ac9334 100644 --- a/octoprint_enclosure/__init__.py +++ b/octoprint_enclosure/__init__.py @@ -52,10 +52,12 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, self.heaterHandler() def heaterHandler(self): + command="" if self.enclosureCurrentTemperature /sys/class/gpio/gpio"+str(self._settings.get_int(["heaterPin"]))+"/value") + command = "sudo echo 0 > /sys/class/gpio/gpio"+str(self._settings.get_int(["heaterPin"]))+"/value" else: - os.system("sudo echo 1 > /sys/class/gpio/gpio"+str(self._settings.get_int(["heaterPin"]))+"/value") + command = "sudo echo 1 > /sys/class/gpio/gpio"+str(self._settings.get_int(["heaterPin"]))+"/value" + os.system(command) #~~ StartupPlugin mixin def on_after_startup(self): @@ -81,7 +83,9 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, @octoprint.plugin.BlueprintPlugin.route("/handleFan", methods=["GET"]) def handleFan(self): + self._logger.info("Caiu no Fan") if self._settings.get_boolean(["fanEnable"]): + self._logger.info("Fan: " + flask.request.values["status"]) if flask.request.values["status"] == "on": os.system("sudo echo 0 > /sys/class/gpio/gpio"+str(self._settings.get_int(["fanPin"]))+"/value") else: @@ -129,7 +133,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, return dict( heaterEnable=False, heaterPin=18, - fanPin=14, + fanPin=23, lightPin=15, dhtPin=4, dhtModel=22, diff --git a/octoprint_enclosure/static/css/README.txt b/octoprint_enclosure/static/css/README.txt deleted file mode 100644 index 1803f70..0000000 --- a/octoprint_enclosure/static/css/README.txt +++ /dev/null @@ -1 +0,0 @@ -Have your plugin's CSS files generated to here. \ No newline at end of file diff --git a/octoprint_enclosure/static/js/README.txt b/octoprint_enclosure/static/js/README.txt deleted file mode 100644 index 6705398..0000000 --- a/octoprint_enclosure/static/js/README.txt +++ /dev/null @@ -1 +0,0 @@ -Put your plugin's javascript files here. \ No newline at end of file diff --git a/octoprint_enclosure/static/js/enclosure.js b/octoprint_enclosure/static/js/enclosure.js index 5b6e133..23767e8 100644 --- a/octoprint_enclosure/static/js/enclosure.js +++ b/octoprint_enclosure/static/js/enclosure.js @@ -22,8 +22,7 @@ $(function() { }; self.isConnected = ko.computed(function() { - //return self.connection.isOperational(); - return true; + return self.connection.loginState.isUser(); }); self.setTemperature = function(){ @@ -81,22 +80,41 @@ $(function() { return "off"; } - self.turnFanOn = function(isON){ + self.turnFanOn = function(){ $.ajax({ type: "GET", dataType: "json", - data: {"status": isON ? "on" : "off"}, - url: "/plugin/enclosure/getEnclosureTemperature", + data: {"status": "on"}, + url: "/plugin/enclosure/handleFan", + async: false + }); + } + + self.turnFanOff = function(){ + $.ajax({ + type: "GET", + dataType: "json", + data: {"status": "off"}, + url: "/plugin/enclosure/handleFan", async: false }); } - self.turnLightOn = function(isON){ + self.turnLightOn = function(){ $.ajax({ type: "GET", dataType: "json", - data: {"status": isON ? "on" : "off"}, - url: "/plugin/enclosure/getEnclosureTemperature", + data: {"status":"on"}, + url: "/plugin/enclosure/handleLight", + async: false + }); + } + self.turnLightOff = function(){ + $.ajax({ + type: "GET", + dataType: "json", + data: {"status":"off"}, + url: "/plugin/enclosure/handleLight", async: false }); } @@ -112,3 +130,4 @@ $(function() { function isNumeric(n) { return !isNaN(parseFloat(n)) && isFinite(n); } + diff --git a/octoprint_enclosure/static/less/README.txt b/octoprint_enclosure/static/less/README.txt deleted file mode 100644 index 023008f..0000000 --- a/octoprint_enclosure/static/less/README.txt +++ /dev/null @@ -1 +0,0 @@ -Put your plugin's LESS files here, have them generated to ../css. \ No newline at end of file diff --git a/octoprint_enclosure/templates/enclosure_settings.jinja2 b/octoprint_enclosure/templates/enclosure_settings.jinja2 index e4d399f..69671ae 100644 --- a/octoprint_enclosure/templates/enclosure_settings.jinja2 +++ b/octoprint_enclosure/templates/enclosure_settings.jinja2 @@ -15,12 +15,16 @@ + +

{{ _('Temperature Sensor') }}

- -Available options are: -11 for DHT11 -22 for DHT22 -2302 for AM2302 +Available options are: 11 for DHT11; 22 for DHT22 and 2302 for AM2302 +
+ +
+ +
+
diff --git a/octoprint_enclosure/templates/enclosure_tab.jinja2 b/octoprint_enclosure/templates/enclosure_tab.jinja2 index 585c4d0..ea3d87a 100644 --- a/octoprint_enclosure/templates/enclosure_tab.jinja2 +++ b/octoprint_enclosure/templates/enclosure_tab.jinja2 @@ -33,11 +33,11 @@

{{ _('Fan') }}

- - + +

{{ _('Light') }}

- - + + diff --git a/translations/README.txt b/translations/README.txt deleted file mode 100644 index 7edeefe..0000000 --- a/translations/README.txt +++ /dev/null @@ -1,28 +0,0 @@ -Your plugin's translations will reside here. The provided setup.py supports a -couple of additional commands to make managing your translations easier: - -babel_extract - Extracts any translateable messages (marked with Jinja's `_("...")` or - JavaScript's `gettext("...")`) and creates the initial `messages.pot` file. -babel_refresh - Reruns extraction and updates the `messages.pot` file. -babel_new --locale= - Creates a new translation folder for locale ``. -babel_compile - Compiles the translations into `mo` files, ready to be used within - OctoPrint. -babel_pack --locale= [ --author= ] - Packs the translation for locale `` up as an installable - language pack that can be manually installed by your plugin's users. This is - interesting for languages you can not guarantee to keep up to date yourself - with each new release of your plugin and have to depend on contributors for. - -If you want to bundle translations with your plugin, create a new folder -`octoprint_enclosure/translations`. When that folder exists, -an additional command becomes available: - -babel_bundle --locale= - Moves the translation for locale `` to octoprint_enclosure/translations, - effectively bundling it with your plugin. This is interesting for languages - you can guarantee to keep up to date yourself with each new release of your - plugin.