Initial commit
This commit is contained in:
commit
3436d5b949
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# PWR-Switch
|
||||
|
||||
A little wrapper around [my PWR-Switch config](https://voidcruiser.nl/rambles/pwr-switch/).
|
68
pwr-switch
Executable file
68
pwr-switch
Executable file
|
@ -0,0 +1,68 @@
|
|||
#!/bin/sh
|
||||
|
||||
# $Id: pwr-switch 122491 2022-06-02 13:30:06Z sluijtma $
|
||||
# $URL: https://svn.uvt.nl/its-unix/systems/hastur/usr/local/sbin/pwr-switch $
|
||||
|
||||
INIT_PIN(){
|
||||
# the PWR-SWITCH is connected to GPIO 15 and the presceding ground pin
|
||||
# reference page https://pinout.xyz/pinout/
|
||||
[ -d /sys/class/gpio/gpio15 ] && echo "Pin already initialised" && exit 0
|
||||
echo 15 > /sys/class/gpio/export
|
||||
echo out > /sys/class/gpio/gpio15/direction
|
||||
}
|
||||
|
||||
DEINIT_PIN(){
|
||||
[ -d /sys/class/gpio/gpio15 ] || echo "Pin not initialised" && exit 0
|
||||
echo 15 > /sys/class/gpio/unexport
|
||||
}
|
||||
|
||||
PIN_STATUS(){
|
||||
if [ -d /sys/class/gpio/gpio15 ] ; then
|
||||
echo "pin status: Pin initialised"
|
||||
else
|
||||
echo "pin status: Pin not initialised"
|
||||
fi
|
||||
}
|
||||
|
||||
SWITCH_ON(){
|
||||
# initialise pin before doing anything
|
||||
[ -d /sys/class/gpio/gpio15 ] || INIT_PIN
|
||||
echo 1 > /sys/class/gpio/gpio15/value
|
||||
}
|
||||
|
||||
SWITCH_OFF(){
|
||||
# initialise pin before doing anything
|
||||
[ -d /sys/class/gpio/gpio15 ] || INIT_PIN
|
||||
echo 0 > /sys/class/gpio/gpio15/value
|
||||
}
|
||||
|
||||
TOGGLE_SWITCH(){
|
||||
# initialise pin before doing anything
|
||||
[ -d /sys/class/gpio/gpio15 ] || INIT_PIN
|
||||
case $(cat /sys/class/gpio/gpio15/value) in
|
||||
1) SWITCH_OFF;;
|
||||
0) SWITCH_ON;;
|
||||
esac
|
||||
}
|
||||
|
||||
USAGE(){
|
||||
cat >&2 <<EOF
|
||||
Usage: pwr-switch <on|off|init|deinit|help>
|
||||
on: send on signal
|
||||
off: send off signal
|
||||
init: initialise pin
|
||||
deinit: deinitialise pin
|
||||
status: show pin initialisation state
|
||||
toggle: toggle on/off signal
|
||||
EOF
|
||||
}
|
||||
|
||||
case $1 in
|
||||
on) SWITCH_ON;;
|
||||
off) SWITCH_OFF;;
|
||||
init) INIT_PIN;;
|
||||
deinit) DEINIT_PIN;;
|
||||
status) PIN_STATUS;;
|
||||
toggle) TOGGLE_SWITCH;;
|
||||
*) USAGE;;
|
||||
esac
|
Loading…
Reference in a new issue