シャットダウン
ファイルの設定
シャットダウン用のシェルスクリプト作成
cd
sudo vi shutdown-daemon.sh
sudo chmod 755 shutdown-daemon.sh
作成するシェルスクリプトの内容
#!/bin/sh
GPIO=22 #使用するGPIOポート
PUSHTIME=5 #押す秒数
#初期設定
echo "$GPIO" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio$GPIO/direction
echo "low" > /sys/class/gpio/gpio$GPIO/direction
#5秒間押されるまで待つ
cnt=0
while [ $cnt -lt $PUSHTIME ] ; do
data=`cat /sys/class/gpio/gpio$GPIO/value` if [ "$data" -eq "1" ] ; then cnt=`expr $cnt + 1` else cnt=0 fi sleep 1
done
#シャットダウンの実行
shutdown -h now
作成したシェルスクリプトを起動時に実行するようにする
sudo vi /etc/rc.local
変更前
# Print the IP address
_IP=$(hostname -I) | | true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
exit 0
変更後
# Print the IP address
_IP=$(hostname -I) | | true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi
su -c /home/pi/shutdown-daemon.sh &
exit 0
- 最終更新:2015-04-06 08:10:57