Break up into procedures
[khatus.git] / x4 / sanity_check
CommitLineData
4411059d
SK
1#! /bin/sh
2
3set -e
4
5. ./bin/khatus_x4_lib_common_sensor.sh
6
7dir="${prefix}/${host}"
8
1fd28945 9sensors_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
18sensors_fork_all() {
19 ./bin/khatus_x4_sensor_datetime &
20 ./bin/khatus_x4_sensor_mpd &
21 ./bin/khatus_x4_sensor_energy &
22}
23
24sensor_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
33sensors_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
45main() {
46 sensors_kill_all
47 sensors_fork_all
48 sensors_read_all
49}
50
51main
This page took 0.02801 seconds and 4 git commands to generate.