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 | |
3565cd1d | 15 | pkill khatus_x4_sensor || true |
4411059d SK |
16 | } |
17 | ||
1fd28945 SK |
18 | sensors_fork_all() { |
19 | ./bin/khatus_x4_sensor_datetime & | |
3565cd1d | 20 | ./bin/khatus_x4_sensor_bluetooth& |
1fd28945 SK |
21 | ./bin/khatus_x4_sensor_mpd & |
22 | ./bin/khatus_x4_sensor_energy & | |
23 | } | |
24 | ||
25 | sensor_read_one() { | |
4411059d SK |
26 | if test -f "$1" |
27 | then | |
28 | cat "$1" | |
29 | else | |
30 | printf '%s\n' '--' | |
31 | fi | |
32 | } | |
33 | ||
1fd28945 SK |
34 | sensors_read_all() { |
35 | while : | |
36 | do | |
37 | battery_state="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_state)" | |
38 | battery_percentage="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_percentage)" | |
3565cd1d SK |
39 | bluetooth_controllers="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_powered_controllers)" |
40 | bluetooth_devices="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_connected_devices)" | |
1fd28945 SK |
41 | datetime="$(sensor_read_one ${dir}/khatus_x4_sensor_datetime/out/datetime)" |
42 | mpd="$(sensor_read_one ${dir}/khatus_x4_sensor_mpd/out/status)" | |
3565cd1d | 43 | echo "E[${battery_state} ${battery_percentage}] [${mpd}] [$bluetooth_controllers $bluetooth_devices] ${datetime}" |
1fd28945 SK |
44 | sleep 1 |
45 | done | |
46 | } | |
47 | ||
48 | main() { | |
49 | sensors_kill_all | |
50 | sensors_fork_all | |
51 | sensors_read_all | |
52 | } | |
53 | ||
54 | main |