forked from Juice4halt/Shutdown-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshutdown_script
More file actions
63 lines (43 loc) · 1.7 KB
/
shutdown_script
File metadata and controls
63 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#title :shutdown_script
#description :This script runs on Raspberry Pi equipped with the Juice4Halt module.
#author :Nelectra s.r.o.
#date :20150812
#version :1.0
#usage :copy this file to /home/pi/juice4halt/bin/
# and make it executable: sudo chmod 755 shutdown_script
#notes :www.juice4halt.com
#copyright :GNU GPL v3.0
#==============================================================================
#create directory for working with GPIO and wait
echo "25" > /sys/class/gpio/export
sleep 0.2s
# use the pin as an open-drain output, send a short LOW pulse (means: message "Booting finished, shutdown_script runs")
# after that change to input and listen
# when a LOW occurs sent from J4H start with shutdown
# set GPIO25 as output and set output to LOW
echo "out" > /sys/class/gpio/gpio25/direction
echo "0" > /sys/class/gpio/gpio25/value
sleep 0.1s
echo "in" > /sys/class/gpio/gpio25/direction
#wait until pin rises to HI
sleep 0.1s
pinval="1"
while [ "$pinval" != "0" ]
do
#reading the value of the input pin
pinval=$(cat /sys/class/gpio/gpio25/value)
#wait
sleep 0.2s
done
#juice4halt firmware needs another reading from I2C bus for acknowledging
pinval=$(cat /sys/class/gpio/gpio25/value)
# set GPIO25 as output and set output to LOW
echo "out" > /sys/class/gpio/gpio25/direction
echo "0" > /sys/class/gpio/gpio25/value
# wait for system halt
# after system halted the pin will be automatically switched to input and the level will be pulled up to HI
# a LOW to HI transition signals to the J4H to turn the power off
echo ""
echo "Juice4halt: Power failure, RPi will now shut down."
sudo halt