Terminato gertione driver e implementato prima versione beta del driver spb16ch
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 0.4.5 - xx/08/2017
|
||||||
|
- Implemented driver subsystem for interfacing with other board
|
||||||
|
- Added driver spb16ch for interfacing with "Smart Power Board 16 channel with RTC"
|
||||||
|
|
||||||
## 0.4.4 - 17/06/2017
|
## 0.4.4 - 17/06/2017
|
||||||
Remove lock/unlock from init function for resove bug
|
Remove lock/unlock from init function for resove bug
|
||||||
|
|
||||||
|
|||||||
156
conf/piGarden.conf.spb16ch.example
Normal file
156
conf/piGarden.conf.spb16ch.example
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
# Log file
|
||||||
|
LOG_FILE="/home/pi/piGarden/log/piGarden.log"
|
||||||
|
LOG_FILE_MAX_SIZE=1048576 # 1MB
|
||||||
|
|
||||||
|
# Log file for driver output
|
||||||
|
LOG_OUTPUT_DRV_FILE="/tmp/piGarden.drv.log"
|
||||||
|
|
||||||
|
# Status directory
|
||||||
|
STATUS_DIR="/home/pi/piGarden/state"
|
||||||
|
|
||||||
|
# Posizione gpio
|
||||||
|
GPIO="/usr/local/bin/gpio"
|
||||||
|
|
||||||
|
# Posizione js
|
||||||
|
JQ="/usr/local/bin/jq"
|
||||||
|
|
||||||
|
# Percorso curl
|
||||||
|
CURL="/usr/bin/curl"
|
||||||
|
|
||||||
|
# Percorso wc
|
||||||
|
WC="/usr/bin/wc"
|
||||||
|
|
||||||
|
# Percorso gzip
|
||||||
|
GZIP="/bin/gzip"
|
||||||
|
|
||||||
|
# Percorso mv
|
||||||
|
MV="/bin/mv"
|
||||||
|
|
||||||
|
# Percorso di tr
|
||||||
|
TR="/usr/bin/tr"
|
||||||
|
|
||||||
|
# Percorso di cut
|
||||||
|
CUT="/usr/bin/cut"
|
||||||
|
|
||||||
|
# Percorso tcpserver
|
||||||
|
TCPSERVER="/usr/bin/tcpserver"
|
||||||
|
|
||||||
|
# Percorso cron
|
||||||
|
CRONTAB="/usr/bin/crontab"
|
||||||
|
|
||||||
|
# Percorso grep
|
||||||
|
GREP="/bin/grep"
|
||||||
|
|
||||||
|
# Percorsp sed
|
||||||
|
SED="/bin/sed"
|
||||||
|
|
||||||
|
# Percorso readlink
|
||||||
|
READLINK="/bin/readlink"
|
||||||
|
|
||||||
|
# Percorso stat
|
||||||
|
STAT="/usr/bin/stat"
|
||||||
|
|
||||||
|
# Se impostato con il valore 1, indica che il sistema gestisce elettrovalvole monostabili,
|
||||||
|
# se impostato a 0 il sistema gestirà elettrovalvole bisstabili
|
||||||
|
EV_MONOSTABLE=1
|
||||||
|
|
||||||
|
# Id gpio usati per simulare il doppio deviatore con cui eseguire l'alimentazione alle elettrovalvole
|
||||||
|
SUPPLY_GPIO_1="drv:spb16ch:15"
|
||||||
|
SUPPLY_GPIO_2="drv:spb16ch:16"
|
||||||
|
|
||||||
|
# Stato dei due gpio per impartire l'alimentazione positiva alle elettrovalvole (aperta)
|
||||||
|
SUPPLY_GPIO_POS=0
|
||||||
|
|
||||||
|
# Stato dei due gpio per impartire l'alimentazione negativa alle elettrovalvole (chiusa)
|
||||||
|
SUPPLY_GPIO_NEG=1
|
||||||
|
|
||||||
|
# Stato di ingresso da assegnare al gpio per chiudere il rele
|
||||||
|
RELE_GPIO_CLOSE=0
|
||||||
|
|
||||||
|
# Stato di ingresso da assegnare al gpio per aprire il rele
|
||||||
|
RELE_GPIO_OPEN=1
|
||||||
|
|
||||||
|
# Id del gpio usato per collegare il sensore di rilevamento pioggia
|
||||||
|
RAIN_GPIO=
|
||||||
|
|
||||||
|
# Valore in ingresso sul gpio definito in RAIN_GPIO che indica lo stato di pioggia
|
||||||
|
RAIN_GPIO_STATE=0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Numero totale di elettrovalvole
|
||||||
|
EV_TOTAL=16
|
||||||
|
|
||||||
|
# Definizione delle elettrovalvole
|
||||||
|
EV1_ALIAS="Zona_1" #
|
||||||
|
EV1_GPIO="drv:spb16ch:1"
|
||||||
|
|
||||||
|
EV2_ALIAS="Zona_2" #
|
||||||
|
EV2_GPIO="drv:spb16ch:2"
|
||||||
|
|
||||||
|
EV3_ALIAS="Zona_3" #
|
||||||
|
EV3_GPIO="drv:spb16ch:3"
|
||||||
|
|
||||||
|
EV4_ALIAS="Zona_4" #
|
||||||
|
EV4_GPIO="drv:spb16ch:4"
|
||||||
|
|
||||||
|
EV5_ALIAS="Zona_5" #
|
||||||
|
EV5_GPIO="drv:spb16ch:5"
|
||||||
|
|
||||||
|
EV6_ALIAS="Zona_6" #
|
||||||
|
EV6_GPIO="drv:spb16ch:6"
|
||||||
|
|
||||||
|
EV7_ALIAS="Zona_7" #
|
||||||
|
EV7_GPIO="drv:spb16ch:7"
|
||||||
|
|
||||||
|
EV8_ALIAS="Zona_8" #
|
||||||
|
EV8_GPIO="drv:spb16ch:8"
|
||||||
|
|
||||||
|
EV9_ALIAS="Zona_9" #
|
||||||
|
EV9_GPIO="drv:spb16ch:9"
|
||||||
|
|
||||||
|
EV10_ALIAS="Zona_10" #
|
||||||
|
EV10_GPIO="drv:spb16ch:10"
|
||||||
|
|
||||||
|
EV11_ALIAS="Zona_11" #
|
||||||
|
EV11_GPIO="drv:spb16ch:11"
|
||||||
|
|
||||||
|
EV12_ALIAS="Zona_12" #
|
||||||
|
EV12_GPIO="drv:spb16ch:12"
|
||||||
|
|
||||||
|
EV13_ALIAS="Zona_13" #
|
||||||
|
EV13_GPIO="drv:spb16ch:13"
|
||||||
|
|
||||||
|
EV14_ALIAS="Zona_14" #
|
||||||
|
EV14_GPIO="drv:spb16ch:14"
|
||||||
|
|
||||||
|
EV15_ALIAS="Zona_15" #
|
||||||
|
EV15_GPIO="drv:spb16ch:15"
|
||||||
|
|
||||||
|
EV16_ALIAS="Zona_16" #
|
||||||
|
EV16_GPIO="drv:spb16ch:16"
|
||||||
|
|
||||||
|
|
||||||
|
# Definisce l'api key e il luogo per recuperare lo stato meteo online
|
||||||
|
WUNDERGROUND_KEY=""
|
||||||
|
WUNDERGROUND_LOCATION="IY/Monsummano" # http://www.wunderground.com/weather/api/d/docs?d=resources/country-to-iso-matching&MR=1
|
||||||
|
|
||||||
|
# Blocca l'irrigazione se l'ultima pioggia rilevata online è avvenuta nell'ultima quantità di tempo inserita.
|
||||||
|
# Il tempo è espresso in secondi. Quindi inserendo 86400, se nelle ultime 24 ore ha piovuto viene bloccata l'irrigazione. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
|
NOT_IRRIGATE_IF_RAIN_ONLINE=86400
|
||||||
|
|
||||||
|
# Il parametro è simile a quello precedente, il controllo però anziché essere fatto attingendo a wunderground, viene eseguito direttamente sul sensore se installato. Inserendo il valore zero non viene eseguito nessun controllo.
|
||||||
|
NOT_IRRIGATE_IF_RAIN_SENSOR=86400
|
||||||
|
|
||||||
|
# Indirizzo ip e porta di ascolto del socket server
|
||||||
|
TCPSERVER_IP="127.0.0.1"
|
||||||
|
TCPSERVER_PORT="8084"
|
||||||
|
|
||||||
|
# Utente e password che i clients devono utilizzare per stabilire una connessione tramite socket server
|
||||||
|
TCPSERVER_USER=""
|
||||||
|
TCPSERVER_PWD=""
|
||||||
|
|
||||||
|
# Con impostato il valore 1 non invia l'identificativi per statistiche di utilizzo
|
||||||
|
NO_SEND_IDENTIFIER=0
|
||||||
|
|
||||||
4
drv/sample/config.include.sh
Normal file
4
drv/sample/config.include.sh
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#
|
||||||
|
# File di configurazione del driver
|
||||||
|
#
|
||||||
|
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
#
|
#
|
||||||
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
|
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
|
||||||
#
|
#
|
||||||
# $1 identificativo relè 1
|
# $1 identificativo relè
|
||||||
# $2 identificativo relè 2
|
|
||||||
#
|
#
|
||||||
function drv_sample_supply_bistable_init {
|
function drv_sample_supply_bistable_init {
|
||||||
|
|
||||||
@@ -13,8 +12,7 @@ function drv_sample_supply_bistable_init {
|
|||||||
#
|
#
|
||||||
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
||||||
#
|
#
|
||||||
# $1 identificativo relè 1
|
# $1 identificativo relè
|
||||||
# $2 identificativo relè 2
|
|
||||||
#
|
#
|
||||||
function drv_sample_supply_positive {
|
function drv_sample_supply_positive {
|
||||||
|
|
||||||
@@ -25,8 +23,7 @@ function drv_sample_supply_positive {
|
|||||||
#
|
#
|
||||||
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
||||||
#
|
#
|
||||||
# $1 identificativo relè 1
|
# $1 identificativo relè
|
||||||
# $2 identificativo relè 2
|
|
||||||
#
|
#
|
||||||
function drv_sample_supply_negative {
|
function drv_sample_supply_negative {
|
||||||
|
|
||||||
|
|||||||
7
drv/spb16ch/README.md
Normal file
7
drv/spb16ch/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Driver per controllare la scheda "Smart Power Board 16 channel with RTC" (spb16ch)
|
||||||
|
|
||||||
|
Questo driver richiede l'interprete python e la libreria python-smbus. Inoltre l'utente pi deve fare parte del gruppo i2c
|
||||||
|
|
||||||
|
sudo apt-get install python python-smbus
|
||||||
|
sudo usermod -a -G i2c pi
|
||||||
|
|
||||||
20
drv/spb16ch/config.include.sh
Normal file
20
drv/spb16ch/config.include.sh
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#
|
||||||
|
# Mapping rele spb16ch: l'indice indica il relè, ogni elemento deve essere lungo quattro caratteri,
|
||||||
|
# i primi due indicano il mux channel, mentre gli ultimi due caratteri indicano il numero del rele sul canale
|
||||||
|
#
|
||||||
|
SPB16CH_RELE_MAP[1]=" 0 1"
|
||||||
|
SPB16CH_RELE_MAP[2]=" 0 2"
|
||||||
|
SPB16CH_RELE_MAP[3]=" 0 3"
|
||||||
|
SPB16CH_RELE_MAP[4]=" 0 4"
|
||||||
|
SPB16CH_RELE_MAP[5]=" 0 5"
|
||||||
|
SPB16CH_RELE_MAP[6]=" 0 6"
|
||||||
|
SPB16CH_RELE_MAP[7]=" 0 7"
|
||||||
|
SPB16CH_RELE_MAP[8]=" 0 8"
|
||||||
|
SPB16CH_RELE_MAP[9]=" 1 1"
|
||||||
|
SPB16CH_RELE_MAP[10]=" 1 2"
|
||||||
|
SPB16CH_RELE_MAP[11]=" 1 3"
|
||||||
|
SPB16CH_RELE_MAP[12]=" 1 4"
|
||||||
|
SPB16CH_RELE_MAP[13]=" 1 5"
|
||||||
|
SPB16CH_RELE_MAP[14]=" 1 6"
|
||||||
|
SPB16CH_RELE_MAP[15]=" 1 7"
|
||||||
|
SPB16CH_RELE_MAP[16]=" 1 8"
|
||||||
13
drv/spb16ch/init.include.sh
Normal file
13
drv/spb16ch/init.include.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#
|
||||||
|
# Questa funzione viene inviocata dalla funzione "init" di piGarden se sono presenti elettrovalvole o sensori che utilizzano questo driver
|
||||||
|
#
|
||||||
|
function drv_spb16ch_init {
|
||||||
|
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py 72 0
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/gpo_init.py 25 255 0
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py 72 1
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/gpo_init.py 25 255 0
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py 72 0
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
23
drv/spb16ch/rainsensor.include.sh
Normal file
23
drv/spb16ch/rainsensor.include.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#
|
||||||
|
# Inizializza il sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
function drv_spb16ch_rain_sensor_init {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Ritorna lo stato del sensore di rilevamento pioggia
|
||||||
|
#
|
||||||
|
# $i identificativo gpio del sensore di pioggia
|
||||||
|
#
|
||||||
|
function drv_spb16ch_rain_sensor_get {
|
||||||
|
|
||||||
|
local FOO="bar"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
58
drv/spb16ch/rele.include.sh
Normal file
58
drv/spb16ch/rele.include.sh
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#
|
||||||
|
# Inizializzazione rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da inizializzare
|
||||||
|
#
|
||||||
|
function drv_spb16ch_rele_init {
|
||||||
|
|
||||||
|
drv_spb16ch_rele_open "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Apertura rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da aprire
|
||||||
|
#
|
||||||
|
function drv_spb16ch_rele_open {
|
||||||
|
|
||||||
|
local rele_id=`echo $1 | $CUT -d':' -f3,3`
|
||||||
|
local rele_data=${SPB16CH_RELE_MAP[$rele_id]}
|
||||||
|
if [[ -z $rele_data ]]; then
|
||||||
|
local message="Error - Rele map not defined - rele_id=$rele_id - ($1)"
|
||||||
|
log_write "$message"
|
||||||
|
message_write "warning" "$message"
|
||||||
|
fi
|
||||||
|
local channel_num=${rele_data:0:2}
|
||||||
|
local rele_num=${rele_data:2:2}
|
||||||
|
|
||||||
|
echo channel_num=$channel_num
|
||||||
|
echo rele_num=$rele_num
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py 72 $channel_num
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/gpo_active.py 72 $rele_num 0
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Chiusura rele
|
||||||
|
#
|
||||||
|
# $1 identificativo relè da chiudere
|
||||||
|
#
|
||||||
|
function drv_spb16ch_rele_close {
|
||||||
|
|
||||||
|
local rele_id=`echo $1 | $CUT -d':' -f3,3`
|
||||||
|
local rele_data=${SPB16CH_RELE_MAP[$rele_id]}
|
||||||
|
if [[ -z $rele_data ]]; then
|
||||||
|
local message="Error - Rele map not defined - rele_id=$rele_id - ($1)"
|
||||||
|
log_write "$message"
|
||||||
|
message_write "warning" "$message"
|
||||||
|
fi
|
||||||
|
local channel_num=${rele_data:0:2}
|
||||||
|
local rele_num=${rele_data:2:2}
|
||||||
|
|
||||||
|
echo channel_num=$channel_num
|
||||||
|
echo rele_num=$rele_num
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py 72 $channel_num
|
||||||
|
$DIR_SCRIPT/drv/spb16ch/scripts/gpo_active.py 72 $rele_num 1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
37
drv/spb16ch/scripts/ee_read.py
Executable file
37
drv/spb16ch/scripts/ee_read.py
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
# Read the eeprom 24C16
|
||||||
|
# I2C Address: 0x50 (24C16)
|
||||||
|
# sudo ./ee_read.py 0x50 address
|
||||||
|
# Example: sudo ./ee_read.py 50 0
|
||||||
|
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import smbus
|
||||||
|
|
||||||
|
def I2C_setup(i2c_address, eeprom_address):
|
||||||
|
I2C_address = 0x50
|
||||||
|
if GPIO.RPI_REVISION in [2, 3]:
|
||||||
|
I2C_bus_number = 1
|
||||||
|
else:
|
||||||
|
I2C_bus_number = 0
|
||||||
|
bus = smbus.SMBus(I2C_bus_number)
|
||||||
|
#bus.read_byte_data(I2C_address, eeprom_address)
|
||||||
|
print("24C16 ADDRESS: {}".format(bin(eeprom_address)))
|
||||||
|
print("24C16 DATA: {}".format(bin(bus.read_byte_data(I2C_address, eeprom_address))))
|
||||||
|
print("24C16 DATA: {}".format(hex(bus.read_byte_data(I2C_address, eeprom_address))))
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
parser = argparse.ArgumentParser(description='Select address to read data on eeprom 24C16 ')
|
||||||
|
parser.add_argument('i2c_address', type=int)
|
||||||
|
parser.add_argument('eeprom_address', type=int)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
I2C_setup(args.i2c_address, args.eeprom_address)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menu()
|
||||||
35
drv/spb16ch/scripts/ee_write.py
Executable file
35
drv/spb16ch/scripts/ee_write.py
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
# Write the eeprom 24C16
|
||||||
|
# I2C Address: 0x50 (24C16)
|
||||||
|
# sudo ./ee_write.py 0x50 address data
|
||||||
|
# Example: sudo ./ee_write.py 50 0 1
|
||||||
|
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import smbus
|
||||||
|
|
||||||
|
def I2C_setup(i2c_address, eeprom_address, eeprom_data):
|
||||||
|
I2C_address = 0x50
|
||||||
|
if GPIO.RPI_REVISION in [2, 3]:
|
||||||
|
I2C_bus_number = 1
|
||||||
|
else:
|
||||||
|
I2C_bus_number = 0
|
||||||
|
bus = smbus.SMBus(I2C_bus_number)
|
||||||
|
bus.write_byte_data(I2C_address, eeprom_address, eeprom_data)
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
parser = argparse.ArgumentParser(description='Select address and data to write on eeprom 24C16 ')
|
||||||
|
parser.add_argument('i2c_address', type=int)
|
||||||
|
parser.add_argument('eeprom_address', type=int)
|
||||||
|
parser.add_argument('eeprom_data', type=int)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
I2C_setup(args.i2c_address, args.eeprom_address, args.eeprom_data)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menu()
|
||||||
44
drv/spb16ch/scripts/gpo_active.py
Executable file
44
drv/spb16ch/scripts/gpo_active.py
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
# Select address and channel of PCA9571 I2C general purpose outputs
|
||||||
|
# I2C Address: 0x25 Fixed
|
||||||
|
# sudo ./gpo_active.py CHANNEL
|
||||||
|
# Example: sudo ./gpo_active.py 25 255 1 #all relays activates
|
||||||
|
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import smbus
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def I2C_setup(multiplexer_i2c_address, i2c_channel_setup, state):
|
||||||
|
I2C_address = 0x25
|
||||||
|
if GPIO.RPI_REVISION in [2, 3]:
|
||||||
|
I2C_bus_number = 1
|
||||||
|
else:
|
||||||
|
I2C_bus_number = 0
|
||||||
|
|
||||||
|
bus = smbus.SMBus(I2C_bus_number)
|
||||||
|
status_outputs=bus.read_byte(I2C_address)
|
||||||
|
if state == 1:
|
||||||
|
i2c_channel_setup=status_outputs|i2c_channel_setup
|
||||||
|
elif state == 0:
|
||||||
|
i2c_channel_setup=(-i2c_channel_setup-1)&status_outputs
|
||||||
|
elif state == -1:
|
||||||
|
i2c_channel_setup=0
|
||||||
|
bus.write_byte(I2C_address, i2c_channel_setup)
|
||||||
|
#time.sleep(0)
|
||||||
|
|
||||||
|
file = open("rl1", "r")
|
||||||
|
address=int(file.readline())
|
||||||
|
channel_outputs=int(file.readline())
|
||||||
|
state=int(file.readline())
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
I2C_setup(address, channel_outputs, state)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menu()
|
||||||
44
drv/spb16ch/scripts/gpo_init.py
Executable file
44
drv/spb16ch/scripts/gpo_init.py
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
# Select address and channel of PCA9571 I2C general purpose outputs
|
||||||
|
# I2C Address: 0x25 Fixed
|
||||||
|
# sudo ./gpo_active.py CHANNEL
|
||||||
|
# Example: sudo ./gpo_active.py 25 255 1 #all relays activates
|
||||||
|
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import smbus
|
||||||
|
|
||||||
|
def I2C_setup(multiplexer_i2c_address, i2c_channel_setup, state):
|
||||||
|
I2C_address = 0x25
|
||||||
|
if GPIO.RPI_REVISION in [2, 3]:
|
||||||
|
I2C_bus_number = 1
|
||||||
|
else:
|
||||||
|
I2C_bus_number = 0
|
||||||
|
|
||||||
|
bus = smbus.SMBus(I2C_bus_number)
|
||||||
|
status_outputs=bus.read_byte(I2C_address)
|
||||||
|
if state == 1:
|
||||||
|
i2c_channel_setup=status_outputs|i2c_channel_setup
|
||||||
|
elif state == 0:
|
||||||
|
i2c_channel_setup=(-i2c_channel_setup-1)&status_outputs
|
||||||
|
elif state == -1:
|
||||||
|
i2c_channel_setup=0
|
||||||
|
bus.write_byte(I2C_address, i2c_channel_setup)
|
||||||
|
#time.sleep(0)
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
parser = argparse.ArgumentParser(description='Select channel outputs of PCA9571')
|
||||||
|
parser.add_argument('address', type=int)
|
||||||
|
parser.add_argument('channel_outputs', type=int)
|
||||||
|
parser.add_argument('state', type=int)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
I2C_setup(args.address, args.channel_outputs, args.state)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menu()
|
||||||
33
drv/spb16ch/scripts/gpo_read.py
Executable file
33
drv/spb16ch/scripts/gpo_read.py
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
# Select address and channel of PCA9571 I2C general purpose outputs
|
||||||
|
# I2C Address: 0x25 Fixed
|
||||||
|
# sudo ./gpo_read.py CHANNEL
|
||||||
|
# Example: sudo ./gpo_read.py 25
|
||||||
|
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import smbus
|
||||||
|
|
||||||
|
def I2C_read(multiplexer_i2c_address):
|
||||||
|
I2C_address = 0x25
|
||||||
|
if GPIO.RPI_REVISION in [2, 3]:
|
||||||
|
I2C_bus_number = 1
|
||||||
|
else:
|
||||||
|
I2C_bus_number = 0
|
||||||
|
|
||||||
|
bus = smbus.SMBus(I2C_bus_number)
|
||||||
|
status_outputs=bus.read_byte(I2C_address)
|
||||||
|
time.sleep(0)
|
||||||
|
# print("PCA9571 sts:{}".format(bin(bus.read_byte(I2C_address))))
|
||||||
|
print("PCA9571 GPO sts:{}".format(hex(bus.read_byte(I2C_address))))
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
|
||||||
|
I2C_read(0x25)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menu()
|
||||||
3
drv/spb16ch/scripts/gpo_send
Executable file
3
drv/spb16ch/scripts/gpo_send
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
25
|
||||||
|
100
|
||||||
|
1
|
||||||
1
drv/spb16ch/scripts/gpo_states
Executable file
1
drv/spb16ch/scripts/gpo_states
Executable file
@@ -0,0 +1 @@
|
|||||||
|
PCA9571 GPO sts:0x64
|
||||||
5
drv/spb16ch/scripts/init.sh
Executable file
5
drv/spb16ch/scripts/init.sh
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
./mux_channel.py 72 0
|
||||||
|
./gpo_init.py 25 255 0
|
||||||
|
./mux_channel.py 72 1
|
||||||
|
./gpo_init.py 25 255 0
|
||||||
|
./mux_channel.py 72 0
|
||||||
38
drv/spb16ch/scripts/mux_channel.py
Executable file
38
drv/spb16ch/scripts/mux_channel.py
Executable file
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
# Select address and channel of PCA9547 I2C multiplexer
|
||||||
|
# I2C Address: 0xYY, where YY can be 70 through 77
|
||||||
|
# Multiplexer Channel: 1 - 8
|
||||||
|
# sudo ./mux_channel.py ADDRESS CHANNEL
|
||||||
|
# Example: sudo ./mux_channel.py 70 1
|
||||||
|
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import smbus
|
||||||
|
|
||||||
|
def I2C_setup(multiplexer_i2c_address, i2c_channel_setup):
|
||||||
|
I2C_address = 0x70 + multiplexer_i2c_address % 10
|
||||||
|
if GPIO.RPI_REVISION in [2, 3]:
|
||||||
|
I2C_bus_number = 1
|
||||||
|
else:
|
||||||
|
I2C_bus_number = 0
|
||||||
|
|
||||||
|
bus = smbus.SMBus(I2C_bus_number)
|
||||||
|
i2c_channel_setup=i2c_channel_setup + 0x08
|
||||||
|
bus.write_byte(I2C_address, i2c_channel_setup)
|
||||||
|
#time.sleep(0.1)
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
parser = argparse.ArgumentParser(description='Select channel of PCA9547 I2C multiplexer')
|
||||||
|
parser.add_argument('address', type=int)
|
||||||
|
parser.add_argument('channel', type=int)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
I2C_setup(args.address, args.channel)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menu()
|
||||||
37
drv/spb16ch/scripts/mux_read.py
Executable file
37
drv/spb16ch/scripts/mux_read.py
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
# Select address and channel of PCA9547 I2C multiplexer
|
||||||
|
# I2C Address: 0xYY, where YY can be 70 through 77
|
||||||
|
# Multiplexer Channel: 1 - 8
|
||||||
|
# sudo ./mux_read.py ADDRESS
|
||||||
|
# Example: sudo ./mux_read.py 70
|
||||||
|
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import smbus
|
||||||
|
|
||||||
|
def I2C_setup(multiplexer_i2c_address):
|
||||||
|
I2C_address = 0x70 + multiplexer_i2c_address % 10
|
||||||
|
if GPIO.RPI_REVISION in [2, 3]:
|
||||||
|
I2C_bus_number = 1
|
||||||
|
else:
|
||||||
|
I2C_bus_number = 0
|
||||||
|
|
||||||
|
bus = smbus.SMBus(I2C_bus_number)
|
||||||
|
time.sleep(0.1)
|
||||||
|
# print("PCA9547 MUX sts:{}".format(bin(bus.read_byte(I2C_address))))
|
||||||
|
print("PCA9547 MUX sts:{}".format(hex(bus.read_byte(I2C_address))))
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
parser = argparse.ArgumentParser(description='Select channel of PCA9547 I2C multiplexer')
|
||||||
|
parser.add_argument('address', type=int)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
I2C_setup(args.address)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menu()
|
||||||
1
drv/spb16ch/scripts/mux_states
Executable file
1
drv/spb16ch/scripts/mux_states
Executable file
@@ -0,0 +1 @@
|
|||||||
|
PCA9547 MUX sts:0x8
|
||||||
6
drv/spb16ch/scripts/read_muxfile.py
Executable file
6
drv/spb16ch/scripts/read_muxfile.py
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
file = open("mux", "r")
|
||||||
|
line1=file.readline()
|
||||||
|
print line1
|
||||||
33
drv/spb16ch/scripts/rele1_16
Executable file
33
drv/spb16ch/scripts/rele1_16
Executable file
@@ -0,0 +1,33 @@
|
|||||||
|
25
|
||||||
|
1
|
||||||
|
0
|
||||||
|
2
|
||||||
|
0
|
||||||
|
4
|
||||||
|
0
|
||||||
|
8
|
||||||
|
0
|
||||||
|
16
|
||||||
|
1
|
||||||
|
32
|
||||||
|
1
|
||||||
|
64
|
||||||
|
1
|
||||||
|
128
|
||||||
|
1
|
||||||
|
1
|
||||||
|
0
|
||||||
|
2
|
||||||
|
0
|
||||||
|
4
|
||||||
|
0
|
||||||
|
8
|
||||||
|
0
|
||||||
|
16
|
||||||
|
1
|
||||||
|
32
|
||||||
|
1
|
||||||
|
64
|
||||||
|
1
|
||||||
|
128
|
||||||
|
1
|
||||||
95
drv/spb16ch/scripts/rele_1_16_active.py
Executable file
95
drv/spb16ch/scripts/rele_1_16_active.py
Executable file
@@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
# Select address and channel of PCA9571 I2C general purpose outputs
|
||||||
|
# I2C Address: 0x25 Fixed
|
||||||
|
# sudo ./gpo_active.py CHANNEL
|
||||||
|
# Example: sudo ./gpo_active.py 25 255 1 #all relays activates
|
||||||
|
|
||||||
|
import time
|
||||||
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
|
import smbus
|
||||||
|
|
||||||
|
|
||||||
|
def I2C_setup(multiplexer_i2c_address, i2c_channel_setup, state):
|
||||||
|
I2C_address = 0x25
|
||||||
|
if GPIO.RPI_REVISION in [2, 3]:
|
||||||
|
I2C_bus_number = 1
|
||||||
|
else:
|
||||||
|
I2C_bus_number = 0
|
||||||
|
|
||||||
|
bus = smbus.SMBus(I2C_bus_number)
|
||||||
|
status_outputs=bus.read_byte(I2C_address)
|
||||||
|
if state == 1:
|
||||||
|
i2c_channel_setup=status_outputs|i2c_channel_setup
|
||||||
|
elif state == 0:
|
||||||
|
i2c_channel_setup=(-i2c_channel_setup-1)&status_outputs
|
||||||
|
elif state == -1:
|
||||||
|
i2c_channel_setup=0
|
||||||
|
bus.write_byte(I2C_address, i2c_channel_setup)
|
||||||
|
#time.sleep(0)
|
||||||
|
|
||||||
|
|
||||||
|
def menu():
|
||||||
|
while 1==1:
|
||||||
|
subprocess.call('./mux_channel.py 72 0', shell=True)
|
||||||
|
#time.sleep(0.1)
|
||||||
|
file = open("rele1_16", "r")
|
||||||
|
address=int(file.readline())
|
||||||
|
channel_outputs1=int(file.readline())
|
||||||
|
state1=int(file.readline())
|
||||||
|
channel_outputs2=int(file.readline())
|
||||||
|
state2=int(file.readline())
|
||||||
|
channel_outputs3=int(file.readline())
|
||||||
|
state3=int(file.readline())
|
||||||
|
channel_outputs4=int(file.readline())
|
||||||
|
state4=int(file.readline())
|
||||||
|
channel_outputs5=int(file.readline())
|
||||||
|
state5=int(file.readline())
|
||||||
|
channel_outputs6=int(file.readline())
|
||||||
|
state6=int(file.readline())
|
||||||
|
channel_outputs7=int(file.readline())
|
||||||
|
state7=int(file.readline())
|
||||||
|
channel_outputs8=int(file.readline())
|
||||||
|
state8=int(file.readline())
|
||||||
|
channel_outputs9=int(file.readline())
|
||||||
|
state9=int(file.readline())
|
||||||
|
channel_outputs10=int(file.readline())
|
||||||
|
state10=int(file.readline())
|
||||||
|
channel_outputs11=int(file.readline())
|
||||||
|
state11=int(file.readline())
|
||||||
|
channel_outputs12=int(file.readline())
|
||||||
|
state12=int(file.readline())
|
||||||
|
channel_outputs13=int(file.readline())
|
||||||
|
state13=int(file.readline())
|
||||||
|
channel_outputs14=int(file.readline())
|
||||||
|
state14=int(file.readline())
|
||||||
|
channel_outputs15=int(file.readline())
|
||||||
|
state15=int(file.readline())
|
||||||
|
channel_outputs16=int(file.readline())
|
||||||
|
state16=int(file.readline())
|
||||||
|
I2C_setup(address, channel_outputs1, state1)
|
||||||
|
I2C_setup(address, channel_outputs2, state2)
|
||||||
|
I2C_setup(address, channel_outputs3, state3)
|
||||||
|
I2C_setup(address, channel_outputs4, state4)
|
||||||
|
I2C_setup(address, channel_outputs5, state5)
|
||||||
|
I2C_setup(address, channel_outputs6, state6)
|
||||||
|
I2C_setup(address, channel_outputs7, state7)
|
||||||
|
I2C_setup(address, channel_outputs8, state8)
|
||||||
|
subprocess.call('./mux_channel.py 72 1', shell=True)
|
||||||
|
#time.sleep(0.1)
|
||||||
|
I2C_setup(address, channel_outputs9, state9)
|
||||||
|
I2C_setup(address, channel_outputs10, state10)
|
||||||
|
I2C_setup(address, channel_outputs11, state11)
|
||||||
|
I2C_setup(address, channel_outputs12, state12)
|
||||||
|
I2C_setup(address, channel_outputs13, state13)
|
||||||
|
I2C_setup(address, channel_outputs14, state14)
|
||||||
|
I2C_setup(address, channel_outputs15, state15)
|
||||||
|
I2C_setup(address, channel_outputs16, state16)
|
||||||
|
subprocess.call('./mux_channel.py 72 0', shell=True)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
menu()
|
||||||
34
drv/spb16ch/supply.include.sh
Normal file
34
drv/spb16ch/supply.include.sh
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#
|
||||||
|
# Inizializza i rele che gestiscono l'alimentazione per le valvole bistabili
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_spb16ch_supply_bistable_init {
|
||||||
|
|
||||||
|
drv_spb16ch_supply_negative "$1"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio positivo
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_spb16ch_supply_positive {
|
||||||
|
|
||||||
|
drv_spb16ch_rele_open "$1"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Imposta l'alimentazione delle elettrovalvole con voltaggio negativo
|
||||||
|
#
|
||||||
|
# $1 identificativo relè
|
||||||
|
#
|
||||||
|
function drv_spb16ch_supply_negative {
|
||||||
|
|
||||||
|
drv_spb16ch_rele_close "$1"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ function setup_drv {
|
|||||||
local file_drv
|
local file_drv
|
||||||
for drv in "${list_drv[@]}"
|
for drv in "${list_drv[@]}"
|
||||||
do
|
do
|
||||||
for callback in init rele supply rainsensor
|
for callback in config init rele supply rainsensor
|
||||||
do
|
do
|
||||||
file_drv="$DIR_SCRIPT/drv/$drv/$callback.include.sh"
|
file_drv="$DIR_SCRIPT/drv/$drv/$callback.include.sh"
|
||||||
if [ -f "$file_drv" ]; then
|
if [ -f "$file_drv" ]; then
|
||||||
@@ -78,14 +78,14 @@ function drv_rele_init {
|
|||||||
|
|
||||||
# Nessun driver definito, esegue la chiusura del relè tramite gpio del raspberry
|
# Nessun driver definito, esegue la chiusura del relè tramite gpio del raspberry
|
||||||
if [ -z "$fnc" ]; then
|
if [ -z "$fnc" ]; then
|
||||||
$GPIO -g write $idx RELE_GPIO_OPEN # chiude l'alimentazione all'elettrovalvole
|
$GPIO -g write $idx $RELE_GPIO_OPEN # chiude l'alimentazione all'elettrovalvole
|
||||||
$GPIO -g mode $idx out # setta il gpio nella modalita di scrittura
|
$GPIO -g mode $idx out # setta il gpio nella modalita di scrittura
|
||||||
# Il driver definito non è stato trovato
|
# Il driver definito non è stato trovato
|
||||||
elif [ "$fnc" == "drvnotfound" ]; then
|
elif [ "$fnc" == "drvnotfound" ]; then
|
||||||
log_write "Driver not found: $idx"
|
log_write "Driver not found: $idx"
|
||||||
message_write "warning" "Driver not found: $idx"
|
message_write "warning" "Driver not found: $idx"
|
||||||
else
|
else
|
||||||
echo "$(date) $fnc arg:$idx" > "$LOG_OUTPUT_DRV_FILE"
|
echo "$(date) $fnc arg:$idx" >> "$LOG_OUTPUT_DRV_FILE"
|
||||||
$fnc "$idx" >> "$LOG_OUTPUT_DRV_FILE" 2>&1
|
$fnc "$idx" >> "$LOG_OUTPUT_DRV_FILE" 2>&1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ function initialize {
|
|||||||
# Iniziazlizza i driver gpio
|
# Iniziazlizza i driver gpio
|
||||||
for drv in "${list_drv[@]}"
|
for drv in "${list_drv[@]}"
|
||||||
do
|
do
|
||||||
|
echo "$(date) drv_${drv}_init"
|
||||||
drv_${drv}_init
|
drv_${drv}_init
|
||||||
done
|
done &> "$LOG_OUTPUT_DRV_FILE"
|
||||||
|
|
||||||
# Imposta l'alimentazione con voltaggio negativo e setta i gpio in scrittura per le elettrovalvole bistabili
|
# Imposta l'alimentazione con voltaggio negativo e setta i gpio in scrittura per le elettrovalvole bistabili
|
||||||
if [ "$EV_MONOSTABLE" != "1" ]; then
|
if [ "$EV_MONOSTABLE" != "1" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user