double all i2c calls and change nginx config in update script
This commit is contained in:
parent
6ce27f177d
commit
ede52d59db
|
@ -1427,7 +1427,7 @@
|
||||||
"type": "python3-function",
|
"type": "python3-function",
|
||||||
"z": "1371dec5.76e671",
|
"z": "1371dec5.76e671",
|
||||||
"name": "fan control",
|
"name": "fan control",
|
||||||
"func": "#!/usr/bin/python\nimport smbus\n\nstate = msg[\"payload\"]\n\nbus = smbus.SMBus(1)\n\nDEVICE_ADDRESS = 0x0d\n\nif state == \"off\":\n bus.write_byte_data(DEVICE_ADDRESS, 0x08, 0x00)\nif state == \"on\":\n bus.write_byte_data(DEVICE_ADDRESS, 0x08, 0x01)\n",
|
"func": "#!/usr/bin/python\nimport smbus\n\nstate = msg[\"payload\"]\n\nbus = smbus.SMBus(1)\n\nDEVICE_ADDRESS = 0x0d\n\n# command happens twice, for reasons\nif state == \"off\":\n bus.write_byte_data(DEVICE_ADDRESS, 0x08, 0x00)\n bus.write_byte_data(DEVICE_ADDRESS, 0x08, 0x00)\nif state == \"on\":\n bus.write_byte_data(DEVICE_ADDRESS, 0x08, 0x01)\n bus.write_byte_data(DEVICE_ADDRESS, 0x08, 0x01)\n",
|
||||||
"outputs": 1,
|
"outputs": 1,
|
||||||
"x": 1110,
|
"x": 1110,
|
||||||
"y": 40,
|
"y": 40,
|
||||||
|
|
|
@ -25,15 +25,15 @@ function special(){
|
||||||
sudo rm /etc/nginx/sites-enabled/img.conf
|
sudo rm /etc/nginx/sites-enabled/img.conf
|
||||||
sudo nginx -t && sudo systemctl reload nginx
|
sudo nginx -t && sudo systemctl reload nginx
|
||||||
fi
|
fi
|
||||||
if [[ -f "/etc/nginx/sites-available/gallery.conf" ]]; then
|
if ! [[ -f "/etc/nginx/sites-enabled/gallery.conf" ]]; then
|
||||||
${log} "Updating the old nginx config"
|
|
||||||
sudo rm /etc/nginx/sites-available/gallery.conf
|
|
||||||
sudo rm /etc/nginx/sites-enabled/gallery.conf
|
|
||||||
fi
|
|
||||||
if ! [[ -f "/etc/nginx/sites-available/gallery.conf" ]]; then
|
|
||||||
${log} "Nginx config is not installed, doing that now"
|
${log} "Nginx config is not installed, doing that now"
|
||||||
sudo cp /home/pi/PlanktonScope/scripts/gallery/gallery.conf /etc/nginx/sites-available/gallery.conf
|
sudo ln -s /home/pi/PlanktonScope/scripts/gallery/gallery.conf /etc/nginx/sites-enabled/gallery.conf
|
||||||
sudo ln -s /etc/nginx/sites-available/gallery.conf /etc/nginx/sites-enabled/gallery.conf
|
sudo nginx -t && sudo systemctl reload nginx
|
||||||
|
fi
|
||||||
|
if [[ -f "/etc/nginx/sites-available/gallery.conf" ]]; then
|
||||||
|
${log} "Nginx config is installed, changing the links now"
|
||||||
|
sudo rm /etc/nginx/sites-enabled/gallery.conf /etc/nginx/sites-available/gallery.conf
|
||||||
|
sudo ln -s /home/pi/PlanktonScope/scripts/gallery/gallery.conf /etc/nginx/sites-enabled/gallery.conf
|
||||||
sudo nginx -t && sudo systemctl reload nginx
|
sudo nginx -t && sudo systemctl reload nginx
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -44,10 +44,10 @@ cd /home/pi/PlanktonScope || { echo "/home/pi/PlanktonScope does not exist"; exi
|
||||||
# TODO We need to add here a way to load the latest version of this script and execute it again
|
# TODO We need to add here a way to load the latest version of this script and execute it again
|
||||||
remote=$(git ls-remote -h origin master | awk '{print $1}')
|
remote=$(git ls-remote -h origin master | awk '{print $1}')
|
||||||
local=$(git rev-parse HEAD)
|
local=$(git rev-parse HEAD)
|
||||||
${log} "Local : $local - Remote: $remote"
|
|
||||||
if [[ "$local" == "$remote" ]]; then
|
if [[ "$local" == "$remote" ]]; then
|
||||||
${log} "nothing to do!"
|
${log} "nothing to do!"
|
||||||
else
|
else
|
||||||
|
${log} "Local and Remote are different, we have to update!"
|
||||||
git fetch
|
git fetch
|
||||||
UPDATE=$(git diff --numstat origin/master scripts/bash/update.sh | awk '/update.sh/ {print $NF}')
|
UPDATE=$(git diff --numstat origin/master scripts/bash/update.sh | awk '/update.sh/ {print $NF}')
|
||||||
if [[ -n "${UPDATE}" ]]; then
|
if [[ -n "${UPDATE}" ]]; then
|
||||||
|
|
|
@ -8,13 +8,12 @@
|
||||||
# Logger library compatible with multiprocessing
|
# Logger library compatible with multiprocessing
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
|
import subprocess # nosec
|
||||||
|
|
||||||
# Library to send command over I2C for the light module on the fan
|
# Library to send command over I2C for the light module on the fan
|
||||||
try:
|
try:
|
||||||
import smbus2 as smbus
|
import smbus2 as smbus
|
||||||
except ModuleNotFoundError: # We need this to install the library on machine that do not have the module yet
|
except ModuleNotFoundError: # We need this to install the library on machine that do not have the module yet
|
||||||
import subprocess # nosec
|
|
||||||
|
|
||||||
subprocess.run("pip3 install smbus2".split()) # nosec
|
subprocess.run("pip3 install smbus2".split()) # nosec
|
||||||
import smbus2 as smbus
|
import smbus2 as smbus
|
||||||
|
|
||||||
|
@ -55,6 +54,11 @@ class EffectColor(enum.IntEnum):
|
||||||
White = 6
|
White = 6
|
||||||
|
|
||||||
|
|
||||||
|
def i2c_update():
|
||||||
|
# Update the I2C Bus in order to really update the LEDs new values
|
||||||
|
subprocess.Popen("i2cdetect -y 1".split(), stdout=subprocess.PIPE) # nosec
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# LEDs functions
|
# LEDs functions
|
||||||
################################################################################
|
################################################################################
|
||||||
|
@ -62,12 +66,16 @@ def setRGB(R, G, B):
|
||||||
"""Update all LED at the same time"""
|
"""Update all LED at the same time"""
|
||||||
try:
|
try:
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
|
bus.write_byte_data(DEVICE_ADDRESS, Register.led_select, 0xFF)
|
||||||
bus.write_byte_data(
|
bus.write_byte_data(
|
||||||
DEVICE_ADDRESS, Register.led_select, 0xFF
|
DEVICE_ADDRESS, Register.led_select, 0xFF
|
||||||
) # 0xFF write to all LEDs, 0x01/0x02/0x03 to choose first, second or third LED
|
) # 0xFF write to all LEDs, 0x01/0x02/0x03 to choose first, second or third LED
|
||||||
bus.write_byte_data(DEVICE_ADDRESS, Register.red, R & 0xFF)
|
bus.write_byte_data(DEVICE_ADDRESS, Register.red, R & 0xFF)
|
||||||
bus.write_byte_data(DEVICE_ADDRESS, Register.green, G & 0xFF)
|
bus.write_byte_data(DEVICE_ADDRESS, Register.green, G & 0xFF)
|
||||||
bus.write_byte_data(DEVICE_ADDRESS, Register.blue, B & 0xFF)
|
bus.write_byte_data(DEVICE_ADDRESS, Register.blue, B & 0xFF)
|
||||||
|
bus.write_byte_data(DEVICE_ADDRESS, Register.red, R & 0xFF)
|
||||||
|
bus.write_byte_data(DEVICE_ADDRESS, Register.green, G & 0xFF)
|
||||||
|
bus.write_byte_data(DEVICE_ADDRESS, Register.blue, B & 0xFF)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"An Exception has occured in the light library at {e}")
|
logger.exception(f"An Exception has occured in the light library at {e}")
|
||||||
|
|
||||||
|
@ -77,6 +85,7 @@ def setRGBOff():
|
||||||
try:
|
try:
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
bus.write_byte_data(DEVICE_ADDRESS, Register.rgb_off, 0x00)
|
bus.write_byte_data(DEVICE_ADDRESS, Register.rgb_off, 0x00)
|
||||||
|
bus.write_byte_data(DEVICE_ADDRESS, Register.rgb_off, 0x00)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(f"An Exception has occured in the light library at {e}")
|
logger.exception(f"An Exception has occured in the light library at {e}")
|
||||||
|
|
||||||
|
@ -121,50 +130,71 @@ def setRGBColor(bus, color):
|
||||||
|
|
||||||
def ready():
|
def ready():
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
|
setRGBColor(bus, EffectColor.Green)
|
||||||
setRGBColor(bus, EffectColor.Green)
|
setRGBColor(bus, EffectColor.Green)
|
||||||
setRGBSpeed(bus, 1)
|
setRGBSpeed(bus, 1)
|
||||||
|
setRGBSpeed(bus, 1)
|
||||||
|
setRGBEffect(bus, Effect.Breathing)
|
||||||
setRGBEffect(bus, Effect.Breathing)
|
setRGBEffect(bus, Effect.Breathing)
|
||||||
|
|
||||||
|
|
||||||
def error():
|
def error():
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
|
setRGBColor(bus, EffectColor.Red)
|
||||||
setRGBColor(bus, EffectColor.Red)
|
setRGBColor(bus, EffectColor.Red)
|
||||||
setRGBSpeed(bus, 3)
|
setRGBSpeed(bus, 3)
|
||||||
|
setRGBSpeed(bus, 3)
|
||||||
|
setRGBEffect(bus, Effect.Water)
|
||||||
setRGBEffect(bus, Effect.Water)
|
setRGBEffect(bus, Effect.Water)
|
||||||
|
|
||||||
|
|
||||||
def interrupted():
|
def interrupted():
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
|
setRGBColor(bus, EffectColor.Yellow)
|
||||||
setRGBColor(bus, EffectColor.Yellow)
|
setRGBColor(bus, EffectColor.Yellow)
|
||||||
setRGBSpeed(bus, 3)
|
setRGBSpeed(bus, 3)
|
||||||
|
setRGBSpeed(bus, 3)
|
||||||
|
setRGBEffect(bus, Effect.Water)
|
||||||
setRGBEffect(bus, Effect.Water)
|
setRGBEffect(bus, Effect.Water)
|
||||||
|
|
||||||
|
|
||||||
def pumping():
|
def pumping():
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
|
setRGBColor(bus, EffectColor.Blue)
|
||||||
setRGBColor(bus, EffectColor.Blue)
|
setRGBColor(bus, EffectColor.Blue)
|
||||||
setRGBSpeed(bus, 3)
|
setRGBSpeed(bus, 3)
|
||||||
|
setRGBSpeed(bus, 3)
|
||||||
|
setRGBEffect(bus, Effect.Water)
|
||||||
setRGBEffect(bus, Effect.Water)
|
setRGBEffect(bus, Effect.Water)
|
||||||
|
|
||||||
|
|
||||||
def focusing():
|
def focusing():
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
|
setRGBColor(bus, EffectColor.Purple)
|
||||||
setRGBColor(bus, EffectColor.Purple)
|
setRGBColor(bus, EffectColor.Purple)
|
||||||
setRGBSpeed(bus, 3)
|
setRGBSpeed(bus, 3)
|
||||||
|
setRGBSpeed(bus, 3)
|
||||||
|
setRGBEffect(bus, Effect.Water)
|
||||||
setRGBEffect(bus, Effect.Water)
|
setRGBEffect(bus, Effect.Water)
|
||||||
|
|
||||||
|
|
||||||
def imaging():
|
def imaging():
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
|
setRGBColor(bus, EffectColor.White)
|
||||||
setRGBColor(bus, EffectColor.White)
|
setRGBColor(bus, EffectColor.White)
|
||||||
setRGBSpeed(bus, 1)
|
setRGBSpeed(bus, 1)
|
||||||
|
setRGBSpeed(bus, 1)
|
||||||
|
setRGBEffect(bus, Effect.Breathing)
|
||||||
setRGBEffect(bus, Effect.Breathing)
|
setRGBEffect(bus, Effect.Breathing)
|
||||||
|
|
||||||
|
|
||||||
def segmenting():
|
def segmenting():
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
|
setRGBColor(bus, EffectColor.Purple)
|
||||||
setRGBColor(bus, EffectColor.Purple)
|
setRGBColor(bus, EffectColor.Purple)
|
||||||
setRGBSpeed(bus, 1)
|
setRGBSpeed(bus, 1)
|
||||||
|
setRGBSpeed(bus, 1)
|
||||||
|
setRGBEffect(bus, Effect.Breathing)
|
||||||
setRGBEffect(bus, Effect.Breathing)
|
setRGBEffect(bus, Effect.Breathing)
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,22 +205,48 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
print("ready")
|
print("ready")
|
||||||
ready()
|
ready()
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
print("error")
|
print("error")
|
||||||
error()
|
error()
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
print("pumping")
|
print("pumping")
|
||||||
pumping()
|
pumping()
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
print("focusing")
|
print("focusing")
|
||||||
focusing()
|
focusing()
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
print("imaging")
|
print("imaging")
|
||||||
imaging()
|
imaging()
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
print("segmenting")
|
print("segmenting")
|
||||||
segmenting()
|
segmenting()
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
|
print("with i2c_update now!")
|
||||||
|
print("ready")
|
||||||
|
ready()
|
||||||
|
i2c_update()
|
||||||
|
time.sleep(5)
|
||||||
|
print("error")
|
||||||
|
error()
|
||||||
|
i2c_update()
|
||||||
|
time.sleep(5)
|
||||||
|
print("pumping")
|
||||||
|
pumping()
|
||||||
|
i2c_update()
|
||||||
|
time.sleep(5)
|
||||||
|
print("focusing")
|
||||||
|
focusing()
|
||||||
|
i2c_update()
|
||||||
|
time.sleep(5)
|
||||||
|
print("imaging")
|
||||||
|
imaging()
|
||||||
|
i2c_update()
|
||||||
|
time.sleep(5)
|
||||||
|
print("segmenting")
|
||||||
|
segmenting()
|
||||||
|
i2c_update()
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
with smbus.SMBus(1) as bus:
|
with smbus.SMBus(1) as bus:
|
||||||
setRGBSpeed(bus, 3)
|
setRGBSpeed(bus, 3)
|
||||||
for effect in Effect:
|
for effect in Effect:
|
||||||
|
|
Loading…
Reference in a new issue