From: Siraaj Khandkar Date: Tue, 19 Mar 2019 12:46:06 +0000 (-0400) Subject: Port connection-counting x4 bluetooth sensor to x2 X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=b9592ab6c6553ff1568a5100169c756472aebbab;p=khatus.git Port connection-counting x4 bluetooth sensor to x2 --- diff --git a/x2/Makefile b/x2/Makefile index 3ccc2b9..063ead5 100644 --- a/x2/Makefile +++ b/x2/Makefile @@ -27,6 +27,7 @@ AWK_EXECUTABLES := \ bin/khatus_parse_upower BASH_EXECUTABLE_NAMES := \ khatus \ + khatus_sensor_bluetooth \ khatus_sensor_bluetooth_power \ khatus_sensor_datetime \ khatus_sensor_devices \ diff --git a/x2/sanity_check b/x2/sanity_check index fad813b..a6783d6 100755 --- a/x2/sanity_check +++ b/x2/sanity_check @@ -10,8 +10,8 @@ -v Opt_Pulseaudio_Sink=0 \ -v GC_Interval=300 \ -f <(./bin/khatus_gen_bar_make_status \ - -v Status_Fmt=' E=%s%% M=%d%% P=[%s %sr %sd %st %si %sz] C=[%s %s°C %srpm] D=[%s%% %s▲ %s▼] W=[%s %s %s▲ %s▼] E:%s:%s B=%s *=%s%% (%s) [%s] %s°F %s ' \ - -v Status_Args='@energy_percent,@memory_percent,@processes_count_all,@processes_count_r,@processes_count_d,@processes_count_t,@processes_count_i,@processes_count_z,@cpu_loadavg,@cpu_temp,@cpu_fan_speed,@disk_space,@disk_io_w,@disk_io_r,@net_wifi_link:wlp4s0,@net_wifi:wlp4s0,@net_io_w:wlp4s0,@net_io_r:wlp4s0,@net_iface_status:enp0s31f6,@net_addr:enp0s31f6,@bluetooth_power,@backlight_percent,@volume:0,@mpd,@weather_temp_f,@datetime' \ + -v Status_Fmt=' E=%s%% M=%d%% P=[%s %sr %sd %st %si %sz] C=[%s %s°C %srpm] D=[%s%% %s▲ %s▼] W=[%s %s %s▲ %s▼] E:%s:%s B=[%s %s] *=%s%% (%s) [%s] %s°F %s ' \ + -v Status_Args='@energy_percent,@memory_percent,@processes_count_all,@processes_count_r,@processes_count_d,@processes_count_t,@processes_count_i,@processes_count_z,@cpu_loadavg,@cpu_temp,@cpu_fan_speed,@disk_space,@disk_io_w,@disk_io_r,@net_wifi_link:wlp4s0,@net_wifi:wlp4s0,@net_io_w:wlp4s0,@net_io_r:wlp4s0,@net_iface_status:enp0s31f6,@net_addr:enp0s31f6,@bluetooth_power,@bluetooth,@backlight_percent,@volume:0,@mpd,@weather_temp_f,@datetime' \ ) \ ) \ >(stdbuf -o L ./bin/khatus_monitor_energy) \ diff --git a/x2/src/awk/exe/bar.awk b/x2/src/awk/exe/bar.awk index 294dc45..8d611b1 100644 --- a/x2/src/awk/exe/bar.awk +++ b/x2/src/awk/exe/bar.awk @@ -194,6 +194,14 @@ function bar_make_status_net_wifi_link(interface, link) { # Bluetooth # ----------------------------------------------------------------------------- +function bar_make_status_bluetooth( src, controllers, devices) { + src = "khatus_sensor_bluetooth" + controllers = cache_get_fmt_def(src, "count_powered_controllers", 10, "%d") + devices = cache_get_fmt_def(src, "count_connected_devices" , 10, "%d") + # Using %s format bellow because default value is a string + return sprintf("%s:%s", controllers, devices) +} + function bar_make_status_bluetooth_power( src) { src = "khatus_sensor_bluetooth_power" return cache_get_fmt_def(src, "power_status", 10, "%s") diff --git a/x2/src/awk/exe/gen_bar_make_status.awk b/x2/src/awk/exe/gen_bar_make_status.awk index 2cad533..ea82f09 100644 --- a/x2/src/awk/exe/gen_bar_make_status.awk +++ b/x2/src/awk/exe/gen_bar_make_status.awk @@ -34,6 +34,7 @@ BEGIN { aliases["@net_iface_status"] = "bar_make_status_net_iface_status(\"%s\")" params["@net_iface_status"] = 1 + aliases["@bluetooth"] = "bar_make_status_bluetooth()" aliases["@bluetooth_power"] = "bar_make_status_bluetooth_power()" aliases["@backlight_percent"] = "bar_make_status_backlight_percent()" diff --git a/x2/src/bash/exe/khatus.sh b/x2/src/bash/exe/khatus.sh index 6526ab5..438828d 100644 --- a/x2/src/bash/exe/khatus.sh +++ b/x2/src/bash/exe/khatus.sh @@ -200,6 +200,7 @@ main() { fork_poller "${opts['--interval_mpd']}" "$perf" "$pipe" "$bin" "$cmd_sens_mpd" fork_poller "${opts['--interval_volume']}" "$perf" "$pipe" "$bin" "$cmd_sens_volume" fork_poller "${opts['--interval_bluetooth']}" "$perf" "$pipe" "$bin" "$cmd_sens_bluetooth" + fork_poller "${opts['--interval_bluetooth']}" "$perf" "$pipe" "$bin" 'khatus_sensor_bluetooth' fork_poller "${opts['--interval_net_wifi']}" "$perf" "$pipe" "$bin" "$cmd_sens_wifi" fork_poller "${opts['--interval_net_io']}" "$perf" "$pipe" "$bin" "$cmd_sens_net_addr_io" fork_poller "${opts['--interval_disk_space']}" "$perf" "$pipe" "$bin" "$cmd_sens_disk_space" diff --git a/x2/src/bash/exe/khatus_sensor_bluetooth.sh b/x2/src/bash/exe/khatus_sensor_bluetooth.sh new file mode 100644 index 0000000..4e696c8 --- /dev/null +++ b/x2/src/bash/exe/khatus_sensor_bluetooth.sh @@ -0,0 +1,21 @@ +#! /bin/sh + +set -e + +# TODO: Centralize the definitions of the constants, as in AWK code. +FS1='|' # Fields separator, level 1 (a record's fields) +FS2=':' # Fields separator, level 2 (a field's subfields) + +count_powered_controllers() { + bluetoothctl -- show | grep -c 'Powered: yes' +} + +count_connected_devices() { + bluetoothctl -- paired-devices \ + | awk '{print $2}' \ + | xargs -I % bluetoothctl -- info % \ + | grep -c 'Connected: yes' +} + +printf "%s%s%d\n" 'count_powered_controllers' "$FS1" "$(count_powered_controllers)" +printf "%s%s%d\n" 'count_connected_devices' "$FS1" "$(count_connected_devices)"