1.6 Release

This commit is contained in:
Vitor de Miranda Henrique
2017-03-01 10:27:25 -06:00
parent a9d4da9c34
commit f1101c97b3
9 changed files with 135 additions and 94 deletions

View File

@@ -1,17 +0,0 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
root = true
[*]
end_of_line = lf
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true
[**.py]
indent_style = tab
[**.js]
indent_style = space
indent_size = 4

9
.gitignore vendored
View File

@@ -1,9 +0,0 @@
*.pyc
*.swp
.idea
*.iml
build
dist
*.egg*
.DS_Store
*.zip

View File

@@ -1 +0,0 @@
include README.md

View File

@@ -1,6 +0,0 @@
[python: */**.py]
[jinja2: */**.jinja2]
extensions=jinja2.ext.autoescape, jinja2.ext.with_
[javascript: */**.js]
extract_messages = gettext, ngettext

View File

@@ -1,11 +1,10 @@
# coding=utf-8
from __future__ import absolute_import
from octoprint.events import eventManager, Events
from octoprint.util import RepeatedTimer
from subprocess import Popen, PIPE
import octoprint.plugin
import RPi.GPIO as GPIO
import RPi.GPIO as GPIO
import flask
import sched
import time
@@ -14,12 +13,13 @@ import os
scheduler = sched.scheduler(time.time, time.sleep)
class EnclosureGPIO():
def __init__(self, pinNumber, label, activeLow, enable, autoShutDown,isOutput,timeDelay):
def __init__(self, pinNumber, label, activeLow, enable, autoShutDown,isOutput,timeDelay,autoStartup):
self.pinNumber = pinNumber
self.label = label
self.activeLow = activeLow
self.enable = enable
self.autoShutDown = autoShutDown
self.autoStartup = autoStartup
self.isOutput = isOutput
self.timeDelay = timeDelay
@@ -30,7 +30,10 @@ class EnclosureGPIO():
else:
GPIO.setup(self.pinNumber, GPIO.OUT, initial=GPIO.LOW)
else:
GPIO.setup(self.pinNumber, GPIO.IN, pull_up_down=GPIO.PUD_UP)
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)
def write(self,active):
if self.activeLow:
@@ -45,28 +48,40 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
octoprint.plugin.BlueprintPlugin,
octoprint.plugin.EventHandlerPlugin):
previousHeaterStatus = False
currentHeaterStatus = False
enclosureSetTemperature=0.0
enclosureCurrentTemperature=0.0
enclosureCurrentHumidity=0.0
def startGPIO(self):
GPIO.setmode(GPIO.BCM)
if self._settings.get(["useBoardPinNumber"]):
GPIO.setmode(GPIO.BOARD)
else:
GPIO.setmode(GPIO.BCM)
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(["io1Enable"]),self._settings.get(["io1AutoShutDown"]),True,self._settings.get(["io1TimeDelay"]),
self._settings.get(["io1AutoStartup"]))
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(["io2Enable"]),self._settings.get(["io2AutoShutDown"]),True,self._settings.get(["io2TimeDelay"]),
self._settings.get(["io2AutoStartup"]))
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(["io3Enable"]),self._settings.get(["io3AutoShutDown"]),True,self._settings.get(["io3TimeDelay"]),
self._settings.get(["io3AutoStartup"]))
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(["io4Enable"]),self._settings.get(["io4AutoShutDown"]),True,self._settings.get(["io4TimeDelay"]),
self._settings.get(["io4AutoStartup"]))
self.heater = EnclosureGPIO(self._settings.get_int(["heaterPin"]),"heater",self._settings.get(["heaterActiveLow"]), self._settings.get(["heaterEnable"]),True,True,0)
self.heater = EnclosureGPIO(self._settings.get_int(["heaterPin"]),"heater",self._settings.get(["heaterActiveLow"]),
self._settings.get(["heaterEnable"]),True,True,0,False)
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",False,self._settings.get(["filamentSensorEnable"]),False,False,0)
self.io1.configureGPIO()
self.io2.configureGPIO()
@@ -74,6 +89,8 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
self.io4.configureGPIO()
self.heater.configureGPIO()
self.filamentSensor.configureGPIO()
self._settings.set(["useCelsius"],not self._settings.get(["useFahrenheit"]))
def startTimer(self):
self._checkTempTimer = RepeatedTimer(10, self.checkEnclosureTemp, None, None, True)
@@ -84,7 +101,6 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
val = float(value)
return val
except:
self._logger.info("Failed to convert to float")
return 0
def checkEnclosureTemp(self):
@@ -93,33 +109,39 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
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(" ", "")
if sTemp.find("Failed") != -1:
fTemp = self.toFloat(sTemp)
if sTemp.find("Failed") != -1 or fTemp == 0:
self._logger.info("Failed to read Temperature")
else:
#self._logger.info(sTemp)
self.enclosureCurrentTemperature = self.toFloat(sTemp)
#self._logger.info("enclosureCurrentTemperature is: %s",self.enclosureCurrentTemperature)
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:
self._logger.info("DEBUG -> Reading humidity stdout: %s",stdout)
sHum.replace(" ", "")
if sHum.find("Failed") != -1:
fHum = self.toFloat(sHum)
if sHum.find("Failed") != -1 or fHum == 0:
self._logger.info("Failed to read Humidity")
else:
# self._logger.info(sHum)
self.enclosureCurrentHumidity = self.toFloat(sHum)
self.enclosureCurrentHumidity = fHum
self._plugin_manager.send_plugin_message(self._identifier, dict(enclosuretemp=self.enclosureCurrentTemperature,enclosureHumidity=self.enclosureCurrentHumidity))
self.heaterHandler()
def heaterHandler(self):
if self.enclosureCurrentTemperature<float(self.enclosureSetTemperature) and self.heater.enable:
self._logger.info("Turning heater on.")
self.heater.write(True)
else:
self._logger.info("Turning heater off.")
self.heater.write(False)
self.currrentHeaterStatus = self.enclosureCurrentTemperature<float(self.enclosureSetTemperature)
if self.currentHeaterStatus != self.previousHeaterStatus:
if self.currentHeaterStatus and self.heater.enable:
self._logger.info("Turning heater on.")
self.heater.write(True)
else:
self._logger.info("Turning heater off.")
self.heater.write(False)
self.previousHeaterStatus = self.currentHeaterStatus
def startFilamentDetection(self):
if not GPIO.input(self.filamentSensor.pinNumber):
@@ -131,12 +153,16 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
pass
if self.filamentSensor.pinNumber != -1:
self._logger.info("Started filament detection.")
GPIO.add_event_detect(self.filamentSensor.pinNumber, GPIO.FALLING, callback=self.handleFilamentDetection, bouncetime=300)
if self._settings.get(["filamentSensorActiveLow"]):
GPIO.add_event_detect(self.filamentSensor.pinNumber, GPIO.FALLING, callback=self.handleFilamentDetection, bouncetime=300)
else:
GPIO.add_event_detect(self.filamentSensor.pinNumber, GPIO.RISING, callback=self.handleFilamentDetection, bouncetime=300)
def handleFilamentDetection(self,channel):
if not GPIO.input(self.filamentSensor.pinNumber) and self._printer.is_printing():
self._logger.info("Detected end of filament.")
self._printer.toggle_pause_print()
if self._printer.is_printing():
if ~(self._settings.get(["filamentSensorActiveLow"]) ^ (not GPIO.input(self.filamentSensor.pinNumber))):
self._logger.info("Detected end of filament.")
self._printer.toggle_pause_print()
def stopFilamentDetection(self):
try:
@@ -168,7 +194,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
io = flask.request.values["io"]
value = True if flask.request.values["status"] == "on" else False
if io == "io1":
if io == "io1":
self.io1.write(value)
elif io == "io2":
self.io2.write(value)
@@ -184,6 +210,16 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
if event == Events.PRINT_STARTED:
if self.filamentSensor.enable:
self.startFilamentDetection()
if self.io1.autoStartup:
scheduler.enter(self.toFloat(self.io1.timeDelay), 1, self.io1.write, (True,))
if self.io2.autoStartup:
scheduler.enter(self.toFloat(self.io2.timeDelay), 1, self.io2.write, (True,))
if self.io3.autoStartup:
scheduler.enter(self.toFloat(self.io3.timeDelay), 1, self.io3.write, (True,))
if self.io4.autoStartup:
scheduler.enter(self.toFloat(self.io4.timeDelay), 1, self.io4.write, (True,))
elif event in (Events.PRINT_DONE, Events.PRINT_FAILED, Events.PRINT_CANCELLED):
if self.filamentSensor.enable:
self.stopFilamentDetection()
@@ -201,7 +237,6 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
scheduler.enter(self.toFloat(self.io4.timeDelay), 1, self.io4.write, (False,))
scheduler.run()
#~~ SettingsPlugin mixin
def on_settings_save(self, data):
octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
@@ -209,12 +244,17 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
def get_settings_defaults(self):
return dict(
debug=False,
heaterEnable=False,
heaterPin=17,
heaterActiveLow=True,
dhtPin=4,
useFahrenheit=False,
useCelsius=True,
useBoardPinNumber=False,
filamentSensorPin=24,
filamentSensorEnable=True,
filamentSensorActiveLow=True,
dhtModel=2302,
io1Pin=18,
io2Pin=23,
@@ -236,6 +276,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin,
io2AutoShutDown=True,
io3AutoShutDown=True,
io4AutoShutDown=True,
io1AutoStartup=False,
io2AutoStartup=False,
io3AutoStartup=False,
io4AutoStartup=False,
io1TimeDelay=0,
io2TimeDelay=0,
io3TimeDelay=0,
@@ -281,4 +325,3 @@ def __plugin_load__():
__plugin_hooks__ = {
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
}

View File

@@ -48,6 +48,11 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
<input type="text" class="input-block-level" data-bind="value: settings.plugins.enclosure.getHumiScript">
</div>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.useFahrenheit"> {{ _('Use Fahrenheit Unit') }}
</label>
</div>
</form>
<h4>{{ _('IO 1') }}</h4>
@@ -73,12 +78,17 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io1ActiveLow"> {{ _('Active Low') }}
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io1AutoStartup"> {{ _('Auto Startup') }}
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io1AutoShutDown"> {{ _('Auto Shutdown') }}
</label>
</div>
<label class="control-label" for="settings-enclosure-io1">{{ _('Shutdown Delay (Seconds)') }}</label>
<label class="control-label" for="settings-enclosure-io1">{{ _('Delay (Seconds)') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.enclosure.io1TimeDelay">
</div>
@@ -108,12 +118,17 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io2ActiveLow"> {{ _('Active Low') }}
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io2AutoStartup"> {{ _('Auto Startup') }}
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io2AutoShutDown"> {{ _('Auto Shutdown') }}
</label>
</div>
<label class="control-label" for="settings-enclosure-io1">{{ _('Shutdown Delay (Seconds)') }}</label>
<label class="control-label" for="settings-enclosure-io1">{{ _('Delay (Seconds)') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.enclosure.io2TimeDelay">
</div>
@@ -143,12 +158,17 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io3ActiveLow"> {{ _('Active Low') }}
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io3AutoStartup"> {{ _('Auto Startup') }}
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io3AutoShutDown"> {{ _('Auto Shutdown') }}
</label>
</div>
<label class="control-label" for="settings-enclosure-io1">{{ _('Shutdown Delay (Seconds)') }}</label>
<label class="control-label" for="settings-enclosure-io1">{{ _('Delay (Seconds)') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.enclosure.io3TimeDelay">
</div>
@@ -178,12 +198,17 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io4ActiveLow"> {{ _('Active Low') }}
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io4AutoStartup"> {{ _('Auto Startup') }}
</label>
</div>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.io4AutoShutDown"> {{ _('Auto Shutdown') }}
</label>
</div>
<label class="control-label" for="settings-enclosure-io1">{{ _('Shutdown Delay (Seconds)') }}</label>
<label class="control-label" for="settings-enclosure-io1">{{ _('Delay (Seconds)') }}</label>
<div class="controls">
<input type="text" class="input-block-level" data-bind="value: settings.plugins.enclosure.io4TimeDelay">
</div>
@@ -206,4 +231,27 @@ Available options are: 11 for DHT11; 22 for DHT22; 2302 for AM2302; 1820 for DS1
<input type="text" class="input-block-level" data-bind="value: settings.plugins.enclosure.filamentSensorPin">
</div>
</div>
</form>
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.filamentSensorActiveLow"> {{ _('Active Low') }}
</label>
</div>
</form>
<h4>{{ _('Debug / Other') }}</h4>
<form class="form-horizontal">
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.debug"> {{ _('Enable debug info') }}
</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.plugins.enclosure.useBoardPinNumber"> {{ _('Use Board Pin #') }}
</label>
</div>
</div>
</form>

View File

@@ -11,7 +11,8 @@
<td style="vertical-align: middle; overflow: visible">
<div class="input-append">
<input type="text" class="input-mini text-right tempInput" id="enclosureSetTemp" data-bind="attr: {placeholder: cleanTemperature(requestEnclosureSetTemperature())}">
<span class="add-on">&deg;C</span>
<span class="add-on" data-bind="visible: settings.settings.plugins.enclosure.useCelsius">&deg;C</span>
<span class="add-on" data-bind="visible: settings.settings.plugins.enclosure.useFahrenheit">&deg;F</span>
<div class="btn-group">
<button type="submit" data-bind="click: setTemperature, enable: settings.settings.plugins.enclosure.heaterEnable && isConnected()" class="btn">{{ _('Set') }}</button>
<button class="btn dropdown-toggle" data-toggle="dropdown" data-bind="enable: settings.settings.plugins.enclosure.heaterEnable && isConnected()">
@@ -35,33 +36,24 @@
<div data-bind="visible: settings.settings.plugins.enclosure.io1Enable">
<h4><p data-bind="html: settings.settings.plugins.enclosure.io1Label"></p></h4>
<button type="submit" data-bind="click: handleIO.bind($data, ['io1', 'on']), enable: settings.settings.plugins.enclosure.io1Enable && isConnected()" class="btn">Turn on</button>
<button type="submit" data-bind="click: handleIO.bind($data, ['io1', 'on']), enable: settings.settings.plugins.enclosure.io1Enable && isConnected()" class="btn">Turn on</button>
<button type="submit" data-bind="click: handleIO.bind($data, ['io1', 'off']), enable: settings.settings.plugins.enclosure.io1Enable && isConnected()" class="btn">Turn off</button>
</div>
<div data-bind="visible: settings.settings.plugins.enclosure.io2Enable">
<h4><p data-bind="html: settings.settings.plugins.enclosure.io2Label"></p></h4>
<button type="submit" data-bind="click: handleIO.bind($data, ['io2', 'on']), enable: settings.settings.plugins.enclosure.io2Enable && isConnected()" class="btn">Turn on</button>
<button type="submit" data-bind="click: handleIO.bind($data, ['io2', 'on']), enable: settings.settings.plugins.enclosure.io2Enable && isConnected()" class="btn">Turn on</button>
<button type="submit" data-bind="click: handleIO.bind($data, ['io2', 'off']), enable: settings.settings.plugins.enclosure.io2Enable && isConnected()" class="btn">Turn off</button>
</div>
<div data-bind="visible: settings.settings.plugins.enclosure.io3Enable">
<h4><p data-bind="html: settings.settings.plugins.enclosure.io3Label"></p></h4>
<button type="submit" data-bind="click: handleIO.bind($data, ['io3', 'on']), enable: settings.settings.plugins.enclosure.io3Enable && isConnected()" class="btn">Turn on</button>
<button type="submit" data-bind="click: handleIO.bind($data, ['io3', 'on']), enable: settings.settings.plugins.enclosure.io3Enable && isConnected()" class="btn">Turn on</button>
<button type="submit" data-bind="click: handleIO.bind($data, ['io3', 'off']), enable: settings.settings.plugins.enclosure.io3Enable && isConnected()" class="btn">Turn off</button>
</div>
<div data-bind="visible: settings.settings.plugins.enclosure.io4Enable">
<h4><p data-bind="html: settings.settings.plugins.enclosure.io4Label"></p></h4>
<button type="submit" data-bind="click: handleIO.bind($data, ['io4', 'on']), enable: settings.settings.plugins.enclosure.io4Enable && isConnected()" class="btn">Turn on</button>
<button type="submit" data-bind="click: handleIO.bind($data, ['io4', 'on']), enable: settings.settings.plugins.enclosure.io4Enable && isConnected()" class="btn">Turn on</button>
<button type="submit" data-bind="click: handleIO.bind($data, ['io4', 'off']), enable: settings.settings.plugins.enclosure.io4Enable && isConnected()" class="btn">Turn off</button>
</div>

View File

@@ -1,9 +0,0 @@
###
# This file is only here to make sure that something like
#
# pip install -e .
#
# works as expected. Requirements can be found in setup.py.
###
.

View File

@@ -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 = "1.5"
plugin_version = "1.6"
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module