commit 3436d5b9497f681de55b22deac3f22d9783d4271 Author: Marty Sluijtman Date: Wed Jul 12 16:59:16 2023 +0200 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..321893f --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# PWR-Switch + +A little wrapper around [my PWR-Switch config](https://voidcruiser.nl/rambles/pwr-switch/). diff --git a/pwr-switch b/pwr-switch new file mode 100755 index 0000000..921a4f9 --- /dev/null +++ b/pwr-switch @@ -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 < + 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