~mil/f_scripts

f_scripts/scripts/f_timer -rwxr-xr-x 1.4 KiB
c52a77c4Miles Alan f_audio: Set AIF1 DA0 to 20% rather then 100% to prevent distortion 4 days ago
                                                                                
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
#!/usr/bin/env osh
shopt -s strict:all
DEP="linuxconsoletools util-linux-misc"
DEC="Set a countdown timer to be alerted"
DOC="
  Set a countdown timer after which expiry you'll be alerted.

  Use the variable \$F_TIMER_PRESETS to set a space deliniated
  array of strings suffixed by (h/m/s) that will prepopulate the
  menu with time values.
"
VAR='
  F_TIMER_PRESETS="10m 9m 8m 7m 6m 5m 4m 3m 2m 1m 30s 5s 1h"
'

terminate() {
  setterm --inversescreen off
  exit 0
}

timerrun() {
  local ALERTTIME DATE

  ALERTTIME=$(
    echo "$@" |
    sed 's#h#*60m#g'|
    sed 's#m#*60s#g'|
    sed 's#s#*1#g'|
    sed 's# #+#g' |
    bc
  )
  DATE="$(echo $(date +%s) + $ALERTTIME | bc)"

  clear
  while [ "$DATE" -ge "$(date +%s)" ]; do
    printf %b "$(date -u --date @$((DATE - $(date +%s))) +%H:%M:%S) \r";
    sleep 0.1
  done

  echo "Done with $*"

  while true; do
    pkill fftest
    yes 5 | fftest /dev/input/by-path/platform-vibrator-event 2>&1 > /dev/null &
    echo "Done with $*";
    setterm --inversescreen on
    sleep 0.2
    setterm --inversescreen off
    sleep 0.2
  done
}

main() {
  local TIME

  trap terminate INT HUP TERM
  env | grep -q "^$(basename "$0" | tr '[a-z]' '[A-Z]')=" || eval "$VAR"
  clear
  echo "Timer"
  [ -p /tmp/fbp.fifo ] && { echo -e "\b\f\r"; echo "$F_TIMER_PRESETS" | tr " " "\n"; } > /tmp/fbp.fifo
  read -p "Time (s, h, m): " TIME
  timerrun "$TIME"
}

if [ -n "$1" ]; then "$@"; else main; fi