source: branches/contrib/debian/rootfs/files/all/usr/bin/led @ 707

Last change on this file since 707 was 707, checked in by ehem, 5 years ago

Drag in changes to trunk

Coordination is interesting to deal with. Drag in changes that were done
on trunk.

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/bin/sh
2#
3# Johan van Zoomeren <amain@debwrt.net>
4# 2010
5#
6# usage: led <on|off|n>
7#
8#        on : enable powerled
9#        off: disable powerled
10#        n  : flash every n seconds ( n may be smaller then 0. For example 0.5 )
11
12ARG1=$1
13ARG2=$2
14sleep=${ARG1:=1}
15if [ "`echo $sleep | egrep ^[0-9\.]+$`" = "" ]; then sleep=1; fi
16
17led_kill ()
18{
19   ps x | grep "/usr/bin/led .*loop" | grep -v grep | awk '{print $1}' | xargs -r kill
20}
21
22led_off ()
23{
24   echo "0">/proc/diag/led/power 2>/dev/null
25}
26
27led_on ()
28{
29   echo "1">/proc/diag/led/power 2>/dev/null
30}
31
32trigger ()
33{
34   led_on
35   exit 0
36}
37
38trap 'trigger' 2 3 1 9 15
39
40/sbin/modprobe diag >/dev/null 2>&1
41[ ! -f /proc/diag/led/power ] && exit 1
42
43if [ "off" = "$ARG1" ]; then
44   led_kill
45   led_off
46   exit 0
47elif [ "on" = "$ARG1" ]; then
48   led_kill
49   led_on
50   exit 0
51fi
52
53if [ ! "loop" = "$ARG2" ]; then 
54   led_kill
55   exec $0 $ARG1 loop &
56   exit 0
57fi 
58
59toggle=$(((`cat /proc/diag/led/power 2>/dev/null`+1)%2))
60while true; do
61   echo ${toggle}>/proc/diag/led/power 2>/dev/null
62   sleep $sleep
63   toggle=$(((toggle+1)%2))
64done
Note: See TracBrowser for help on using the repository browser.