-
Notifications
You must be signed in to change notification settings - Fork 5
/
showleds
292 lines (254 loc) · 10.3 KB
/
showleds
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash -u
# Script_name : showleds
# Author : Bert Lindeman
# Description : Show values of EV3-leds
# Version : v1.3
# Date : 2014-11-04
# Usage : showleds
# Notes : No arguments needed nor used
# o brightness is only non-zero at the time
# that the led indeed *is* giving light.
# So a blinking led might show zero or non-zero.
# Copyright : 2014 Bert Lindeman
# License : GPL-3.0+
#
#============================================================================
#
# Changelog :
# Date By Description
# 20141104 BL prepare for release v1.3
# 20141023 BL o Since 3.16.1-6 also PF-leds possible
# o move show[LED]trigger to ev3dev_functions
# 20140914 BL Color for some values
# 20140826 BL o Show delay_on and delay_off if available for
# this led and for it's trigger
# o adapt usage clause (no parameters)
# 20150518 BL try to adapt for Raspberry Pi
# 20160103 BL adapt to image 20151230 (change filenames)
#
#============================================================================
#
. /usr/local/bin/bert_ev3dev_functions
usageEXIT () {
echo "$1"
echo
echo "USAGE: $0 "
exit 1
}
declare _A brightnessArr
declare _A triggerArr
declare _A triggerCol
declare _A delayON
declare _A delayOFF
declare _A portix
#
findled=`/bin/ls -d /sys/class/leds/* 2>/dev/null`
# for side in 0 1 ;
for ledbase in $findled;
do
icol=0
iside=0
# ledbase="/sys/class/leds/led$side" # should be "over var" ev3:$ledcolor:$side"
ledbrightness="$ledbase/brightness"
ledMAXbrightness="$ledbase/max_brightness"
delay_onpath="$ledbase/delay_on"
delay_offpath="$ledbase/delay_off"
ledtriggerpath="$ledbase/trigger"
brightness=$(echo "`cat $ledbrightness`")
brightnessArr[$icol$iside]=$brightness
Maxbrightness=$(echo "`cat $ledMAXbrightness`")
MaxbrightnessArr[$icol$iside]=$Maxbrightness
showtrigger "`cat $ledtriggerpath`"
triggerArr[$icol$iside]=${currenttrigger:0:40}
if [ $currenttrigger == "none" ]; then triggerCol[$icol$iside]=$white
else triggerCol[$icol$iside]=$brblue
fi
# triggerCol[$icol$iside]=$triggercol
if [ -e "$delay_onpath" ]; then delayON[$icol$iside]=$(echo "`cat $delay_onpath`")
else delayON[$icol$iside]="."
fi
if [ -e "$delay_offpath" ]; then delayOFF[$icol$iside]=$(echo "`cat $delay_offpath`")
else delayOFF[$icol$iside]="."
fi
# clear
echo -e "${endColor}\nReport from ${ledbase} \n"
# header
printf "$brwhite%-6s %-11s %10s %8s %8s %-40s$white\n" "color" "MAX_brightn" "Brightness" " dly_ON" "dly_OFF" "trigger"
printf "$brwhite%-6s %-11s %10s %8s %8s %-40s$white\n" "/port" "-----------" "----------" " ------" "-------" "-------"
ledcolor=""
# for side in 0 1 ;
# do
# if [ $ledcolor == "red" ]; then icol=0 ; else icol=1 ; fi
# if [ $side == "left" ]; then iside=0 ; else iside=1; fi
curColor=" " # \$br$ledcolor # dereference $ledcolor to get bright colorcode for ledcolor
# if [ "$side" == "right" ] ; then
# curside="right"; sidealign="" # results in %11s so align right
# else
# curside="left" ; sidealign="-" # results in %-11s so align left
# fi
sidealign=""
curside=" "
if [ ${brightnessArr[$icol$iside]} == "0" ]; then brightnessCol=$white
else brightnessCol=$brgreen
fi
if [ ${delayON[$icol$iside]} == "0" ]; then delay_onCol=$white
else delay_onCol=$brgreen
fi
if [ ${delayOFF[$icol$iside]} == "0" ]; then delay_offCol=$white
else delay_offCol=$brgreen
fi
# set -x
printf "`eval echo $curColor`%-6s ${white}%${sidealign}11s ${brightnessCol}%10s$white ${delay_onCol}%8s$white ${delay_offCol}%8s$white ${triggerCol[$icol$iside]}%-40s\n" \
"$ledcolor" \
"${MaxbrightnessArr[$icol$iside]}" \
"${brightnessArr[$icol$iside]}" \
"${delayON[$icol$iside]}" \
"${delayOFF[$icol$iside]}" \
"${triggerArr[$icol$iside]}"
# set +x
done
echo -e " ${endColor} " # back to normal
exit
for side in left right ;
do
for ledcolor in red green ;
do
if [ $ledcolor == "red" ]; then icol=0 ; else icol=1 ; fi
if [ $side == "left" ]; then iside=0 ; else iside=1; fi
ledbase="/sys/class/leds/ev3:$ledcolor:$side"
ledbrightness="$ledbase/brightness"
delay_onpath="$ledbase/delay_on"
delay_offpath="$ledbase/delay_off"
ledtriggerpath="$ledbase/trigger"
brightness=$(echo "`cat $ledbrightness`")
brightnessArr[$icol$iside]=$brightness
showtrigger "`cat $ledtriggerpath`"
triggerArr[$icol$iside]=${currenttrigger:0:40}
if [ $currenttrigger == "none" ]; then triggerCol[$icol$iside]=$white
else triggerCol[$icol$iside]=$brblue
fi
# triggerCol[$icol$iside]=$triggercol
if [ -e "$delay_onpath" ]; then delayON[$icol$iside]=$(echo "`cat $delay_onpath`")
else delayON[$icol$iside]="."
fi
if [ -e "$delay_offpath" ]; then delayOFF[$icol$iside]=$(echo "`cat $delay_offpath`")
else delayOFF[$icol$iside]="."
fi
done
done
# clear
echo -e "Report from `dirname ${ledbase}` ev3:{${red}red,${green}green${white}}:{left,right}\n"
# header
printf "$brwhite%-6s %-11s %10s %8s %8s %-40s$white\n" "color" "Side" "Brightness" " dly_ON" "dly_OFF" "trigger"
printf "$brwhite%-6s %-11s %10s %8s %8s %-40s$white\n" "/port" "-----------" "----------" " ------" "-------" "-------"
for side in left right ;
do
for ledcolor in red green ;
do
if [ $ledcolor == "red" ]; then icol=0 ; else icol=1 ; fi
if [ $side == "left" ]; then iside=0 ; else iside=1; fi
curColor=\$br$ledcolor # dereference $ledcolor to get bright colorcode for ledcolor
if [ "$side" == "right" ] ; then
curside="right"; sidealign="" # results in %11s so align right
else
curside="left" ; sidealign="-" # results in %-11s so align left
fi
if [ ${brightnessArr[$icol$iside]} == "0" ]; then brightnessCol=$white
else brightnessCol=$brgreen
fi
if [ ${delayON[$icol$iside]} == "0" ]; then delay_onCol=$white
else delay_onCol=$brgreen
fi
if [ ${delayOFF[$icol$iside]} == "0" ]; then delay_offCol=$white
else delay_offCol=$brgreen
fi
printf "`eval echo $curColor`%-6s ${white}%${sidealign}11s ${brightnessCol}%10s$white ${delay_onCol}%8s$white ${delay_offCol}%8s$white ${triggerCol[$icol$iside]}%-40s\n" \
"$ledcolor" \
"$curside" \
"${brightnessArr[$icol$iside]}" \
"${delayON[$icol$iside]}" \
"${delayOFF[$icol$iside]}" \
"${triggerArr[$icol$iside]}"
done
done
# PF and rcx leds:
if [ -e /sys/class/leds/ev3::out* ]; then
for port in /sys/class/leds/ev3::out*
do
# echo "path port:${port}"
echo ""
outport=`basename ${port}`
curColor=${brwhite}
# fake led color and side
iside=0
# set empty:
icol2=""
icol3=""
icol4=""
icol5=""
case $outport in
"ev3::outA") icol2=2
icol=2
portix[$icol$iside]="outA"
;;
"ev3::outB") icol3=3
icol=3
portix[$icol$iside]="outB"
;;
"ev3::outC") icol4=4
icol=4
portix[$icol$iside]="outC"
;;
"ev3::outD") icol5=5
icol=5
portix[$icol$iside]="outD"
;;
*)
echo "Unrecognized output port: \"${outport}\" from ${port}"
exit
;;
esac
ledbase="/sys/class/leds/$outport"
ledbrightness="$ledbase/brightness"
delay_onpath="$ledbase/delay_on"
delay_offpath="$ledbase/delay_off"
ledtriggerpath="$ledbase/trigger"
showtrigger "`cat $ledtriggerpath`"
triggerArr[$icol$iside]=${currenttrigger:0:40}
brightnessArr[$icol$iside]=$(echo "`cat $ledbrightness`")
if [ $currenttrigger == "none" ]; then triggerCol[$icol$iside]=$white
else triggerCol[$icol$iside]=$brblue
fi
# triggerCol[$icol$iside]=$triggercol
if [ -e "$delay_onpath" ]; then delayON[$icol$iside]=$(echo "`cat $delay_onpath`")
else delayON[$icol$iside]="."
fi
if [ -e "$delay_offpath" ]; then delayOFF[$icol$iside]=$(echo "`cat $delay_offpath`")
else delayOFF[$icol$iside]="."
fi
done
sidealign="-" # align left
for side in $icol2 $icol3 $icol4 $icol5
do
# echo "Looping through PF leds side;$side \"$icol2\" \"$icol3\" \"$icol4\" \"$icol5\""
curside=""
if [ ${brightnessArr[$icol$iside]} == "0" ]; then brightnessCol=$white
else brightnessCol=$brgreen
fi
if [ ${delayON[$icol$iside]} == "0" ]; then delay_onCol=$white
else delay_onCol=$brgreen
fi
if [ ${delayOFF[$icol$iside]} == "0" ]; then delay_offCol=$white
else delay_offCol=$brgreen
fi
portname="${portix[$icol$iside]}"
printf "${brgreen}%-6s ${white}%${sidealign}11s ${brightnessCol}%10s$white ${delay_onCol}%8s$white ${delay_offCol}%8s$white ${triggerCol[$icol$iside]}%-40s\n" \
"$portname" \
"$curside" \
"${brightnessArr[$icol$iside]}" \
"${delayON[$icol$iside]}" \
"${delayOFF[$icol$iside]}" \
"${triggerArr[$icol$iside]}"
done
fi
echo -e " ${endColor} " # back to normal