| 1 | #! /bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | . ./bin/khatus_x4_lib_common_sensor.sh |
| 6 | |
| 7 | dir="${prefix}/${host}" |
| 8 | |
| 9 | sensors_kill_all() { |
| 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 || true |
| 16 | } |
| 17 | |
| 18 | sensors_fork_all() { |
| 19 | ./bin/khatus_x4_sensor_datetime -d -i 1 |
| 20 | ./bin/khatus_x4_sensor_bluetooth -d -i 1 |
| 21 | ./bin/khatus_x4_sensor_mpd -d -i 1 |
| 22 | ./bin/khatus_x4_sensor_energy -d |
| 23 | ./bin/khatus_x4_sensor_energy_poller -d -i 1 |
| 24 | ./bin/khatus_x4_sensor_memory -d -i 1 |
| 25 | ./bin/khatus_x4_sensor_loadavg -d -i 1 |
| 26 | ./bin/khatus_x4_sensor_temp -d -i 1 -- -z 0 |
| 27 | ./bin/khatus_x4_sensor_disk -d -i 1 -- -f / |
| 28 | ./bin/khatus_x4_sensor_volume -d -i 1 |
| 29 | } |
| 30 | |
| 31 | sensor_read_one() { |
| 32 | if test -f "$1" |
| 33 | then |
| 34 | cat "$1" |
| 35 | else |
| 36 | printf '%s\n' '--' |
| 37 | fi |
| 38 | } |
| 39 | |
| 40 | sensors_read_all() { |
| 41 | while : |
| 42 | do |
| 43 | battery_state="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_state)" |
| 44 | battery_state_poll="$(sensor_read_one ${dir}/khatus_x4_sensor_energy_poller/out/battery_state)" |
| 45 | battery_percentage="$(sensor_read_one ${dir}/khatus_x4_sensor_energy/out/battery_percentage)" |
| 46 | battery_percentage_poll="$(sensor_read_one ${dir}/khatus_x4_sensor_energy_poller/out/battery_percentage)" |
| 47 | bluetooth_controllers="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_powered_controllers)" |
| 48 | bluetooth_devices="$(sensor_read_one ${dir}/khatus_x4_sensor_bluetooth/out/count_connected_devices)" |
| 49 | datetime="$(sensor_read_one ${dir}/khatus_x4_sensor_datetime/out/datetime)" |
| 50 | mpd="$(sensor_read_one ${dir}/khatus_x4_sensor_mpd/out/status)" |
| 51 | mem="$(sensor_read_one ${dir}/khatus_x4_sensor_memory/out/percent_used)" |
| 52 | load="$(sensor_read_one ${dir}/khatus_x4_sensor_loadavg/out/load_avg_1min)" |
| 53 | temp="$(sensor_read_one ${dir}/khatus_x4_sensor_temp/out/thermal_zone0)" |
| 54 | disk="$(sensor_read_one ${dir}/khatus_x4_sensor_disk/out/disk_usage_percentage)" |
| 55 | vol_left="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/vol_left)" |
| 56 | vol_right="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/vol_right)" |
| 57 | vol_state="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/state)" |
| 58 | vol_mute="$(sensor_read_one ${dir}/khatus_x4_sensor_volume/out/mute)" |
| 59 | echo "E[${battery_state} ${battery_percentage} | ${battery_state} ${battery_percentage_poll}] M:${mem}% L:${load} T:${temp}°C D:${disk}% [${mpd}] B:${bluetooth_controllers}:${bluetooth_devices} V:${vol_state}:${vol_left}:${vol_right}:${vol_mute} ${datetime}" |
| 60 | sleep 1 |
| 61 | done |
| 62 | } |
| 63 | |
| 64 | main() { |
| 65 | sensors_kill_all |
| 66 | sensors_fork_all |
| 67 | sensors_read_all |
| 68 | } |
| 69 | |
| 70 | main |