1. 程式人生 > >分享一段shell指令碼--su許可權下自動讀取某個GPIO電平,判斷為低即自動關機的功能

分享一段shell指令碼--su許可權下自動讀取某個GPIO電平,判斷為低即自動關機的功能

以下內容均為原創,歡迎轉載,轉載請說明來源:https://blog.csdn.net/masterbee/article/details/78832701

sudo sh -c "echo 50 > /sys/class/gpio/export"

sudo sh -c "echo "in" > /sys/class/gpio/gpio50/direction"

while(true)
do
gpiovalue=`sudo cat /sys/class/gpio/gpio50/value`
# sleep 3
# echo "gpio:$((gpiovalue))";
if [ "$gpiovalue" = 0 ];
 
then
{
echo "shut down system";
shutdown -h now
}
fi
sleep 3
done
sudo sh -c "echo 50 > /sys/class/gpio/unexport"