diff --git a/conf/piGarden.conf.spb16ch.example b/conf/piGarden.conf.spb16ch.example index 7d03e74..7c48b21 100644 --- a/conf/piGarden.conf.spb16ch.example +++ b/conf/piGarden.conf.spb16ch.example @@ -496,8 +496,8 @@ NO_SEND_IDENTIFIER=0 # # Stato da assegnare ai gpio per abilitare/disabilitare le schede spb16ch -SPB16CH_GPIO_ON=0 -SPB16CH_GPIO_OFF=1 +SPB16CH_GPIO_ON=1 +SPB16CH_GPIO_OFF=0 # Gpio di per gestire l'abilitazione/disabilitazione delle chede spb16ch SPB16CH1_GPIO=17 # Physical 11 - wPi 0 diff --git a/drv/spb16ch/common.include.sh b/drv/spb16ch/common.include.sh index 7ee0f57..9013923 100644 --- a/drv/spb16ch/common.include.sh +++ b/drv/spb16ch/common.include.sh @@ -10,8 +10,6 @@ function drv_spb16ch_board_enable { local board_id=$1 - drv_spb16ch_board_disable_all - local a=SPB16CH"$board_id"_GPIO local gpio_n=${!a} @@ -20,6 +18,22 @@ function drv_spb16ch_board_enable { } +# +# Disabilita una scheda spb16ch +# $1 identificativo scheda da disabilitare +# +function drv_spb16ch_board_disable { + + local board_id=$1 + + local a=SPB16CH"$board_id"_GPIO + local gpio_n=${!a} + + echo "** drv_spb16ch_board_disable() - Disable board: $board_id - gpio $gpio_n" + $GPIO -g write $gpio_n $SPB16CH_GPIO_OFF + +} + # # Disabilita tutte le schede # @@ -39,3 +53,28 @@ function drv_spb16ch_board_disable_all { } +# +# Memorizza in un file di appoggio gli id delle schede spb16ch utilizzate +# +function drv_spb16ch_boards_id_store { + + echo "${SPB16CH_USED_ID[@]}" > "$SPB16CH_BOARD_ID_STORE_FILE" + +} + +# +# Recupera gli di delle schede spb16ch utilizzate leggendoli dal file di appoggio +# $1 identificativi schede da salvare +# +function drv_spb16ch_boards_id_load { + + if [ -f "$SPB16CH_BOARD_ID_STORE_FILE" ]; then + for board_id in $(cat "$SPB16CH_BOARD_ID_STORE_FILE") + do + SPB16CH_USED_ID+=("$board_id") + done + else + log_write "spb16ch: file $SPB16CH_BOARD_ID_STORE_FILE not found: remember to run 'piGarden init' to generate the file" + fi + +} diff --git a/drv/spb16ch/config.include.sh b/drv/spb16ch/config.include.sh index 8189c67..81adf07 100644 --- a/drv/spb16ch/config.include.sh +++ b/drv/spb16ch/config.include.sh @@ -155,4 +155,6 @@ SPB16CH_RELE_MAP[128]="77|1|128|8" declare -g -a SPB16CH_USED_ID SPB16CH_USED_ID=() - +# Nome del file dove memorizzare gli id delle schede utilizzate +declare -g SPB16CH_BOARD_ID_STORE_FILE +SPB16CH_BOARD_ID_STORE_FILE="$STATUS_DIR/spb16ch_board_id_store" diff --git a/drv/spb16ch/init.include.sh b/drv/spb16ch/init.include.sh index 340034b..0853692 100644 --- a/drv/spb16ch/init.include.sh +++ b/drv/spb16ch/init.include.sh @@ -5,8 +5,10 @@ function drv_spb16ch_init { declare -a address_used address_used=() + SPB16CH_USED_ID=() local address="" + local board_id="" # Cerca gli indirizzi delle schede spb16ch utilizzate per i rele utilizzati per le zone for i in $(seq $EV_TOTAL) @@ -18,8 +20,10 @@ function drv_spb16ch_init { local rele_data=${SPB16CH_RELE_MAP[$rele_id]} if [[ ! -z $rele_data ]]; then local address_num=${rele_data:0:2} + local board_id=${rele_data:9:1} if [[ ! " ${address_used[@]} " =~ " ${address_num} " ]]; then address_used+=("$address_num") + SPB16CH_USED_ID+=("$board_id") fi fi fi @@ -33,24 +37,17 @@ function drv_spb16ch_init { local rele_data=${SPB16CH_RELE_MAP[$rele_id]} if [[ ! -z $rele_data ]]; then local address_num=${rele_data:0:2} + local board_id=${rele_data:9:1} if [[ ! " ${address_used[@]} " =~ " ${address_num} " ]]; then address_used+=("$address_num") + SPB16CH_USED_ID+=("$board_id") fi fi fi done - # Esegue l'inizializzazione delle schede spb16ch trovate - local address_num - for address_num in ${address_used[@]} - do - echo "****** Inizializzazione address_num = $address_num *******" - $DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py $address_num 0 - $DIR_SCRIPT/drv/spb16ch/scripts/gpo_init.py 25 255 0 - $DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py $address_num 1 - $DIR_SCRIPT/drv/spb16ch/scripts/gpo_init.py 25 255 0 - $DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py $address_num 0 - done + # Memorizza gli id delle schede usate + drv_spb16ch_boards_id_store # Esegue l'inizializzazione dei gpio che gestiscono l'abilitazine/disabilitazione delle schede local board_id @@ -62,6 +59,24 @@ function drv_spb16ch_init { echo "******** Number used board: $board_id - inizializzazione gpio $gpio_n" $GPIO -g mode $gpio_n out done + drv_spb16ch_board_disable_all + + # Esegue l'inizializzazione delle schede spb16ch trovate + local address_num="" + local board_num="" + for i in ${!address_used[@]} + do + address_num=${address_used[$i]} + board_num=${SPB16CH_USED_ID[$i]} + drv_spb16ch_board_enable $board_num + echo "****** Inizializzazione address_num = $address_num - board_num = $board_num *******" + $DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py $address_num 0 + $DIR_SCRIPT/drv/spb16ch/scripts/gpo_init.py 25 255 0 + $DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py $address_num 1 + $DIR_SCRIPT/drv/spb16ch/scripts/gpo_init.py 25 255 0 + $DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py $address_num 0 + drv_spb16ch_board_disable $board_id + done } diff --git a/drv/spb16ch/rele.include.sh b/drv/spb16ch/rele.include.sh index f8ddbea..b08f399 100644 --- a/drv/spb16ch/rele.include.sh +++ b/drv/spb16ch/rele.include.sh @@ -35,6 +35,8 @@ function drv_spb16ch_rele_open { $DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py $address_num $channel_num $DIR_SCRIPT/drv/spb16ch/scripts/gpo_init.py $address_num $rele_num 0 + drv_spb16ch_board_disable $board_id + } # @@ -64,5 +66,7 @@ function drv_spb16ch_rele_close { $DIR_SCRIPT/drv/spb16ch/scripts/mux_channel.py $address_num $channel_num $DIR_SCRIPT/drv/spb16ch/scripts/gpo_init.py $address_num $rele_num 1 + drv_spb16ch_board_disable $board_id + } diff --git a/drv/spb16ch/setup.include.sh b/drv/spb16ch/setup.include.sh index 352d433..e9a19af 100644 --- a/drv/spb16ch/setup.include.sh +++ b/drv/spb16ch/setup.include.sh @@ -4,39 +4,9 @@ # function drv_spb16ch_setup { - # Cerca gli identificativi delle schede spb16ch utilizzate per i rele utilizzati per le zone - for i in $(seq $EV_TOTAL) - do - local a=EV"$i"_GPIO - local gpio="${!a}" - if [[ "$gpio" == drv:spb16ch:* ]]; then - local rele_id=`echo $gpio | $CUT -d':' -f3,3` - local rele_data=${SPB16CH_RELE_MAP[$rele_id]} - if [[ ! -z $rele_data ]]; then - local board_id=${rele_data:9:1} - if [[ ! " ${SPB16CH_USED_ID[@]} " =~ " ${board_id} " ]]; then - SPB16CH_USED_ID+=("$board_id") - fi - fi - fi - done - - # Cerca gli identificativi schede spb16ch utilizzate che gestiscono l'alimentazione delle elettrovalvole bistabili - for gpio in "$SUPPLY_GPIO_1" "$SUPPLY_GPIO_2" - do - if [[ "$gpio" == drv:spb16ch:* ]]; then - local rele_id=`echo $gpio | $CUT -d':' -f3,3` - local rele_data=${SPB16CH_RELE_MAP[$rele_id]} - if [[ ! -z $rele_data ]]; then - local board_id=${rele_data:9:1} - if [[ ! " ${SPB16CH_USED_ID[@]} " =~ " ${board_id} " ]]; then - SPB16CH_USED_ID+=("$board_id") - fi - fi - fi - done - - echo "Identificativi board spb16ch utilizzate: ${SPB16CH_USED_ID[@]}" + drv_spb16ch_boards_id_load + echo "*********** drv_spb16ch_setup: identificativi schede caricati: ${SPB16CH_USED_ID[@]}" } +