-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuvOn.sh
executable file
·66 lines (51 loc) · 1.16 KB
/
uvOn.sh
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
#!/bin/bash
# quickhack script enhancement for UV lamp which tries
# to enhance the percentage value equally during one hour
# 20 blocks per hour each 3 minutes
if [ $# -ne 2 ]; then
echo Usage $0 [percent 5,10, ... 100] [block 1..20 ]
echo returns 1 if UV lamp is on during this time block and 0 if not
exit 0
fi
# parameter
percent=$1
block=$2
# constants
sumBlocks=20
# parameter check
if [ $percent -lt 0 ] || [ $percent -gt 100 ] || [ $block -lt 1 ] || [ $block -gt $sumBlocks ]
then
echo parameter error: percent := { 0..100 }, block := { 1..20 }
exit 1
fi
if [ 0 -ne $(( $percent % 5 )) ]; then
echo parameter error: percent has to be multiple of 5
exit 1
fi
# on 100 percent no calculations necessary
if [ $percent -eq 100 ]; then
echo 1
exit 0
fi
# on 0 percent no calculation is cecessary
if [ $percent -eq 0 ]; then
echo 0
exit 0
fi
blocksOn=$(( $percent / 5 ))
blocksOff=$(( $sumBlocks - $blocksOn ))
if [ $percent -le 50 ]; then
periode=$(( $sumBlocks / $blocksOn ))
invert=0
else
periode=$(( $sumBlocks / $blocksOff ))
invert=1
fi
erg=$(( $block % $periode ))
if [ $erg -eq 1 ]; then
retval=$((1 ^ invert))
else
retval=$((0 ^ invert))
fi
echo $retval
exit 0