initial commit
[ETG_Helmet] / SOFTWARE / UTILS / fast-gpio / scripts / expled.sh
1 #!/bin/sh
2
3 # include the Onion sh lib
4 . /usr/lib/onion/lib.sh
5
6
7 Usage () {
8         echo "Functionality:"
9         echo "  Set colors on Omega Expansion Dock LED"
10         echo ""
11         echo "Usage:"
12         echo "$0 <hex value>"
13         echo "  Displays color of hex value on the Exp Dock LED"
14         echo ""
15         echo "$0 -help"
16         echo "  Displays this prompt"
17         echo ""
18 }
19
20
21 ########################
22 ##### Main Program #####
23
24 # check for arguments
25 if      [ $# != 1 ] ||
26         [ "$1" == "-help" ] || 
27         [ "$1" == "-h" ] || 
28         [ "$1" == "--help" ] || 
29         [ "$1" == "--h" ];
30 then
31         Usage
32         exit;
33 fi
34
35 #read color argument
36 hex=$1;
37
38 #split into color components
39 hex=`echo $hex | sed -e 's/0x//' `
40 rHex=`echo $hex | sed -e 's/....$//' `
41 gHex=`echo $hex | sed -e 's/^..//' -e 's/..$//' `
42 bHex=`echo $hex | sed -e 's/^....//' `
43
44 rDuty=$(ExpLedHexToDuty $rHex)
45 gDuty=$(ExpLedHexToDuty $gHex)
46 bDuty=$(ExpLedHexToDuty $bHex)
47
48 echo "Setting LEDs to: $hex"
49 echo "Duty: $rDuty $gDuty $bDuty"
50
51 #run the pwm
52 if [ $rHex != "00" ]; then        
53         fast-gpio pwm 17 200 $rDuty;  
54 else                                             
55         fast-gpio set 17 1            
56 fi;                                              
57                                       
58 if [ $gHex != "00" ]; then    
59         fast-gpio pwm 16 200 $gDuty;
60 else                          
61         fast-gpio set 16 1          
62 fi;                              
63                             
64 if [ $bHex != "00" ]; then       
65         fast-gpio pwm 15 200 $bDuty;
66 else                      
67         fast-gpio set 15 1          
68 fi;             
69
70
71
Contact me: dev (at) shalnoff (dot) com
PGP fingerprint: A6B8 3B23 6013 F18A 0C71 198B 83D8 C64D 917A 5717