#!/bin/sh

for pid in $(pidof -x vccaux_workaround_vck190.sh); do
    if [ $pid != $$ ]; then
        echo "VCCRAM_SCRIPT: Found a process already running.. So EXIT"
        exit 1
    fi
done

echo "VCCRAM_SCRIPT: Starting Poll for MIO37"

declare -i triggered=0
while [ 1 ]; do
    # var1="$(gpioget `gpiofind "DC_SYS_CTRL4"`)"
    var1="$(gpioget gpiochip0 11)"
    if [[ $var1 == 0 ]]; then
        if [[ $triggered == 1 ]]; then
            echo "Falling edge found"
            declare -i triggered=0
            python3 AuxiliaryScripts/vccaux_workaround_vck190.py --disable
        fi           
    elif [[ $var1 == 1 ]]; then
        if [[ $triggered == 0 ]]; then
            echo "Rising edge found"
            declare -i triggered=1
            python3 AuxiliaryScripts/vccaux_workaround_vck190.py --enable
        fi
    fi
done
