Commit | Line | Data |
---|---|---|
4411059d SK |
1 | #! /bin/sh |
2 | ||
3 | set -e | |
4 | ||
5 | . ./bin/khatus_x4_lib_common_sensor.sh | |
6 | ||
7 | dir="${prefix}/${host}" | |
8 | ||
1fd28945 | 9 | sensors_kill_all() { |
7c4d20a9 SK |
10 | for pid_file in $(find $dir -type f -name pid) |
11 | do | |
12 | kill -9 $(cat $pid_file) || true | |
13 | rm $pid_file | |
14 | done | |
15 | pkill khatus_x4 | |
4411059d SK |
16 | } |
17 | ||
1fd28945 SK |
18 | sensors_fork_all() { |
19 | ./bin/khatus_x4_sensor_datetime & | |
20 | ./bin/khatus_x4_sensor_mpd & | |
21 | ./bin/khatus_x4_sensor_energy & | |
22 | } | |
23 | ||
24 | sensor_read_one() { | |
4411059d SK |
25 | if test -f "$1" |
26 | then | |
27 | cat "$1" | |
28 | else | |
29 | printf '%s\n' '--' | |
30 | fi | |
31 | } | |
32 | ||
1fd28945 SK |
33 | sensors_read_all() { |
34 | while : | |
35 | do | |
36 | battery_state="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_state)" | |
37 | battery_percentage="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_percentage)" | |
38 | datetime="$(sensor_read_one ${dir}/khatus_x4_sensor_datetime/out/datetime)" | |
39 | mpd="$(sensor_read_one ${dir}/khatus_x4_sensor_mpd/out/status)" | |
40 | echo "E[${battery_state} ${battery_percentage}] [${mpd}] ${datetime}" | |
41 | sleep 1 | |
42 | done | |
43 | } | |
44 | ||
45 | main() { | |
46 | sensors_kill_all | |
47 | sensors_fork_all | |
48 | sensors_read_all | |
49 | } | |
50 | ||
51 | main |