-
Notifications
You must be signed in to change notification settings - Fork 0
/
retroidle
62 lines (52 loc) · 1.48 KB
/
retroidle
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
58
59
60
61
62
#!/bin/bash
# This script watches /proc/interrupts for incrementing pinctrl
# The gpio pinctrl interupts are used by retrogame
# Currently it sums all lines matching pinctrl.
# Change the awk pattern to only match specific pins
# Can be used with any interrupts. Just change the awk search pattern
# Run from rc.local. /usr/local/bin/retroidle &
# idle_max=number of seconds of no interupts before idle
idle_max=7200
idle_start()
{
#Code to execute when idle
#echo "IDLE START"
#/usr/local/bin/idlestart
}
idle_end()
{
#Code to execute when off idle
#echo "IDLE DONE"
#/usr/local/bin/idleend
}
idle_while()
{
#Code to run while idling
#Will run once a second
#/usr/local/bin/ledblink
}
idlecount=0
idling=false
while true;do
ints_last=$ints_now
ints_now=`awk ' /pinctrl/{total+=$2} END {print total}' < /proc/interrupts`
sleep 1
if [ "$ints_last" == "$ints_now" ] ; then
((idlecount++))
else
if [ "$idling" == "true" ] ; then
idling=false
idlecount=0
idle_end
fi
fi
if [ $idlecount -ge $idle_max ] ; then
idlecount=$idle_max
if [ "$idling" == "false" ] ; then
idling=true
idle_start
else
idle_while
fi
fi
done