]> arthur.barton.de Git - ppin.git/commitdiff
Add some examle scripts master
authorAlexander Barton <alex@barton.de>
Tue, 12 Apr 2022 08:46:43 +0000 (10:46 +0200)
committerAlexander Barton <alex@barton.de>
Tue, 12 Apr 2022 08:46:43 +0000 (10:46 +0200)
contrib/go.sh [new file with mode: 0755]
contrib/ppinload.sh [new file with mode: 0755]

diff --git a/contrib/go.sh b/contrib/go.sh
new file mode 100755 (executable)
index 0000000..603eb6d
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+[ -w /dev/ppin ] || exit 1
+
+export LC_ALL=C
+
+function set_ppin_up_to()
+{
+       declare -i count="$1"
+       declare -i n=0
+       while [ $n -lt 8 ]; do
+               [ $n -lt $count ] \
+                       && echo "$n on" >/dev/ppin \
+                       || echo "$n off" >/dev/ppin
+       n=$n+1
+       done
+}
+
+while true; do
+       for i in 0 1 2 3 4 5 6 7; do
+               set_ppin_up_to $i
+               sleep 1
+       done
+       for i in 7 6 5 4 3 2 1 0; do
+               set_ppin_up_to $i
+               sleep 1
+       done
+done
diff --git a/contrib/ppinload.sh b/contrib/ppinload.sh
new file mode 100755 (executable)
index 0000000..1ccbdf8
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+[ -w /dev/ppin ] || exit 1
+[ "$1" = "-v" ] && VERBOSE=1 || unset VERBOSE
+
+export LC_ALL=C
+
+function set_ppin_up_to()
+{
+       declare -i count="$1"
+       declare -i n=0
+       while [ $n -lt 8 ]; do
+               [ $n -lt $count ] \
+                       && echo "$n on" >/dev/ppin \
+                       || echo "$n off" >/dev/ppin
+       n=$n+1
+       done
+}
+
+function load_ppin()
+{
+       if [ $load -lt 3 ]; then        #    < 0.03: 0 PINs     d=0.03
+               set_ppin_up_to 0
+       elif [ $load -lt 10 ]; then     # 0.03-0.09: 1 PIN      d=0.07
+               set_ppin_up_to 1
+       elif [ $load -lt 24 ]; then     # 0.10-0.24: 2 PIN      d=0.15
+               set_ppin_up_to 2
+       elif [ $load -lt 50 ]; then     # 0.25-0.49: 3 PINs     d=0.25
+               set_ppin_up_to 3
+       elif [ $load -lt 100 ]; then    # 0.50-0.99: 4 PINs     d=0.50
+               set_ppin_up_to 4
+       elif [ $load -lt 200 ]; then    # 1.00-1.99: 5 PINs     d=1.00
+               set_ppin_up_to 5 
+       elif [ $load -lt 400 ]; then    # 2.00-3.99: 6 PINs     d=2.00
+               set_ppin_up_to 6
+       elif [ $load -lt 800 ]; then    # 4.00-7.99: 7 PINs     d=4.50
+               set_ppin_up_to 7
+       else                            #    > 8.00: 8 PINs
+               set_ppin_up_to 8
+       fi
+}
+
+while true; do
+       declare load_raw=`cat /proc/loadavg | cut -d' ' -f1`
+       declare -i load=`echo $load_raw | sed -e "s/\.//" | sed -e "s/^0*//g"`
+       [ -n "$VERBOSE" ] && echo "Load: $load_raw"
+       load_ppin
+       sleep 1
+done