bin/khatus_parse_upower
BASH_EXECUTABLE_NAMES := \
khatus \
+ khatus_sensor_bluetooth \
khatus_sensor_bluetooth_power \
khatus_sensor_datetime \
khatus_sensor_devices \
-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) \
# 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")
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()"
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"
--- /dev/null
+#! /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)"