Skip to content

Instantly share code, notes, and snippets.

@nibalizer
Last active September 23, 2022 03:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibalizer/dd5e536971b2d0aa70004a0b877fcf29 to your computer and use it in GitHub Desktop.
Save nibalizer/dd5e536971b2d0aa70004a0b877fcf29 to your computer and use it in GitHub Desktop.
#!/bin/bash
#hack the planet
morse=".... .- -.-. -.- / - .... . / .--. .-.. .- -. . -"
# testing morse
#morse=".... .... .... --- ..."
# TIME_UNIT
TU=0.1
# ----------------------------------------------------------
#There are rules to help people distinguish dots from dashes in Morse code.
# ---
#The length of a dot is 1 time unit.
#A dash is 3 time units.
#The space between symbols (dots and dashes) of the same letter is 1 time unit.
#The space between letters is 3 time units.
#The space between words is 7 time units.
# ----------------------------------------------------------
high() {
light -s sysfs/leds/tpacpi::lid_logo_dot -A 1
}
low() {
light -s sysfs/leds/tpacpi::lid_logo_dot -U 1
}
dot() {
high
sleep $TU
low
sleep $TU
low
}
dash() {
high
sleep $TU
sleep $TU
sleep $TU
low
sleep $TU
low
}
char_space() {
low
sleep $TU
sleep $TU
sleep $TU
low
}
word_space() {
low
sleep $TU
sleep $TU
sleep $TU
sleep $TU
sleep $TU
sleep $TU
sleep $TU
low
}
run_morse() {
echo $morse | while read -n1 item
do
echo $item
case $item in
.)
echo dot
dot;;
-)
echo dash
dash;;
/)
echo slash
word_space;;
'')
echo space
char_space;;
*)
echo OMFG unknown;;
esac
done
}
blink() {
while true
do
light -s sysfs/leds/tpacpi::lid_logo_dot -U 1
light -s sysfs/leds/tpacpi::lid_logo_dot -G
sleep 0.05
light -s sysfs/leds/tpacpi::lid_logo_dot -A 1
light -s sysfs/leds/tpacpi::lid_logo_dot -G
sleep 0.05
done
}
show_help() {
echo "Morse Code LED Blinker"
echo "Usage: $0 <arg>"
echo "-h | show this help"
echo "-l | show morse code continuously"
echo "-m | run morse code once"
echo "-b | blink on off rapidly"
}
case $1 in
-l)
echo "Looping, exit with ^C"
while true;
do
run_morse
done;;
-b)
echo "Blinking"
blink;;
-m)
echo "Morse"
run_morse;;
-h)
show_help;;
*)
show_help;;
esac
[Unit]
Description=BLINKLED service
After=network.target
[Service]
ExecStart=/root/lid_led.sh -l
ExecReload=/bin/kill $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment