From 1f265b90b233e790902cb266eb2f9de130c34816 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Mon, 18 Dec 2023 19:13:17 +0100 Subject: tp_dot_morse --- scripts/tp_dot_morse.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 scripts/tp_dot_morse.sh (limited to 'scripts') diff --git a/scripts/tp_dot_morse.sh b/scripts/tp_dot_morse.sh new file mode 100755 index 0000000..7a68238 --- /dev/null +++ b/scripts/tp_dot_morse.sh @@ -0,0 +1,80 @@ +#!/bin/bash +#brightnessctl -d 'tpacpi::lid_logo_dot' s 100 + + +# For some reason, the TP dot only blinks consistently for > 0.7s + +DEVICE='tpacpi::lid_logo_dot' +#DEVICE='input4::capslock' + +LED_PATH="/sys/class/leds/$DEVICE" + +function led() { + #echo $1 > "$LED_PATH/brightness" + brightnessctl -d "$DEVICE" s $1 > /dev/null +} + +LONG='1.4' +SHORT='0.7' +INT_PAUSE='0.7' +EXT_PAUSE='1' + +function morse() { + for w in $@; do + echo $w + echo $w | fold -w1 | while read c; do + led 1 + case $c in + .) + sleep $SHORT;; + -) + sleep $LONG;; + *);; + esac + led 0 + sleep $INT_PAUSE + done + + sleep $EXT_PAUSE + done +} + +function to_morse() { + for w in $@; do + echo ${w,,} | fold -w1 | while read c; do + case $c in + a) echo .- ;; + b) echo -... ;; + c) echo -.-. ;; + d) echo -.. ;; + e) echo . ;; + f) echo ..-. ;; + g) echo --. ;; + h) echo .... ;; + i) echo .. ;; + j) echo .--- ;; + k) echo -.- ;; + l) echo .-.. ;; + m) echo -- ;; + n) echo -. ;; + o) echo --- ;; + p) echo .--. ;; + q) echo --.- ;; + r) echo .-. ;; + s) echo ... ;; + t) echo - ;; + u) echo ..- ;; + v) echo ...- ;; + w) echo .-- ;; + x) echo -..- ;; + y) echo -.-- ;; + z) echo --.. ;; + esac + done + done +} + +TEXT="$@" + +AAA=( $(to_morse $TEXT) ) +morse ${AAA[@]} -- cgit v1.2.3