Merge branch 'master' of https://github.com/IvanGirderboot/OctoPrint-Enclosure
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
||||
venv
|
||||
.vscode
|
||||
*egg-info*
|
||||
*.pyc
|
||||
|
||||
4
API.md
4
API.md
@@ -144,7 +144,7 @@ Error Responses:
|
||||
|
||||
Endpoint: **PATCH** `/outputs/<id>`
|
||||
|
||||
*Note: id needs to be int (index_id)*
|
||||
*Note: id needs to be int (index_id), one-based index in octoprint settings' enclosure section's `rpi_outputs` list*
|
||||
|
||||
Body (Content-Type: `application/json`):
|
||||
```
|
||||
@@ -340,4 +340,4 @@ Body: empty
|
||||
Response (204): No-Content
|
||||
|
||||
Error Responses:
|
||||
- none
|
||||
- none
|
||||
|
||||
139
README.md
139
README.md
@@ -28,86 +28,107 @@ Here is a list of possibilities:
|
||||
|
||||
Check pictures on thingiverse: http://www.thingiverse.com/thing:2245493
|
||||
|
||||
**Software**
|
||||
## Installation
|
||||
|
||||
Install the plugin using the Plugin Manager bundled with OctoPrint, you can search for the Enclosure plugin or just use the url: https://github.com/vitormhenrique/OctoPrint-Enclosure/archive/master.zip.
|
||||
|
||||
## Hardware
|
||||
|
||||
This plugin support many hardware temperature sensors, led, relays, heater...
|
||||
|
||||
Here are detailled instructions on how to setup them.
|
||||
|
||||
### Temperature sensors
|
||||
|
||||
To control the enclosure temperature or get temperature triggered events, you need to install and configure a temperature sensor. This plugin can support DHT11, DHT22, AM2302, DS18B20, SI7021, BME280 and TMP102 temperature sensors.
|
||||
|
||||
* For the DHT11, DHT22 and AM2302 follow this steps:
|
||||
|
||||
Wire the sensor following the wiring diagram on the pictures on thingiverse, you can use any GPIO pin.
|
||||
#### DHT11, DHT22 and AM2302 sensors
|
||||
|
||||
Wire the sensor following the wiring diagram on the pictures on thingiverse; you can use any GPIO pin.
|
||||
|
||||
For DHT11 and DHT22 sensors, don't forget to connect a 4.7K - 10K resistor from the data pin to VCC. Also, be aware that DHT sensors some times can not work reliably on linux, this is a limitation of reading DHT sensors from Linux--there's no guarantee the program will be given enough priority and time by the Linux kernel to reliably read the sensor. Another common issue is the power supply. you need a constant and good 3.3V, sometimes a underpowered raspberry pi will not have a solid 3.3V power supply, so you could try powering the sensor with 5V and using a level shifter on the read pin.
|
||||
|
||||
You need to install Adafruit library to use the temperature sensor on raspberry pi.
|
||||
You need to install the Adafruit library to use the temperature sensor on Raspberry Pi. Recent versions of this plugin have moved to supporting the CircuitPython-based library on Python3 installed below.
|
||||
|
||||
Open raspberry pi terminal and type:
|
||||
Open a raspberry pi terminal and type:
|
||||
|
||||
<pre><code>cd ~
|
||||
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
|
||||
cd Adafruit_Python_DHT
|
||||
```
|
||||
pip3 install adafruit-circuitpython-dht
|
||||
sudo apt-get update
|
||||
sudo apt-get install build-essential python-dev python-openssl
|
||||
sudo python setup.py install</code></pre>
|
||||
sudo apt-get install libgpiod2 -y
|
||||
```
|
||||
|
||||
Note: All libraries need to be installed on raspberry pi system python not octoprint virtual environment.
|
||||
This will install all requirements of the library.
|
||||
|
||||
You can test the library by using:
|
||||
You can test the library by using the sample code from https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/python-setup.
|
||||
|
||||
<pre><code>cd examples
|
||||
sudo ./AdafruitDHT.py 2302 4</code></pre>
|
||||
#### DS18B20 sensor
|
||||
|
||||
Note that the first argument is the temperature sensor (11, 22, or 2302), and the second argument is the GPIO that the sensor was connected.
|
||||
Follow the wiring diagram on the pictures on thingiverse. The DS18B20 uses "1-wire" communication protocol, DS18B20 only works on GPIO pin number 4 by default. You also need to add OneWire support for your raspberry pi.
|
||||
|
||||
* For the DS18B20 sensor:
|
||||
Start by adding the following line to `/boot/config.txt`
|
||||
|
||||
Follow the wiring diagram on the pictures on thingiverse. The DS18B20 uses "1-wire" communication protocol, you need to use 4.7K to 10K resistor from the data pin to VCC, DS18B20 only works on GPIO pin number 4 by default. You also need to add OneWire support for your raspberry pi.
|
||||
|
||||
Start by adding the following line to /boot/config.txt
|
||||
|
||||
<pre><code>dtoverlay=w1-gpio</code></pre>
|
||||
```
|
||||
dtoverlay=w1-gpio
|
||||
```
|
||||
|
||||
After rebooting, you can check if the OneWire device was found properly with
|
||||
<pre><code>dmesg | grep w1-gpio</code></pre>
|
||||
```
|
||||
dmesg | grep w1-gpio
|
||||
```
|
||||
|
||||
You should see something like
|
||||
<pre><code>[ 3.030368] w1-gpio onewire@0: gpio pin 4, external pullup pin -1, parasitic power 0</code></pre>
|
||||
```
|
||||
[ 3.030368] w1-gpio onewire@0: gpio pin 4, external pullup pin -1, parasitic power 0
|
||||
```
|
||||
|
||||
You should be able to test your sensor by rebooting your system with sudo reboot. When the Pi is back up and you're logged in again, type the commands you see below into a terminal window. When you are in the 'devices' directory, the directory starting '28-' may have a different name, so cd to the name of whatever directory is there.
|
||||
If you're using the internal pullup resistor, you'll need to enable it manually by running these Python commands. Or, you can simply configure the sensor inside of the Enclosure plugin, which will do this for you.
|
||||
|
||||
<pre><code>sudo modprobe w1-gpio
|
||||
You should be able to test your sensor by rebooting your system with `sudo reboot`. When the Pi is back up and you're logged in again, type the commands you see below into a terminal window. When you are in the 'devices' directory, the directory starting '28-' may have a different name, so `cd` to the name of whatever directory is there.
|
||||
|
||||
```
|
||||
sudo modprobe w1-gpio
|
||||
sudo modprobe w1-therm
|
||||
cd /sys/bus/w1/devices
|
||||
ls
|
||||
cd 28-xxxx (change this to match what serial number pops up)
|
||||
cat w1_slave</code></pre>
|
||||
cat w1_slave
|
||||
```
|
||||
|
||||
The response will either have YES or NO at the end of the first line. If it is yes, then the temperature will be at the end of the second line, in 1/000 degrees C.
|
||||
The response will either have `YES` or `NO` at the end of the first line. If it is `YES`, then the temperature will be at the end of the second line, in 1/000 degrees C.
|
||||
|
||||
Copy the serial number, you will need to configure the plugin. Note that for the serial number includes the 28-, for example 28-0000069834ff.
|
||||
Copy the serial number, you will need to configure the plugin. Note that for the serial number includes the `28-`, for example `28-0000069834ff`.
|
||||
|
||||
* For the SI7021, BME280, TMP102 and MCP9808 sensors
|
||||
The DS18B20 needs a pullup resistor on the data pin. On modern Pi models, you can use a resistor built into the Pi, configured in software. To do this, set the "Input Pull Resistor" option to "Input Pullup". If this doesn't work, you need to use a 4.7K to 10K resistor from the data pin to VCC.
|
||||
|
||||
#### SI7021, BME280, TMP102 and MCP9808 sensors
|
||||
|
||||
Enable I2C on your raspberry pi, depending on raspi-config version, step by step can be different:
|
||||
|
||||
<pre><code>Run sudo raspi-config
|
||||
Use the down arrow to select 9 Advanced Options
|
||||
Arrow down to A7 I2C
|
||||
Select yes when it asks you to enable I2C
|
||||
Also select yes when it asks about automatically loading the kernel module
|
||||
Use the right arrow to select the button
|
||||
Select yes when it asks to reboot
|
||||
</code></pre>
|
||||
```
|
||||
sudo raspi-config
|
||||
```
|
||||
* Use the down arrow to select 9 Advanced Options
|
||||
* Arrow down to A7 I2C
|
||||
* Select yes when it asks you to enable I2C
|
||||
* Also select yes when it asks about automatically loading the kernel module
|
||||
* Use the right arrow to select the button
|
||||
* Select yes when it asks to reboot
|
||||
|
||||
Install some packages (on raspberry pi system python not octoprint virtual environment):
|
||||
|
||||
<pre><code>sudo apt-get install i2c-tools python-pip python-smbus</code></pre>
|
||||
```
|
||||
sudo apt-get install i2c-tools python-pip python-smbus
|
||||
```
|
||||
|
||||
Find the address of the sensor:
|
||||
|
||||
<pre><code>i2cdetect -y 1</code></pre>
|
||||
```
|
||||
i2cdetect -y 1
|
||||
```
|
||||
|
||||
* For Neopixel
|
||||
### Neopixel
|
||||
|
||||
If your setup does not have pip install pip:
|
||||
`sudo apt-get install python-pip`
|
||||
@@ -125,40 +146,36 @@ Also backlist the audio kernel:
|
||||
|
||||
`sudo nano /etc/modprobe.d/snd-blacklist.conf`
|
||||
|
||||
add the `blacklist snd_bcm2835` to the end of the file:
|
||||
add the `blacklist snd_bcm2835` to the end of the file.
|
||||
|
||||
|
||||
* GPIO
|
||||
### GPIO
|
||||
|
||||
This release uses RPi.GPIO to control IO of raspberry pi, it should install and work automatically. If it doesn't please update your octoprint with the latest release of octopi.
|
||||
You can use relays / mosfets to control you lights, heater, lockers etc... If you want to control mains voltage I recommend using [PowerSwitch Tail II](http://www.powerswitchtail.com/).
|
||||
|
||||
**Hardware**
|
||||
|
||||
You can use relays / mosfets to control you lights, heater, lockers etc... If you want to control mains voltage I recommend using PowerSwitch Tail II.
|
||||
|
||||
* Relay
|
||||
### Relay
|
||||
|
||||
The relays module that I used couple [SainSmart 2-Channel Relay Module](https://www.amazon.com/gp/product/B0057OC6D8?ie=UTF8&tag=3dpstuff-20&camp=1789&linkCode=xm2&creativeASIN=B0057OC6D8). Those relays are active low, that means that they will turn on when you put LOW on the output of your pin. In order to not fry your Raspberry Pi pay attention on your wiring connection: remove the jumper link and connect 3.3v to VCC, 5V to JD-VCC and Ground to GND.
|
||||
|
||||
* Heater
|
||||
### Heater
|
||||
|
||||
For heating my enclosure I got a $15 lasko inside my enclosure. I opened it and added a relay to the mains wire. If you’re uncomfortable soldering or dealing with high voltage, please check out the [PowerSwitch Tail II](http://www.powerswitchtail.com/) . The PowerSwitch Tail II is fully enclosed, making it a lot safer.
|
||||
For heating my enclosure I got a $15 lasko inside my enclosure. I opened it and added a relay to the mains wire. If you’re uncomfortable soldering or dealing with high voltage, please check out the [PowerSwitch Tail II](http://www.powerswitchtail.com/). It is fully enclosed, making it a lot safer.
|
||||
|
||||
**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**
|
||||
|
||||
* Cooler
|
||||
### Cooler
|
||||
|
||||
You can get a [USB Mini Desktop Fan](https://www.amazon.com/gp/product/B00WM7TRTY?ie=UTF8&tag=3dpstuff-20&camp=1789&linkCode=xm2&creativeASIN=B00WM7TRTY) and control it over a relay.
|
||||
|
||||
* Filament sensor
|
||||
### Filament sensor
|
||||
|
||||
You have the ability to add a filament sensor to the enclosure, it will automatically pause the print and run a gcode command to change the filament if you run out of filament, I can be any type of filament sensor, the sensor should connect to ground if is set as an "active low" when the filament run out or 3.3v if the sensor is set as "active high" when detected the end of filament, it does not matter if it is normally open or closed, that will only interfere on your wiring. I'm using the following sensor:
|
||||
|
||||
http://www.thingiverse.com/thing:1698397
|
||||
|
||||
**Configuration**
|
||||
## Plugin configuration
|
||||
|
||||
You need to enable what do you want the plugin to control. Settings from plugin version < 3.6 are not compatible anymore, you will loose all settings after upgrading the plugin.
|
||||
|
||||
@@ -170,7 +187,7 @@ Outputs can be set to the following types:
|
||||
|
||||
* Regular GPIO
|
||||
* PWM GPIO
|
||||
* Neopixel Control via Microcontroller
|
||||
* Neopixel Control via Microcontroler
|
||||
* Neopixel Control directly from raspberry pi
|
||||
* Temperature and Humidity Control
|
||||
* Temperature Alarm
|
||||
@@ -191,12 +208,12 @@ Temperature Sensors will be used to input temperature and humidity data, they ca
|
||||
|
||||
GPIO inputs will trigger events for the plugin, this feature can be used to add buttons to the enclosure and cause pressing those buttons to act on the printer or other pre-configured outputs.
|
||||
|
||||
After selecting GPIO for the input type, and selecting output control on the action type, the button will be able to turn on / off or toggle linked regular outputs, basically being able to control your lights / fan using mechanical buttons instead of the octoprint interface. You can also use buttons to send g-code commands.
|
||||
After selecting GPIO for the input type, and selecting output control on the action type, the button will be able to turn on / off or toggle linked regular_gpio outputs, basically being able to control your lights / fan using mechanical buttons instead of the octoprint interface. You can also use buttons to send g-code commands.
|
||||
|
||||
Selecting print control on the action type will trigger printer actions when the configured GPIO receives a signal. The actions can be Resume and Pause a print job or Change Filament. You can use the "change filament" action and set up the input GPIO according to your filament sensor, for example, if your filament sensor connects to ground when detects the end of the filament, you should choose PULL UP resistors and detect the event on the falling edge.
|
||||
You can also add mechanical buttons to pause, resume and change filaments near your printer for convenience.
|
||||
|
||||
**Advanced Area**
|
||||
## Advanced Area
|
||||
|
||||
If you want to enable notifications check the following [issue](https://github.com/vitormhenrique/OctoPrint-Enclosure/issues/36)
|
||||
|
||||
@@ -204,16 +221,16 @@ You can control outputs using a simple [API](https://github.com/vitormhenrique/O
|
||||
|
||||
Or use [g-code](https://github.com/vitormhenrique/OctoPrint-Enclosure/wiki/G-CODE-Control) commands
|
||||
|
||||
**Tab Order**
|
||||
### Tab Order
|
||||
|
||||
I often use more this plugin than the time-lapse tab, so having the plugin appear before the timelapse is better for me.
|
||||
|
||||
You can do this by changing the config.yaml file as instructed on [octoprint documentation ](http://docs.octoprint.org/en/master/configuration/config_yaml.html). Unless defined differently via the command line config.yaml is located at ~/.octoprint.
|
||||
You can do this by changing the config.yaml file as instructed on [octoprint documentation ](http://docs.octoprint.org/en/master/configuration/config_yaml.html). Unless defined differently via the command line config.yaml is located at `~/.octoprint`.
|
||||
|
||||
You just need to add the following section:
|
||||
|
||||
|
||||
<pre><code>appearance:
|
||||
```
|
||||
appearance:
|
||||
components:
|
||||
order:
|
||||
tab:
|
||||
@@ -222,4 +239,4 @@ You just need to add the following section:
|
||||
- gcodeviewer
|
||||
- terminal
|
||||
- plugin_enclosure
|
||||
</code></pre>
|
||||
```
|
||||
|
||||
@@ -1,151 +1,25 @@
|
||||
import smbus
|
||||
import sys
|
||||
import time
|
||||
from ctypes import c_short
|
||||
from ctypes import c_byte
|
||||
from ctypes import c_ubyte
|
||||
import smbus2
|
||||
import bme280
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
DEVICE = int(sys.argv[1],16)
|
||||
DEVICE = int(sys.argv[1], 16)
|
||||
else:
|
||||
print('-1 | -1')
|
||||
sys.exit(1)
|
||||
|
||||
bus = smbus.SMBus(1) # Rev 2 Pi, Pi 2 & Pi 3 uses bus 1
|
||||
# Rev 1 Pi uses bus 0
|
||||
|
||||
def getShort(data, index):
|
||||
# return two bytes from data as a signed 16-bit value
|
||||
return c_short((data[index+1] << 8) + data[index]).value
|
||||
|
||||
def getUShort(data, index):
|
||||
# return two bytes from data as an unsigned 16-bit value
|
||||
return (data[index+1] << 8) + data[index]
|
||||
|
||||
def getChar(data,index):
|
||||
# return one byte from data as a signed char
|
||||
result = data[index]
|
||||
if result > 127:
|
||||
result -= 256
|
||||
return result
|
||||
|
||||
def getUChar(data,index):
|
||||
# return one byte from data as an unsigned char
|
||||
result = data[index] & 0xFF
|
||||
return result
|
||||
|
||||
def readBME280ID(addr=DEVICE):
|
||||
# Chip ID Register Address
|
||||
REG_ID = 0xD0
|
||||
(chip_id, chip_version) = bus.read_i2c_block_data(addr, REG_ID, 2)
|
||||
return (chip_id, chip_version)
|
||||
|
||||
def readBME280All(addr=DEVICE):
|
||||
# Register Addresses
|
||||
REG_DATA = 0xF7
|
||||
REG_CONTROL = 0xF4
|
||||
REG_CONFIG = 0xF5
|
||||
|
||||
REG_CONTROL_HUM = 0xF2
|
||||
REG_HUM_MSB = 0xFD
|
||||
REG_HUM_LSB = 0xFE
|
||||
|
||||
# Oversample setting - page 27
|
||||
OVERSAMPLE_TEMP = 2
|
||||
OVERSAMPLE_PRES = 2
|
||||
MODE = 1
|
||||
|
||||
# Oversample setting for humidity register - page 26
|
||||
OVERSAMPLE_HUM = 2
|
||||
bus.write_byte_data(addr, REG_CONTROL_HUM, OVERSAMPLE_HUM)
|
||||
|
||||
control = OVERSAMPLE_TEMP<<5 | OVERSAMPLE_PRES<<2 | MODE
|
||||
bus.write_byte_data(addr, REG_CONTROL, control)
|
||||
|
||||
# Read blocks of calibration data from EEPROM
|
||||
# See Page 22 data sheet
|
||||
cal1 = bus.read_i2c_block_data(addr, 0x88, 24)
|
||||
cal2 = bus.read_i2c_block_data(addr, 0xA1, 1)
|
||||
cal3 = bus.read_i2c_block_data(addr, 0xE1, 7)
|
||||
|
||||
# Convert byte data to word values
|
||||
dig_T1 = getUShort(cal1, 0)
|
||||
dig_T2 = getShort(cal1, 2)
|
||||
dig_T3 = getShort(cal1, 4)
|
||||
|
||||
dig_P1 = getUShort(cal1, 6)
|
||||
dig_P2 = getShort(cal1, 8)
|
||||
dig_P3 = getShort(cal1, 10)
|
||||
dig_P4 = getShort(cal1, 12)
|
||||
dig_P5 = getShort(cal1, 14)
|
||||
dig_P6 = getShort(cal1, 16)
|
||||
dig_P7 = getShort(cal1, 18)
|
||||
dig_P8 = getShort(cal1, 20)
|
||||
dig_P9 = getShort(cal1, 22)
|
||||
|
||||
dig_H1 = getUChar(cal2, 0)
|
||||
dig_H2 = getShort(cal3, 0)
|
||||
dig_H3 = getUChar(cal3, 2)
|
||||
|
||||
dig_H4 = getChar(cal3, 3)
|
||||
dig_H4 = (dig_H4 << 24) >> 20
|
||||
dig_H4 = dig_H4 | (getChar(cal3, 4) & 0x0F)
|
||||
|
||||
dig_H5 = getChar(cal3, 5)
|
||||
dig_H5 = (dig_H5 << 24) >> 20
|
||||
dig_H5 = dig_H5 | (getUChar(cal3, 4) >> 4 & 0x0F)
|
||||
|
||||
dig_H6 = getChar(cal3, 6)
|
||||
|
||||
# Wait in ms (Datasheet Appendix B: Measurement time and current calculation)
|
||||
wait_time = 1.25 + (2.3 * OVERSAMPLE_TEMP) + ((2.3 * OVERSAMPLE_PRES) + 0.575) + ((2.3 * OVERSAMPLE_HUM)+0.575)
|
||||
time.sleep(wait_time/1000) # Wait the required time
|
||||
|
||||
# Read temperature/pressure/humidity
|
||||
data = bus.read_i2c_block_data(addr, REG_DATA, 8)
|
||||
pres_raw = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4)
|
||||
temp_raw = (data[3] << 12) | (data[4] << 4) | (data[5] >> 4)
|
||||
hum_raw = (data[6] << 8) | data[7]
|
||||
|
||||
#Refine temperature
|
||||
var1 = ((((temp_raw>>3)-(dig_T1<<1)))*(dig_T2)) >> 11
|
||||
var2 = (((((temp_raw>>4) - (dig_T1)) * ((temp_raw>>4) - (dig_T1))) >> 12) * (dig_T3)) >> 14
|
||||
t_fine = var1+var2
|
||||
temperature = float(((t_fine * 5) + 128) >> 8);
|
||||
|
||||
# Refine pressure and adjust for temperature
|
||||
var1 = t_fine / 2.0 - 64000.0
|
||||
var2 = var1 * var1 * dig_P6 / 32768.0
|
||||
var2 = var2 + var1 * dig_P5 * 2.0
|
||||
var2 = var2 / 4.0 + dig_P4 * 65536.0
|
||||
var1 = (dig_P3 * var1 * var1 / 524288.0 + dig_P2 * var1) / 524288.0
|
||||
var1 = (1.0 + var1 / 32768.0) * dig_P1
|
||||
if var1 == 0:
|
||||
pressure=0
|
||||
else:
|
||||
pressure = 1048576.0 - pres_raw
|
||||
pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1
|
||||
var1 = dig_P9 * pressure * pressure / 2147483648.0
|
||||
var2 = pressure * dig_P8 / 32768.0
|
||||
pressure = pressure + (var1 + var2 + dig_P7) / 16.0
|
||||
|
||||
# Refine humidity
|
||||
humidity = t_fine - 76800.0
|
||||
humidity = (hum_raw - (dig_H4 * 64.0 + dig_H5 / 16384.0 * humidity)) * (dig_H2 / 65536.0 * (1.0 + dig_H6 / 67108864.0 * humidity * (1.0 + dig_H3 / 67108864.0 * humidity)))
|
||||
humidity = humidity * (1.0 - dig_H1 * humidity / 524288.0)
|
||||
if humidity > 100:
|
||||
humidity = 100
|
||||
elif humidity < 0:
|
||||
humidity = 0
|
||||
|
||||
return temperature/100.0,pressure/100.0,humidity
|
||||
# Rev 2 Pi, Pi 2 & Pi 3 & Pi 4 use bus 1
|
||||
# Rev 1 Pi uses bus 0
|
||||
bus = smbus2.SMBus(1)
|
||||
|
||||
def main():
|
||||
try:
|
||||
temperature,pressure,humidity = readBME280All()
|
||||
print('{0:0.1f} | {1:0.1f}'.format(temperature, humidity))
|
||||
calibration_params = bme280.load_calibration_params(bus, DEVICE)
|
||||
data = bme280.sample(bus, DEVICE, calibration_params)
|
||||
|
||||
print('{0:0.1f} | {1:0.1f}'.format(data.temperature, data.humidity))
|
||||
except:
|
||||
print('-1 | -1')
|
||||
|
||||
if __name__=="__main__":
|
||||
if __name__== "__main__":
|
||||
main()
|
||||
|
||||
@@ -21,6 +21,9 @@ import inspect
|
||||
import threading
|
||||
import json
|
||||
import copy
|
||||
from smbus2 import SMBus
|
||||
from .getPiTemp import PiTemp
|
||||
import struct
|
||||
|
||||
|
||||
#Function that returns Boolean output state of the GPIO inputs / outputs
|
||||
@@ -148,7 +151,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
self.print_complete = False
|
||||
|
||||
def get_settings_version(self):
|
||||
return 6
|
||||
return 10
|
||||
|
||||
def on_settings_migrate(self, target, current=None):
|
||||
self._logger.warn("######### current settings version %s target settings version %s #########", current, target)
|
||||
@@ -156,15 +159,46 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
self._logger.info("rpi_outputs: %s", self.rpi_outputs)
|
||||
self._logger.info("rpi_inputs: %s", self.rpi_inputs)
|
||||
self._logger.info("######### End Current Settings #########")
|
||||
if current >= 4 and target == 6:
|
||||
self._logger.warn("######### migrating settings to v6 #########")
|
||||
if current >= 4 and target == 10:
|
||||
self._logger.warn("######### migrating settings to v10 #########")
|
||||
old_outputs = self._settings.get(["rpi_outputs"])
|
||||
old_inputs = self._settings.get(["rpi_inputs"])
|
||||
for rpi_output in old_outputs:
|
||||
if 'shutdown_on_failed' not in rpi_output:
|
||||
rpi_output['shutdown_on_failed'] = False
|
||||
if 'shell_script' not in rpi_output:
|
||||
rpi_output['shell_script'] = ""
|
||||
if 'gpio_i2c_enabled' not in rpi_output:
|
||||
rpi_output['gpio_i2c_enabled'] = False
|
||||
if 'gpio_i2c_bus' not in rpi_output:
|
||||
rpi_output['gpio_i2c_bus'] = 1
|
||||
if 'gpio_i2c_address' not in rpi_output:
|
||||
rpi_output['gpio_i2c_address'] = 1
|
||||
if 'gpio_i2c_register' not in rpi_output:
|
||||
rpi_output['gpio_i2c_register'] = 1
|
||||
if 'gpio_i2c_data_on' not in rpi_output:
|
||||
rpi_output['gpio_i2c_data_on'] = 1
|
||||
if 'gpio_i2c_data_off' not in rpi_output:
|
||||
rpi_output['gpio_i2c_data_off'] = 0
|
||||
if 'gpio_i2c_register_status' not in rpi_output:
|
||||
rpi_output['gpio_i2c_register_status'] = 1
|
||||
if 'shutdown_on_error' not in rpi_output:
|
||||
rpi_output['shutdown_on_error'] = False
|
||||
self._settings.set(["rpi_outputs"], old_outputs)
|
||||
|
||||
old_inputs = self._settings.get(["rpi_inputs"])
|
||||
for rpi_input in old_inputs:
|
||||
if 'temp_i2c_bus' not in rpi_input:
|
||||
rpi_input['temp_i2c_bus'] = 1
|
||||
if 'temp_i2c_address' not in rpi_input:
|
||||
rpi_input['temp_i2c_address'] = 1
|
||||
if 'temp_i2c_register' not in rpi_input:
|
||||
rpi_input['temp_i2c_register'] = 1
|
||||
if 'show_graph_temp' not in rpi_input:
|
||||
rpi_input['show_graph_temp'] = False
|
||||
if 'show_graph_humidity' not in rpi_input:
|
||||
rpi_input['show_graph_humidity'] = False
|
||||
self._settings.set(["rpi_inputs"], old_inputs)
|
||||
else:
|
||||
self._logger.warn("######### settings not compatible #########")
|
||||
self._settings.set(["rpi_outputs"], [])
|
||||
@@ -191,7 +225,11 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
ConfiguredAs = "Output"
|
||||
ActiveLow = CheckInputActiveLow(rpi_output['active_low'])
|
||||
pin = self.to_int(rpi_output['gpio_pin'])
|
||||
val = PinState_Human(pin,ActiveLow)
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
b = self.gpio_i2c_input(rpi_output, ActiveLow)
|
||||
val = " ON " if b else " OFF "
|
||||
else:
|
||||
val = PinState_Human(pin,ActiveLow)
|
||||
label = rpi_output['label']
|
||||
Resp.append(dict(Configured_As=ConfiguredAs, label=label, GPIO_Pin=pin, Active_Low=ActiveLow, State=val))
|
||||
if MatchFound == False:
|
||||
@@ -279,7 +317,11 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
label = rpi_output['label']
|
||||
pin = self.to_int(rpi_output['gpio_pin'])
|
||||
ActiveLow = rpi_output['active_low']
|
||||
val = PinState_Human(pin,ActiveLow)
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
b = self.gpio_i2c_input(rpi_output, ActiveLow)
|
||||
val = " ON " if b else " OFF "
|
||||
else:
|
||||
val = PinState_Human(pin,ActiveLow)
|
||||
outputs.append(dict(index_id=index, label=label, GPIO_Pin=pin, State=val))
|
||||
return Response(json.dumps(outputs), mimetype='application/json')
|
||||
|
||||
@@ -290,7 +332,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
if identifier == self.to_int(rpi_output['index_id']):
|
||||
out = copy.deepcopy(rpi_output)
|
||||
pin = self.to_int(rpi_output['gpio_pin'])
|
||||
out['current_value'] = PinState_Boolean(pin, rpi_output['active_low'] )
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
out['current_value'] = self.gpio_i2c_input(rpi_output, rpi_output['active_low'])
|
||||
else:
|
||||
out['current_value'] = PinState_Boolean(pin, rpi_output['active_low'] )
|
||||
return Response(json.dumps(out), mimetype='application/json')
|
||||
return make_response('', 404)
|
||||
|
||||
@@ -313,7 +358,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
for rpi_output in self.rpi_outputs:
|
||||
if identifier == self.to_int(rpi_output['index_id']):
|
||||
val = (not value) if rpi_output['active_low'] else value
|
||||
self.write_gpio(self.to_int(rpi_output['gpio_pin']), val)
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(rpi_output, val)
|
||||
else:
|
||||
self.write_gpio(self.to_int(rpi_output['gpio_pin']), val)
|
||||
return make_response('', 204)
|
||||
|
||||
|
||||
@@ -520,7 +568,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
if rpi_output['output_type'] == 'regular':
|
||||
pin = self.to_int(rpi_output['gpio_pin'])
|
||||
ActiveLow = rpi_output['active_low']
|
||||
val = PinState_Boolean(pin, ActiveLow)
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
val = self.gpio_i2c_input(rpi_output, rpi_output['active_low'])
|
||||
else:
|
||||
val = PinState_Boolean(pin, ActiveLow)
|
||||
val2 = PinState_Human(pin, ActiveLow)
|
||||
index = self.to_int(rpi_output['index_id'])
|
||||
gpio_status.append(dict(index_id=index, status=val, State=val2))
|
||||
@@ -533,7 +584,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
for rpi_output in self.rpi_outputs:
|
||||
if self.to_int(index) == self.to_int(rpi_output['index_id']):
|
||||
val = (not value) if rpi_output['active_low'] else value
|
||||
self.write_gpio(self.to_int(rpi_output['gpio_pin']), val)
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(rpi_output, val)
|
||||
else:
|
||||
self.write_gpio(self.to_int(rpi_output['gpio_pin']), val)
|
||||
return jsonify(success=True)
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/sendShellCommand", methods=["GET"])
|
||||
@@ -683,6 +737,63 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
|
||||
# DEPREACTION END
|
||||
|
||||
# GPIO over i2c
|
||||
|
||||
def gpio_i2c_input(self, output, active_low=None):
|
||||
state = False
|
||||
try:
|
||||
i2cbus = self.to_int(output['gpio_i2c_bus'])
|
||||
i2caddr = self.to_int(output['gpio_i2c_address'])
|
||||
i2creg = self.to_int(output['gpio_i2c_register_status'])
|
||||
data_on = self.to_int(output['gpio_i2c_data_on'])
|
||||
|
||||
with SMBus(i2cbus) as bus:
|
||||
data = bus.read_i2c_block_data(i2caddr, i2creg, 1)
|
||||
if data[0] == data_on:
|
||||
state = True
|
||||
|
||||
self._logger.debug("gpio_i2c_input(i2cbus=%s, i2caddr=%s, i2creg=%s, data_on=%s) data == %s",
|
||||
i2cbus, i2caddr, i2creg, data_on, data)
|
||||
|
||||
if active_low is None and state: return state
|
||||
|
||||
except Exception as ex:
|
||||
self.log_error(ex)
|
||||
|
||||
if active_low and not state: return True
|
||||
if not active_low and state: return True
|
||||
return False
|
||||
|
||||
def gpio_i2c_write(self, output, state, queue_id=None):
|
||||
try:
|
||||
i2cbus = self.to_int(output['gpio_i2c_bus'])
|
||||
i2caddr = self.to_int(output['gpio_i2c_address'])
|
||||
i2creg = self.to_int(output['gpio_i2c_register'])
|
||||
data_on = self.to_int(output['gpio_i2c_data_on'])
|
||||
data_off = self.to_int(output['gpio_i2c_data_off'])
|
||||
|
||||
with SMBus(i2cbus) as bus:
|
||||
data = []
|
||||
if state:
|
||||
data.append(data_on)
|
||||
else:
|
||||
data.append(data_off)
|
||||
|
||||
bus.write_i2c_block_data(i2caddr, i2creg, data)
|
||||
|
||||
if queue_id is not None:
|
||||
self._logger.debug("Running scheduled queue id %s", queue_id)
|
||||
self._logger.debug("Writing on GPIO (i2c): %s/%s value %s", output['gpio_i2c_address'], output['gpio_i2c_register'], state)
|
||||
self.update_ui()
|
||||
if queue_id is not None:
|
||||
self.stop_queue_item(queue_id)
|
||||
|
||||
except Exception as ex:
|
||||
template = "An exception of type {0} occurred on {1} when writing on i2c address {2}, reg {3}. Arguments:\n{4!r}"
|
||||
message = template.format(type(ex).__name__, inspect.currentframe().f_code.co_name, output['gpio_i2c_address'], output['gpio_i2c_register'], ex.args)
|
||||
self._logger.warn(message)
|
||||
pass
|
||||
|
||||
|
||||
def send_dotstar_command(self, index_id, active, data_pin, clock_pin, led_count, led_brightness, red, green, blue, queue_id=None):
|
||||
if queue_id is not None:
|
||||
@@ -797,10 +908,13 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
index_id = self.to_int(output['index_id'])
|
||||
|
||||
if output['output_type'] == 'regular':
|
||||
if first_run:
|
||||
current_value = False
|
||||
if output['gpio_i2c_enabled']:
|
||||
current_value = self.gpio_i2c_input(output)
|
||||
else:
|
||||
current_value = (not GPIO.input(gpio_pin)) if output['active_low'] else GPIO.input(gpio_pin)
|
||||
if first_run:
|
||||
current_value = False
|
||||
else:
|
||||
current_value = (not GPIO.input(gpio_pin)) if output['active_low'] else GPIO.input(gpio_pin)
|
||||
|
||||
if current_value:
|
||||
time_delay = self.to_int(output['toggle_timer_off'])
|
||||
@@ -808,12 +922,18 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
time_delay = self.to_int(output['toggle_timer_on'])
|
||||
|
||||
if not self.print_complete:
|
||||
self.write_gpio(gpio_pin, not current_value)
|
||||
if output['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(output, not current_value)
|
||||
else:
|
||||
self.write_gpio(gpio_pin, not current_value)
|
||||
thread = threading.Timer(time_delay, self.toggle_output, args=[index_id])
|
||||
thread.start()
|
||||
else:
|
||||
off_value = True if output['active_low'] else False
|
||||
self.write_gpio(gpio_pin, off_value)
|
||||
if output['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(output, off_value)
|
||||
else:
|
||||
self.write_gpio(gpio_pin, off_value)
|
||||
self.update_ui_outputs()
|
||||
return
|
||||
|
||||
@@ -888,11 +1008,17 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
shutdown = output['auto_shutdown']
|
||||
|
||||
if output['output_type'] == 'regular':
|
||||
val = GPIO.input(pin) if not output['active_low'] else (not GPIO.input(pin))
|
||||
if output['gpio_i2c_enabled']:
|
||||
val = self.gpio_i2c_input(output)
|
||||
else:
|
||||
val = GPIO.input(pin) if not output['active_low'] else (not GPIO.input(pin))
|
||||
regular_status.append(
|
||||
dict(index_id=index, status=val, auto_startup=startup, auto_shutdown=shutdown))
|
||||
if output['output_type'] == 'temp_hum_control':
|
||||
val = GPIO.input(pin) if not output['active_low'] else (not GPIO.input(pin))
|
||||
if output['gpio_i2c_enabled']:
|
||||
val = self.gpio_i2c_input(output)
|
||||
else:
|
||||
val = GPIO.input(pin) if not output['active_low'] else (not GPIO.input(pin))
|
||||
temp_control_status.append(
|
||||
dict(index_id=index, status=val, auto_startup=startup, auto_shutdown=shutdown))
|
||||
if output['output_type'] == 'neopixel_indirect' or output['output_type'] == 'neopixel_direct':
|
||||
@@ -950,6 +1076,9 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
temp, hum = self.read_bme280_temp(sensor['temp_sensor_address'])
|
||||
elif sensor['temp_sensor_type'] == "am2320":
|
||||
temp, hum = self.read_am2320_temp() # sensor has fixed address
|
||||
elif sensor['temp_sensor_type'] == "rpi":
|
||||
temp = self.read_rpi_temp() # rpi CPU Temp
|
||||
hum = 0
|
||||
elif sensor['temp_sensor_type'] == "si7021":
|
||||
temp, hum = self.read_si7021_temp(sensor['temp_sensor_address'], sensor['temp_sensor_i2cbus'])
|
||||
elif sensor['temp_sensor_type'] == "tmp102":
|
||||
@@ -961,6 +1090,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
elif sensor['temp_sensor_type'] == "mcp9808":
|
||||
temp = self.read_mcp_temp(sensor['temp_sensor_address'])
|
||||
hum = 0
|
||||
elif sensor['temp_sensor_type'] == "temp_raw_i2c":
|
||||
temp, hum = self.read_raw_i2c_temp(sensor)
|
||||
elif sensor['temp_sensor_type'] == "hum_raw_i2c":
|
||||
hum, temp = self.read_raw_i2c_temp(sensor)
|
||||
else:
|
||||
self._logger.info("temp_sensor_type no match")
|
||||
temp = None
|
||||
@@ -986,8 +1119,12 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
for rpi_controlled_output in self.rpi_outputs:
|
||||
if self.to_int(temperature_alarm['controlled_io']) == self.to_int(
|
||||
rpi_controlled_output['index_id']):
|
||||
val = GPIO.LOW if temperature_alarm['controlled_io_set_value'] == 'low' else GPIO.HIGH
|
||||
self.write_gpio(self.to_int(rpi_controlled_output['gpio_pin']), val)
|
||||
if rpi_controlled_output['gpio_i2c_enabled']:
|
||||
val = False if temperature_alarm['controlled_io_set_value'] == 'low' else True
|
||||
self.gpio_i2c_write(rpi_controlled_output, val)
|
||||
else:
|
||||
val = GPIO.LOW if temperature_alarm['controlled_io_set_value'] == 'low' else GPIO.HIGH
|
||||
self.write_gpio(self.to_int(rpi_controlled_output['gpio_pin']), val)
|
||||
for notification in self.notifications:
|
||||
if notification['temperatureAction']:
|
||||
msg = ("Temperature action: enclosure temperature exceed " + temperature_alarm[
|
||||
@@ -1005,6 +1142,32 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
|
||||
return return_value, return_value
|
||||
|
||||
def read_raw_i2c_temp(self, sensor):
|
||||
try:
|
||||
i2cbus = self.to_int(sensor['temp_i2c_bus'])
|
||||
i2caddr = self.to_int(sensor['temp_i2c_address'])
|
||||
i2creg = self.to_int(sensor['temp_i2c_register'])
|
||||
|
||||
with SMBus(i2cbus) as bus:
|
||||
data = bus.read_i2c_block_data(i2caddr, i2creg, 8)
|
||||
fval1 = struct.unpack('f', bytearray(data[0:4]))[0]
|
||||
if fval1 != fval1:
|
||||
fval1 = 0
|
||||
fval2 = struct.unpack('f', bytearray(data[4:8]))[0]
|
||||
if fval2 != fval2:
|
||||
fval2 = 0
|
||||
|
||||
self._logger.debug("read_raw_i2c_temp(i2cbus=%s, i2caddr=%s, i2creg=%s) data == %s (%s, %s)",
|
||||
i2cbus, i2caddr, i2creg, data, fval1, fval2)
|
||||
|
||||
return (fval1, fval2)
|
||||
|
||||
except Exception as ex:
|
||||
template = "An exception of type {0} occurred on {1} when reading on i2c address {2}, reg {3}. Arguments:\n{4!r}"
|
||||
message = template.format(type(ex).__name__, inspect.currentframe().f_code.co_name, i2caddr, i2creg, ex.args)
|
||||
self._logger.warn(message)
|
||||
return str(-1)
|
||||
|
||||
def read_mcp_temp(self, address):
|
||||
try:
|
||||
script = os.path.dirname(os.path.realpath(__file__)) + "/mcp9808.py"
|
||||
@@ -1028,7 +1191,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
sudo_str = "sudo "
|
||||
else:
|
||||
sudo_str = ""
|
||||
cmd = sudo_str + "python " + script + str(sensor) + " " + str(pin)
|
||||
cmd = sudo_str + "python3 " + script + str(sensor) + " " + str(pin)
|
||||
if self._settings.get(["debug_temperature_log"]) is True:
|
||||
self._logger.debug("Temperature dht cmd: %s", cmd)
|
||||
stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read()
|
||||
@@ -1044,18 +1207,23 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
|
||||
def read_bme280_temp(self, address):
|
||||
try:
|
||||
script = os.path.dirname(os.path.realpath(__file__)) + "/BME280.py "
|
||||
script = os.path.dirname(os.path.realpath(__file__)) + "/BME280.py"
|
||||
cmd = [sys.executable, script, str(address)]
|
||||
if self._settings.get(["use_sudo"]):
|
||||
sudo_str = "sudo "
|
||||
else:
|
||||
sudo_str = ""
|
||||
cmd = sudo_str + "python " + script + str(address)
|
||||
cmd.insert(0, "sudo")
|
||||
if self._settings.get(["debug_temperature_log"]) is True:
|
||||
self._logger.debug("Temperature BME280 cmd: %s", cmd)
|
||||
stdout = (Popen(cmd, shell=True, stdout=PIPE).stdout).read()
|
||||
if self._settings.get(["debug_temperature_log"]) is True:
|
||||
self._logger.debug("BME280 result: %s", stdout)
|
||||
temp, hum = stdout.decode("utf-8").split("|")
|
||||
|
||||
stdout = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
|
||||
output, errors = stdout.communicate()
|
||||
|
||||
if self._settings.get(["debug_temperature_log"]) is True:
|
||||
if len(errors) > 0:
|
||||
self._logger.error("BME280 error: %s", errors)
|
||||
else:
|
||||
self._logger.debug("BME280 result: %s", output)
|
||||
|
||||
temp, hum = output.split("|")
|
||||
return (self.to_float(temp.strip()), self.to_float(hum.strip()))
|
||||
except Exception as ex:
|
||||
self._logger.info(
|
||||
@@ -1083,6 +1251,19 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
"Failed to execute python scripts, try disabling use SUDO on advanced section of the plugin.")
|
||||
self.log_error(ex)
|
||||
return (0, 0)
|
||||
|
||||
def read_rpi_temp(self):
|
||||
try:
|
||||
pitemp = PiTemp()
|
||||
temp = pitemp.getTemp()
|
||||
if self._settings.get(["debug_temperature_log"]) is True:
|
||||
self._logger.debug("Pi CPU result: %s", temp)
|
||||
return temp
|
||||
except Exception as ex:
|
||||
self._logger.info(
|
||||
"Failed to get pi cpu temperature")
|
||||
self.log_error(ex)
|
||||
return 0
|
||||
|
||||
def read_si7021_temp(self, address, i2cbus):
|
||||
try:
|
||||
@@ -1258,7 +1439,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
if current_status:
|
||||
self._logger.info("Turning gpio to control temperature on.")
|
||||
val = False if temp_hum_control['active_low'] else True
|
||||
self.write_gpio(self.to_int(temp_hum_control['gpio_pin']), val)
|
||||
if temp_hum_control['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(temp_hum_control, val)
|
||||
else:
|
||||
self.write_gpio(self.to_int(temp_hum_control['gpio_pin']), val)
|
||||
else:
|
||||
index_id = temp_hum_control['index_id']
|
||||
if index_id in self.waiting_temperature:
|
||||
@@ -1269,7 +1453,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
|
||||
self._logger.info("Turning gpio to control temperature off.")
|
||||
val = True if temp_hum_control['active_low'] else False
|
||||
self.write_gpio(self.to_int(temp_hum_control['gpio_pin']), val)
|
||||
if temp_hum_control['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(temp_hum_control, val)
|
||||
else:
|
||||
self.write_gpio(self.to_int(temp_hum_control['gpio_pin']), val)
|
||||
for control_status in self.temp_hum_control_status:
|
||||
if control_status['index_id'] == temp_hum_control['index_id']:
|
||||
control_status['status'] = current_status
|
||||
@@ -1279,7 +1466,7 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
def log_error(self, ex):
|
||||
template = "An exception of type {0} occurred on {1}. Arguments:\n{2!r}"
|
||||
message = template.format(type(ex).__name__, inspect.currentframe().f_code.co_name, ex.args)
|
||||
self._logger.warn(message)
|
||||
self._logger.warn(message, exc_info = True)
|
||||
|
||||
def setup_gpio(self):
|
||||
try:
|
||||
@@ -1287,8 +1474,9 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
set_mode = GPIO.BOARD if self._settings.get(["use_board_pin_number"]) else GPIO.BCM
|
||||
if current_mode is None:
|
||||
outputs = list(filter(
|
||||
lambda item: item['output_type'] == 'regular' or item['output_type'] == 'pwm' or item[
|
||||
'output_type'] == 'temp_hum_control' or item['output_type'] == 'neopixel_direct',
|
||||
lambda item: (item['output_type'] == 'regular' or item['output_type'] == 'pwm' or item[
|
||||
'output_type'] == 'temp_hum_control' or item['output_type'] == 'neopixel_direct') and
|
||||
item['gpio_i2c_enabled'] == False,
|
||||
self.rpi_outputs))
|
||||
inputs = list(filter(lambda item: item['input_type'] == 'gpio', self.rpi_inputs))
|
||||
gpios = outputs + inputs
|
||||
@@ -1312,8 +1500,9 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
try:
|
||||
|
||||
for gpio_out in list(filter(
|
||||
lambda item: item['output_type'] == 'regular' or item['output_type'] == 'pwm' or item[
|
||||
'output_type'] == 'temp_hum_control' or item['output_type'] == 'neopixel_direct',
|
||||
lambda item: (item['output_type'] == 'regular' or item['output_type'] == 'pwm' or item[
|
||||
'output_type'] == 'temp_hum_control' or item['output_type'] == 'neopixel_direct') and
|
||||
item['gpio_i2c_enabled'] == False,
|
||||
self.rpi_outputs)):
|
||||
gpio_pin = self.to_int(gpio_out['gpio_pin'])
|
||||
if gpio_pin not in self.rpi_outputs_not_changed:
|
||||
@@ -1345,7 +1534,8 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
try:
|
||||
|
||||
for gpio_out in list(
|
||||
filter(lambda item: item['output_type'] == 'regular' or item['output_type'] == 'temp_hum_control',
|
||||
filter(lambda item: (item['output_type'] == 'regular' or item['output_type'] == 'temp_hum_control') and
|
||||
item['gpio_i2c_enabled'] == False,
|
||||
self.rpi_outputs)):
|
||||
initial_value = GPIO.HIGH if gpio_out['active_low'] else GPIO.LOW
|
||||
pin = self.to_int(gpio_out['gpio_pin'])
|
||||
@@ -1389,6 +1579,16 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
if (rpi_input['action_type'] == 'printer_control' and rpi_input['printer_action'] != 'filament'):
|
||||
GPIO.add_event_detect(gpio_pin, edge, callback=self.handle_printer_action, bouncetime=200)
|
||||
self._logger.info("Adding PRINTER CONTROL event detect on pin %s with edge: %s", gpio_pin, edge)
|
||||
|
||||
for rpi_input in list(filter(lambda item: item['input_type'] == 'temperature_sensor', self.rpi_inputs)):
|
||||
gpio_pin = self.to_int(rpi_input['gpio_pin'])
|
||||
if rpi_input['input_pull_resistor'] == 'input_pull_up':
|
||||
pull_resistor = GPIO.PUD_UP
|
||||
elif rpi_input['input_pull_resistor'] == 'input_pull_down':
|
||||
pull_resistor = GPIO.PUD_DOWN
|
||||
else:
|
||||
pull_resistor = GPIO.PUD_OFF
|
||||
GPIO.setup(gpio_pin, GPIO.IN, pull_up_down=pull_resistor)
|
||||
except Exception as ex:
|
||||
self.log_error(ex)
|
||||
|
||||
@@ -1472,8 +1672,12 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
rpi_output = [r_out for r_out in self.rpi_outputs if
|
||||
self.to_int(r_out['index_id']) == controlled_io].pop()
|
||||
if rpi_output['output_type'] == 'regular':
|
||||
val = GPIO.LOW if rpi_input['controlled_io_set_value'] == 'low' else GPIO.HIGH
|
||||
self.write_gpio(self.to_int(rpi_output['gpio_pin']), val)
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
val = False if rpi_input['controlled_io_set_value'] == 'low' else True
|
||||
self.gpio_i2c_write(rpi_output, val)
|
||||
else:
|
||||
val = GPIO.LOW if rpi_input['controlled_io_set_value'] == 'low' else GPIO.HIGH
|
||||
self.write_gpio(self.to_int(rpi_output['gpio_pin']), val)
|
||||
except Exception as ex:
|
||||
self.log_error(ex)
|
||||
pass
|
||||
@@ -1505,7 +1709,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
self.to_int(rpi_output['gpio_pin'])) == GPIO.HIGH else GPIO.HIGH
|
||||
else:
|
||||
val = GPIO.LOW if rpi_input['controlled_io_set_value'] == 'low' else GPIO.HIGH
|
||||
self.write_gpio(self.to_int(rpi_output['gpio_pin']), val)
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(rpi_output, val)
|
||||
else:
|
||||
self.write_gpio(self.to_int(rpi_output['gpio_pin']), val)
|
||||
for notification in self.notifications:
|
||||
if notification['gpioAction']:
|
||||
msg = "GPIO control action caused by input " + str(
|
||||
@@ -1721,12 +1928,29 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
if event == Events.PRINT_DONE:
|
||||
for notification in self.notifications:
|
||||
if notification['printFinish']:
|
||||
file_name = os.path.basename(payload["file"])
|
||||
file_name = os.path.basename(payload["path"])
|
||||
elapsed_time_in_seconds = payload["time"]
|
||||
elapsed_time = octoprint.util.get_formatted_timedelta(timedelta(seconds=elapsed_time_in_seconds))
|
||||
msg = "Print job finished: " + file_name + "finished printing in " + file_name, elapsed_time
|
||||
self.send_notification(msg)
|
||||
|
||||
if event in (Events.ERROR, Events.DISCONNECTED):
|
||||
self._logger.info("Detected Error or Disconnect in %s will call listeners for shutdown_on_error!", event)
|
||||
for rpi_output in self.rpi_outputs:
|
||||
if rpi_output['shutdown_on_error']:
|
||||
self._logger.debug("Schedule shutdown for: %s", rpi_output["index_id"])
|
||||
self.schedule_auto_shutdown_outputs(rpi_output, 0)
|
||||
self.run_tasks()
|
||||
|
||||
if event == Events.PRINTER_STATE_CHANGED:
|
||||
if "error" in payload["state_string"].lower():
|
||||
self._logger.info("Detected Error in %s id: %s state: %s will call listeners for shutdown_on_error!", event, payload["state_id"], payload["state_string"])
|
||||
for rpi_output in self.rpi_outputs:
|
||||
if rpi_output['shutdown_on_error']:
|
||||
self._logger.debug("Schedule shutdown for: %s", rpi_output["index_id"])
|
||||
self.schedule_auto_shutdown_outputs(rpi_output, 0)
|
||||
self.run_tasks()
|
||||
|
||||
def run_tasks(self):
|
||||
for task in self.event_queue:
|
||||
if not task['thread'].is_alive():
|
||||
@@ -1773,7 +1997,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
gpio = self.to_int(rpi_output['gpio_pin'])
|
||||
if rpi_output['output_type'] == 'regular':
|
||||
value = False if rpi_output['active_low'] else True
|
||||
self.write_gpio(gpio, value)
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(rpi_output, value)
|
||||
else:
|
||||
self.write_gpio(gpio, value)
|
||||
if rpi_output['output_type'] == 'ledstrip':
|
||||
self.ledstrip_set_rgb(rpi_output)
|
||||
if rpi_output['output_type'] == 'pwm' and not rpi_output['pwm_temperature_linked']:
|
||||
@@ -1915,8 +2142,12 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
|
||||
self._logger.debug("Scheduling regular output id %s on %s delay_seconds", queue_id, delay_seconds)
|
||||
|
||||
thread = threading.Timer(delay_seconds, self.write_gpio,
|
||||
args=[self.to_int(rpi_output['gpio_pin']), value, queue_id])
|
||||
if rpi_output['gpio_i2c_enabled']:
|
||||
thread = threading.Timer(delay_seconds, self.gpio_i2c_write,
|
||||
args=[rpi_output, value, queue_id])
|
||||
else:
|
||||
thread = threading.Timer(delay_seconds, self.write_gpio,
|
||||
args=[self.to_int(rpi_output['gpio_pin']), value, queue_id])
|
||||
|
||||
self.event_queue.append(dict(queue_id=queue_id, thread=thread))
|
||||
|
||||
@@ -2031,7 +2262,10 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
set_value = self.constrain(set_value, 0, 1)
|
||||
value = True if set_value == 1 else False
|
||||
value = (not value) if output['active_low'] else value
|
||||
self.write_gpio(self.to_int(output['gpio_pin']), value)
|
||||
if output['gpio_i2c_enabled']:
|
||||
self.gpio_i2c_write(output, value)
|
||||
else:
|
||||
self.write_gpio(self.to_int(output['gpio_pin']), value)
|
||||
comm_instance._log("Setting REGULAR output %s to value %s" % (index_id, value))
|
||||
return
|
||||
if output['output_type'] == 'pwm':
|
||||
@@ -2071,6 +2305,15 @@ class EnclosurePlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.TemplateP
|
||||
comm_instance._log("Setting TEMP/HUM control output %s to value %s" % (index_id, set_value))
|
||||
return
|
||||
|
||||
def get_graph_data(self, comm, parsed_temps):
|
||||
for sensor in list(filter(lambda item: item['input_type'] == 'temperature_sensor', self.rpi_inputs)):
|
||||
if sensor["show_graph_temp"]:
|
||||
parsed_temps[str(sensor["label"])] = (sensor['temp_sensor_temp'], None)
|
||||
if sensor["show_graph_humidity"]:
|
||||
parsed_temps[str(sensor["label"])+" Humidity"] = (sensor['temp_sensor_humidity'], None)
|
||||
|
||||
return parsed_temps
|
||||
|
||||
|
||||
__plugin_name__ = "Enclosure Plugin"
|
||||
__plugin_pythoncompat__ = ">=2.7,<4"
|
||||
@@ -2083,5 +2326,6 @@ def __plugin_load__():
|
||||
global __plugin_hooks__
|
||||
__plugin_hooks__ = {
|
||||
"octoprint.comm.protocol.gcode.queuing" : __plugin_implementation__.hook_gcode_queuing,
|
||||
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information
|
||||
"octoprint.plugin.softwareupdate.check_config": __plugin_implementation__.get_update_information,
|
||||
"octoprint.comm.protocol.temperatures.received": (__plugin_implementation__.get_graph_data, 1)
|
||||
}
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
import sys
|
||||
import Adafruit_DHT
|
||||
import adafruit_dht
|
||||
|
||||
|
||||
# Parse command line parameters.
|
||||
sensor_args = { '11': Adafruit_DHT.DHT11,
|
||||
'22': Adafruit_DHT.DHT22,
|
||||
'2302': Adafruit_DHT.AM2302 }
|
||||
sensor_args = {
|
||||
'11': adafruit_dht.DHT11,
|
||||
'22': adafruit_dht.DHT22,
|
||||
'2302': adafruit_dht.DHT22
|
||||
}
|
||||
|
||||
if len(sys.argv) == 3 and sys.argv[1] in sensor_args:
|
||||
sensor = sensor_args[sys.argv[1]]
|
||||
pin = sys.argv[2]
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin,2,0.5)
|
||||
dht_dev = sensor(pin)
|
||||
humidity = dht_dev.humidity
|
||||
temperature = dht_dev.temperature
|
||||
|
||||
if humidity is not None and temperature is not None:
|
||||
print('{0:0.1f} | {1:0.1f}'.format(temperature, humidity))
|
||||
|
||||
10
octoprint_enclosure/getPiTemp.py
Normal file
10
octoprint_enclosure/getPiTemp.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from gpiozero import CPUTemperature
|
||||
|
||||
import ctypes
|
||||
import struct
|
||||
import sys
|
||||
|
||||
class PiTemp:
|
||||
def getTemp(self):
|
||||
temp = CPUTemperature()
|
||||
return '{0:0.1f}'.format(temp.temperature)
|
||||
@@ -56,7 +56,7 @@ $(function () {
|
||||
self.notifications = ko.observableArray([]);
|
||||
|
||||
self.humidityCapableSensor = function(sensor){
|
||||
if (['11', '22', '2302', 'bme280', 'am2320', 'si7021'].indexOf(sensor) >= 0){
|
||||
if (['11', '22', '2302', 'bme280', 'am2320', 'si7021', 'hum_raw_i2c', 'temp_raw_i2c'].indexOf(sensor) >= 0){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -448,7 +448,15 @@ $(function () {
|
||||
ledstrip_gpio_dat: ko.observable(""),
|
||||
microcontroller_address: ko.observable(0),
|
||||
gcode: ko.observable(""),
|
||||
show_on_navbar: ko.observable(false)
|
||||
show_on_navbar: ko.observable(false),
|
||||
gpio_i2c_enabled: ko.observable(false),
|
||||
gpio_i2c_bus: ko.observable(1),
|
||||
gpio_i2c_address: ko.observable(1),
|
||||
gpio_i2c_register: ko.observable(1),
|
||||
gpio_i2c_data_on: ko.observable(1),
|
||||
gpio_i2c_data_off: ko.observable(0),
|
||||
gpio_i2c_register_status: ko.observable(1),
|
||||
shutdown_on_error:ko.observable(false),
|
||||
});
|
||||
|
||||
};
|
||||
@@ -483,7 +491,12 @@ $(function () {
|
||||
temp_sensor_navbar: ko.observable(true),
|
||||
filament_sensor_timeout: ko.observable(120),
|
||||
filament_sensor_enabled: ko.observable(true),
|
||||
temp_sensor_i2cbus: ko.observable(1)
|
||||
temp_sensor_i2cbus: ko.observable(1),
|
||||
temp_i2c_bus: ko.observable(1),
|
||||
temp_i2c_address: ko.observable(1),
|
||||
temp_i2c_register: ko.observable(1),
|
||||
show_graph_temp: ko.observable(false),
|
||||
show_graph_humidity: ko.observable(false)
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<h4>{{ _('Raspberry Pi Outputs') }}</h4>
|
||||
<p>
|
||||
Configure all
|
||||
<strong>outputs</strong>. Outputs can be everything that do actions based on UI button presses or automatic events or alarms.
|
||||
<strong>outputs</strong>. Outputs can be everything that performs actions based on UI button presses, or automatic events or alarms.
|
||||
</p>
|
||||
<p>
|
||||
Example of possible outputs are gpio pins, neopixel LED's, temperature control or sending gcode to the printer.
|
||||
Example of possible outputs are GPIO pins, neopixel LED's, temperature control or sending gcode to the printer.
|
||||
</p>
|
||||
<form class="form-horizontal">
|
||||
<div data-bind="foreach: settingsViewModel.settings.plugins.enclosure.rpi_outputs">
|
||||
@@ -97,7 +97,8 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
<!-- ko ifnot: ($data.output_type() == "gcode_output" || $data.output_type() == "temperature_alarm" || $data.output_type() == "shell_output" || $data.output_type() == "ledstrip" || $data.output_type() == "dotstar" ) -->
|
||||
<!-- ko ifnot: ($data.output_type() == "gcode_output" || $data.output_type() == "temperature_alarm" || $data.output_type() == "shell_output" || $data.output_type() == "ledstrip" || ($data.output_type() == "regular" && $data.gpio_i2c_enabled()) || $data.output_type() == "dotstar" ) -->
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('IO Number') }}</label>
|
||||
<div class="controls">
|
||||
@@ -227,7 +228,7 @@
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: auto_shutdown"> {{ _('Auto Shutdown') }}
|
||||
</label>
|
||||
<span class="help-inline">Choose if output should turn off automatomatically when print finishes</span>
|
||||
<span class="help-inline">Choose if output should turn off automatically when print finishes</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
@@ -237,7 +238,7 @@
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: shutdown_on_failed"> {{ _('Shutdown on Failed or Canceled') }}
|
||||
</label>
|
||||
<span class="help-inline">Choose if output should turn off automatomatically when print is canceled or fails</span>
|
||||
<span class="help-inline">Choose if output should turn off automatically when print is canceled or fails</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -256,6 +257,16 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
<!-- ko ifnot: ($data.output_type() == "gcode_output" || $data.output_type() == "temperature_alarm" || $data.output_type() == "shell_output") -->
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: shutdown_on_error"> {{ _('Auto Shutdown on Serial Connection Error') }}
|
||||
</label>
|
||||
<span class="help-inline">Choose if output should turn off automatically when an error or disconnect was detected.</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
<!-- /ko -->
|
||||
|
||||
<!-- ko if: ($data.output_type() == "regular" || $data.output_type() == "temp_hum_control" ) -->
|
||||
@@ -269,6 +280,69 @@
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
|
||||
<!-- ko if: ($data.output_type() == "regular" || $data.output_type() == "temp_hum_control" ) -->
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: gpio_i2c_enabled"> {{ _('GPIO over I2C') }}
|
||||
</label>
|
||||
<span class="help-inline">Active low means that the GPIO will turn on when receive a low signal (ground) from Raspberry PI</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
|
||||
<!-- ko if: $data.gpio_i2c_enabled() -->
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-gpio-i2c-bus">{{ _('I2C Bus') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: gpio_i2c_bus" id="settings-enclosure-gpio-i2c-bus">
|
||||
<span class="help-inline">This value should remain 1 unless you've used dtoverlay=i2c-gpio or you are using another bus.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-gpio-i2c-addr">{{ _('I2C Address') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: gpio_i2c_address" id="settings-enclosure-gpio-i2c-addr">
|
||||
<span class="help-inline">I2C address in HEX value, you can find it by running
|
||||
<code>i2cdetect -y 1</code> on your Raspberry Pi</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-gpio-i2c-reg">{{ _('I2C Register') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: gpio_i2c_register" id="settings-enclosure-gpio-i2c-reg">
|
||||
<span class="help-inline">I2C register in HEX value</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-gpio-i2c-data-on">{{ _('I2C ON data') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: gpio_i2c_data_on" id="settings-enclosure-gpio-i2c-data-on">
|
||||
<span class="help-inline">I2C data to write in HEX value when ON</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-gpio-i2c-data-off">{{ _('I2C OFF data') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: gpio_i2c_data_off" id="settings-enclosure-gpio-i2c-data-off">
|
||||
<span class="help-inline">I2C data to write in HEX value when OFF</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-gpio-i2c-reg-read">{{ _('I2C Register (read status)') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: gpio_i2c_register_status" id="settings-enclosure-gpio-i2c-reg-read">
|
||||
<span class="help-inline">I2C register for reading gpio state in HEX value</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
|
||||
<!-- ko if: ($data.output_type() == "regular" || $data.output_type() == "gcode_output" || $data.output_type() == "shell_output" || $data.output_type() == "ledstrip" || $data.output_type() == "dotstar") -->
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
@@ -588,7 +662,10 @@
|
||||
<option value="am2320">AM2320</option>
|
||||
<option value="tmp102">TMP102</option>
|
||||
<option value="max31855">MAX31855</option>
|
||||
<option value="rpi">Raspberry Pi CPU</option>
|
||||
<option value="mcp9808">MCP9808</option>
|
||||
<option value="temp_raw_i2c">Raw I2C Temperature</option>
|
||||
<option value="hum_raw_i2c">Raw I2C Humidity</option>
|
||||
</select>
|
||||
<span class="help-inline">
|
||||
<span class="label label-important">Attention</span> You need to install and configure the necessary libraries for the temperature sensor, check
|
||||
@@ -596,6 +673,35 @@
|
||||
<a href=" https://github.com/vitormhenrique/OctoPrint-Enclosure">github</a> page</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ko if: ($data.temp_sensor_type() == "temp_raw_i2c") || ($data.temp_sensor_type() == "hum_raw_i2c") -->
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-temp-i2c-bus">{{ _('I2C Bus') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: temp_i2c_bus" id="settings-enclosure-temp-i2c-bus">
|
||||
<span class="help-inline">This value should remain 1 unless you've used dtoverlay=i2c-gpio or you are using another bus.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-temp-i2c-addr">{{ _('I2C Address') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: temp_i2c_address" id="settings-enclosure-temp-i2c-addr">
|
||||
<span class="help-inline">I2C address in HEX value, you can find it by running
|
||||
<code>i2cdetect -y 1</code> on your Raspberry Pi</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-temp-i2c-reg">{{ _('I2C Register') }}</label>
|
||||
<div class="controls">
|
||||
<input type="text" class="input-block-level" data-bind="value: temp_i2c_register" id="settings-enclosure-temp-i2c-reg">
|
||||
<span class="help-inline">I2C register in HEX value</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
|
||||
<!-- ko if: ($data.temp_sensor_type() == "18b20") -->
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-dhtPin">{{ _('Sensor Pin') }}</label>
|
||||
@@ -604,6 +710,16 @@
|
||||
<span class="help-inline">GPIO pin for temperature sensor, recommended to use 4 as DS18B20 has default support to pin #4 (BCM)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class"control-group">
|
||||
<label class="control-label" for="settings-enclosure-dhtPin">{{ _('Input Pull Resistor') }}</label>
|
||||
<div class="controls">
|
||||
<select data-bind="value: input_pull_resistor">
|
||||
<option value="" selected="selected">None</option>
|
||||
<option value="input_pull_up">Input Pullup</option>
|
||||
</select>
|
||||
<span class="help-inline">Whether to enable the built-in pullup for this temperature sensor. If set, then no external pullup is needed.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-dhtPin">{{ _('DS18B20 Serial') }}</label>
|
||||
<div class="controls">
|
||||
@@ -663,7 +779,7 @@
|
||||
</div>
|
||||
|
||||
<!-- /ko -->
|
||||
<!-- ko ifnot: ($data.temp_sensor_type() == "18b20") || ($data.temp_sensor_type() == "si7021") || ($data.temp_sensor_type() == "bme280") || ($data.temp_sensor_type() == "am2320") || ($data.temp_sensor_type() == "tmp102") || ($data.temp_sensor_type() == "max31855") || ($data.temp_sensor_type() == "mcp9808") -->
|
||||
<!-- ko ifnot: ($data.temp_sensor_type() == "rpi") || ($data.temp_sensor_type() == "18b20") || ($data.temp_sensor_type() == "si7021") || ($data.temp_sensor_type() == "bme280") || ($data.temp_sensor_type() == "am2320") || ($data.temp_sensor_type() == "tmp102") || ($data.temp_sensor_type() == "max31855") || ($data.temp_sensor_type() == "mcp9808") || ($data.temp_sensor_type() == "temp_raw_i2c") || ($data.temp_sensor_type() == "hum_raw_i2c") -->
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="settings-enclosure-dhtPin">{{ _('Sensor Pin') }}</label>
|
||||
<div class="controls">
|
||||
@@ -728,7 +844,7 @@
|
||||
<option value="input_pull_up">Input Pullup</option>
|
||||
<option value="input_pull_down">Input Pulldown</option>
|
||||
</select>
|
||||
<span class="help-inline">Choose what type of pull resistors that you want on the output. If you signal is active low, that means it should
|
||||
<span class="help-inline">Choose what type of pull resistors that you want on the output. If your signal is active low, that means it should
|
||||
run the action when receive a low signal (ground), you should choose PULL UP resistors.</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -739,8 +855,8 @@
|
||||
<option value="rise">Rise</option>
|
||||
<option value="fall">Fall</option>
|
||||
</select>
|
||||
<span class="help-inline">Do you want thrigger the event on the rise or falling edge? If you signal is active low, that means it should run
|
||||
the action when receive a low signal (ground), you should choose FALLING EDGE.</span>
|
||||
<span class="help-inline">Do you want to trigger the event on the rise or falling edge? If you signal is active low, that means it should run
|
||||
the action when it receives a low signal (ground), you should choose FALLING EDGE.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -751,7 +867,7 @@
|
||||
<select data-bind="options: $root.settings_possible_outputs, optionsText: 'label',
|
||||
optionsValue: 'index_id', value: $data.controlled_io">
|
||||
</select>
|
||||
<span class="help-inline">When the event happen, you want control which OUTPUT?</span>
|
||||
<span class="help-inline">When the event happens, do you want control of which OUTPUT?</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ko if: ($root.isRegularOutput($data.controlled_io())) -->
|
||||
@@ -763,7 +879,8 @@
|
||||
<option value="high">High</option>
|
||||
<option value="toggle">Toggle</option>
|
||||
</select>
|
||||
<span class="help-inline">When the event happen, you want to turn the controlled IO HIGH or LOW?</span>
|
||||
<span class="help-inline">When the event happens, do you want to turn the controlled IO HIGH or LOW?</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
@@ -814,6 +931,24 @@
|
||||
</label>
|
||||
<span class="help-inline">Enable and disable temperature on navbar</span>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: show_graph_temp"> {{ _('Show temperature in graph') }}
|
||||
</label>
|
||||
<span class="help-inline">Enable to show temperature in temperature graph, when a printer is connected.
|
||||
<!-- ko if: ($data.show_graph_temp()) -->
|
||||
<p><i><strong>Note:</strong>This feature currently requires a custom graph plugin like <a href="https://github.com/jneilliii/OctoPrint-PlotlyTempGraph" target="_blank">PlotlyTempGraph</a></i></span></p>
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" data-bind="checked: show_graph_humidity"> {{ _('Show humidity in graph') }}
|
||||
</label>
|
||||
<span class="help-inline">Enable to show humidity in temperature graph, when a printer is connected.
|
||||
<!-- ko if: ($data.show_graph_humidity()) -->
|
||||
<p><i><strong>Note:</strong>This feature currently requires a custom graph plugin like <a href="https://github.com/jneilliii/OctoPrint-PlotlyTempGraph" target="_blank">PlotlyTempGraph</a></i></span></p>
|
||||
<!-- /ko -->
|
||||
</div>
|
||||
</div>
|
||||
<!-- /ko -->
|
||||
<div class="control-group">
|
||||
@@ -902,7 +1037,7 @@
|
||||
<div class="controls">
|
||||
<textarea rows="4" class="block" data-bind="value: settingsViewModel.settings.plugins.enclosure.filament_sensor_gcode"></textarea>
|
||||
<span class="help-inline">GCODE that will be sent to the printer to pause and allow filament to be changed. You should add
|
||||
<code>ENTER</code> on the end of every line sent to the printer</span>
|
||||
<code>ENTER</code> to the end of every line sent to the printer</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
4
setup.py
4
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 = "4.13.1"
|
||||
plugin_version = "4.13.2"
|
||||
|
||||
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
||||
# module
|
||||
@@ -33,7 +33,7 @@ plugin_url = "https://github.com/vitormhenrique/OctoPrint-Enclosure"
|
||||
plugin_license = "AGPLv3"
|
||||
|
||||
# Any additional requirements besides OctoPrint should be listed here
|
||||
plugin_requires = ["RPi.GPIO>=0.6.5","requests>=2.7"]
|
||||
plugin_requires = ["RPi.GPIO>=0.6.5", "requests>=2.7", "smbus2>=0.3.0", "gpiozero==1.6.2", "RPi.bme280"]
|
||||
|
||||
additional_setup_parameters = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user