Skip to content

Commit

Permalink
Update led_sys.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelscholle committed May 12, 2024
1 parent 9e77dc3 commit 07f8eb2
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions led_sys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
TYPE=$1
COLOR=$2
MODIFIER=$3
DEBUG=$4
DELAY=$4
DEBUG=$5

if [ "$TYPE" == "" ]; then
echo "OpenHD LED Control"
Expand All @@ -12,7 +13,7 @@ if [ "$TYPE" == "" ]; then
echo "led TYPE COLOR DELAY DEBUG"
echo "available types:"
echo "________________"
echo "on|off|manual|warning|error"
echo "on|off|manual|warning|error|flashing"
fi

# Kill all previous instances
Expand All @@ -25,27 +26,27 @@ debugMessage() {
}

# Detect platform and LED-type
if [ -d /sys/class/leds/openhd-x20dev ]; then
PLATFORM="x20"
debugMessage "Platform: X20"

elif grep -q "Raspberry Pi" /proc/cpuinfo; then
if grep -q "Raspberry Pi" /proc/cpuinfo; then
PLATFORM="pi"
debugMessage "Platform: RPI"
if [ ! -d /sys/class/leds/PWR ]; then
COLOR="green"
debugMessage "Only One LED"
if [ -d /sys/class/leds/PWR ]; then
PLATFORM="pi"
debugMessage "Platform: RPI"
fi
elif [ -d /sys/class/leds/user-led2/brightness ]; then
elif [ -d /sys/class/leds/openhd-x20dev ]; then
PLATFORM="x20"
debugMessage "Platform: X20"
elif [ -f /sys/class/leds/user-led2/brightness ]; then
PLATFORM="rock5"
debugMessage "Platform: Rock5"
elif [ -d /sys/class/leds/user-led/brightness ]; then
elif [ -f /sys/class/leds/pi-led-green/brightness ]; then
PLATFORM="cm3"
debugMessage "Platform: CM3"

elif [ -d /sys/class/leds/board-led/brightness ]; then
elif [ -f /sys/class/leds/board-led/brightness ]; then
PLATFORM="zero3w"
debugMessage "Platform: Zero3w"
else
echo "Platform not found"
fi

# Main functions
Expand Down Expand Up @@ -120,9 +121,9 @@ LED_ON() {
echo 1 > /sys/class/leds/pwr-led-red/brightness
fi
elif [ "$PLATFORM" == "zero3w" ]; then
echo 1 > /sys/class/leds/board-led/brightness
echo 1 > /sys/class/leds/board-led/brightness
elif [ "$PLATFORM" == "rock5" ]; then
echo 1 > /sys/class/leds/user-led2/brightness
echo 1 > /sys/class/leds/user-led2/brightness
fi
}

Expand Down Expand Up @@ -188,9 +189,9 @@ LED_OFF() {
echo 0 > /sys/class/leds/pwr-led-red/brightness
fi
elif [ "$PLATFORM" == "zero3w" ]; then
echo 0 > /sys/class/leds/board-led/brightness
echo 0 > /sys/class/leds/board-led/brightness
elif [ "$PLATFORM" == "rock5" ]; then
echo 0 > /sys/class/leds/user-led2/brightness
echo 0 > /sys/class/leds/user-led2/brightness
fi
}

Expand All @@ -205,39 +206,39 @@ BLINK_LED() {
BLINK_LED_ASYNC() {
while true; do
LED_ON
sleep $(echo "$DELAY1 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
LED_OFF
sleep $(echo "$DELAY2 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
done
}
BLINK_LED_ASYNC_MULTI() {
while true; do
COLOR=$COLOR1
LED_ON
sleep $(echo "$DELAY1 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
LED_OFF
sleep $(echo "$DELAY2 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
COLOR=$COLOR2
LED_ON
sleep $(echo "$DELAY1 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
LED_OFF
sleep $(echo "$DELAY2 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
done
}
BLINK_LED_ASYNC_MULTI_2() {
while true; do
COLOR=$COLOR1
LED_ON
sleep $(echo "$DELAY1 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
COLOR=$COLOR2
LED_ON
sleep $(echo "$DELAY1 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
COLOR=$COLOR1
LED_OFF
sleep $(echo "$DELAY2 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
COLOR=$COLOR2
LED_OFF
sleep $(echo "$DELAY2 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
done
}
BLINK_LED_ASYNC_MULTI_SWITCHING() {
Expand All @@ -246,12 +247,12 @@ BLINK_LED_ASYNC_MULTI_SWITCHING() {
LED_ON
COLOR=$COLOR2
LED_OFF
sleep $(echo "$DELAY1 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
COLOR=$COLOR2
LED_ON
COLOR=$COLOR1
LED_OFF
sleep $(echo "$DELAY2 * 0.01" | bc)
sleep $(echo "$DELAY * 0.01" | bc)
done
}

Expand All @@ -271,27 +272,24 @@ elif [ "$TYPE" == "warning" ]; then
echo "Missing value for Warning mode."
else
COLOR="green"
DELAY1="50"
DELAY2="200"
DELAY="50"
BLINK_LED_ASYNC
debugMessage "LED Warning $MODIFIER"
fi
elif [ "$TYPE" == "error" ]; then
if [ -z "$MODIFIER" ]; then
echo "Missing value for Error mode."
else
DELAY1="50"
DELAY2="100"
DELAY="50"
COLOR1="green"
COLOR2="red"
BLINK_LED_ASYNC_MULTI_2
debugMessage "LED Error $MODIFIER"
fi
elif [ "$TYPE" == "flashing" ]; then
DELAY1="1"
DELAY2="1"
COLOR1="green"
COLOR2="blue"
BLINK_LED_ASYNC_MULTI_SWITCHING
debugMessage "LED $MODIFIER"
DELAY="1"
COLOR1="green"
COLOR2="blue"
BLINK_LED_ASYNC_MULTI_SWITCHING
debugMessage "LED flashing"
fi

0 comments on commit 07f8eb2

Please sign in to comment.