Skip to content

Commit 06dbd44

Browse files
xyb994dogi
andauthored
treehouses led also for cube image (fixes #2291) (#2292)
Co-authored-by: dogi <dogi@users.noreply.github.com>
1 parent 1ac9f44 commit 06dbd44

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

modules/led.sh

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ function led {
44
color="$1"
55
trigger="$2"
66

7-
gLed="/sys/class/leds/led0"
8-
rLed="/sys/class/leds/led1"
7+
initialize
98
currentGreen=$(sed 's/.*\[\(.*\)\].*/\1/g' 2>"$LOGFILE" < "$gLed/trigger")
109
currentRed=$(sed 's/.*\[\(.*\)\].*/\1/g' 2>"$LOGFILE" < "$rLed/trigger")
1110
green="${GREEN}green led${NC}"
@@ -266,8 +265,32 @@ function led {
266265
fi
267266
}
268267

268+
function initialize {
269+
if [ -d "/sys/class/leds/PWR" ]; then
270+
rLed="/sys/class/leds/PWR"
271+
elif [ -d "/sys/class/leds/led1" ]; then
272+
rLed="/sys/class/leds/led1"
273+
else
274+
echo "Error: Could not find a valid path for the red LED"
275+
exit 1
276+
fi
277+
278+
if [ -d "/sys/class/leds/ACT" ]; then
279+
gLed="/sys/class/leds/ACT"
280+
elif [ -d "/sys/class/leds/led0" ]; then
281+
gLed="/sys/class/leds/led0"
282+
else
283+
echo "Error: Could not find a valid path for the green LED"
284+
exit 1
285+
fi
286+
}
287+
269288
function set_brightness {
270-
echo "$2" > "/sys/class/leds/led$1/brightness"
289+
if [[ "$1" = "T" || "$1" = "0" ]]; then # ACT/led0
290+
echo "$2" > "$gLed/brightness"
291+
elif [[ "$1" = "R" || "$1" = "1" ]]; then # PWR/led1
292+
echo "$2" > "$rLed/brightness"
293+
fi
271294
}
272295

273296
function newyear {
@@ -630,8 +653,6 @@ function labourday {
630653
led red "$current_red"
631654
}
632655

633-
634-
635656
function independenceday {
636657
current_red=$(led "red")
637658
current_green=$(led "green")
@@ -906,7 +927,7 @@ function led_help {
906927
echo
907928
echo "This will help a user to identify a raspberry pi (if a user is working on many of raspberry pis)"
908929
echo
909-
echo " Where to find all modes: cat /sys/class/leds/led0/trigger"
930+
echo " Where to find all modes: cat $gLed/trigger"
910931
echo
911932
echo " OPTIONS OF MODES: "
912933
echo " default-on turns LED on"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@treehouses/cli",
3-
"version": "1.26.14",
3+
"version": "1.26.15",
44
"remote": "6000",
55
"description": "Thin command-line interface for Raspberry Pi low level configuration.",
66
"main": "cli.sh",

0 commit comments

Comments
 (0)