X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=x4%2Fsanity_check;h=6c6b17bb424eedba9bcb175916bbf277a57342cc;hb=93c067b528d520ceaef09830923aa3c951ad2e8f;hp=8100c2f142a9162b0c451d2a92fcd38ccab3b299;hpb=81f816230f652b7c07930807a8ec146e208ad4ca;p=khatus.git diff --git a/x4/sanity_check b/x4/sanity_check index 8100c2f..6c6b17b 100755 --- a/x4/sanity_check +++ b/x4/sanity_check @@ -6,14 +6,28 @@ set -e dir="${prefix}/${host}" -kill_sensor() { - if test -f "$1" - then - kill $(cat "$1") - fi +sensors_kill_all() { + for pid_file in $(find $dir -type f -name pid) + do + kill -9 $(cat $pid_file) || true + rm $pid_file + done + pkill khatus_x4 || true +} + +sensors_fork_all() { + ./bin/khatus_x4_sensor_datetime -d -i 1 + ./bin/khatus_x4_sensor_bluetooth -d -i 1 + ./bin/khatus_x4_sensor_mpd -d -i 1 + ./bin/khatus_x4_sensor_energy -d -i 1 + ./bin/khatus_x4_sensor_memory -d -i 1 + ./bin/khatus_x4_sensor_loadavg -d -i 1 + ./bin/khatus_x4_sensor_temp -d -i 1 -- -z 0 + ./bin/khatus_x4_sensor_disk -d -i 1 -- -f / + ./bin/khatus_x4_sensor_volume -d -i 1 } -read_sensor() { +sensor_read_one() { if test -f "$1" then cat "$1" @@ -22,20 +36,32 @@ read_sensor() { fi } -kill_sensor ${dir}/khatus_x4_sensor_datetime/pid -kill_sensor ${dir}/khatus_x4_sensor_mpd/pid -kill_sensor ${dir}/khatus_x4_sensor_energy/pid - -./bin/khatus_x4_sensor_datetime -d -./bin/khatus_x4_sensor_mpd -d -./bin/khatus_x4_sensor_energy -d - -while : -do - battery_state="$(read_sensor ${dir}/khatus_x4_sensor_energy/out/battery_state)" - battery_percentage="$(read_sensor ${dir}/khatus_x4_sensor_energy/out/battery_percentage)" - datetime="$(read_sensor ${dir}/khatus_x4_sensor_datetime/out/datetime)" - mpd="$(read_sensor ${dir}/khatus_x4_sensor_mpd/out/status)" - echo "E[${battery_state} ${battery_percentage}] [${mpd}] ${datetime}" - sleep 1 -done +sensors_read_all() { + while : + do + battery_state="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_state)" + battery_percentage="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_percentage)" + bluetooth_controllers="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_powered_controllers)" + bluetooth_devices="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_connected_devices)" + datetime="$(sensor_read_one ${dir}/khatus_x4_sensor_datetime/out/datetime)" + mpd="$(sensor_read_one ${dir}/khatus_x4_sensor_mpd/out/status)" + mem="$(sensor_read_one ${dir}/khatus_x4_sensor_memory/out/percent_used)" + load="$(sensor_read_one ${dir}/khatus_x4_sensor_loadavg/out/load_avg_1min)" + temp="$(sensor_read_one ${dir}/khatus_x4_sensor_temp/out/thermal_zone0)" + disk="$(sensor_read_one ${dir}/khatus_x4_sensor_disk/out/disk_usage_percentage)" + vol_left="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/vol_left)" + vol_right="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/vol_right)" + vol_state="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/state)" + vol_mute="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/mute)" + echo "E[${battery_state} ${battery_percentage}] M:${mem}% L:${load} T:${temp}°C D:${disk}% [${mpd}] [$bluetooth_controllers $bluetooth_devices] V:${vol_state}:${vol_left}:${vol_right}:${vol_mute} ${datetime}" + sleep 1 + done +} + +main() { + sensors_kill_all + sensors_fork_all + sensors_read_all +} + +main