X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=x2%2Fsrc%2Fbash%2Fexe%2Fkhatus_sensor_bluetooth.sh;fp=x2%2Fsrc%2Fbash%2Fexe%2Fkhatus_sensor_bluetooth.sh;h=4e696c8f3a7ca7b9c632757ad379c2a868972d33;hb=b9592ab6c6553ff1568a5100169c756472aebbab;hp=0000000000000000000000000000000000000000;hpb=50401a4d45c16bd92210552252a10b7ea9b5c527;p=khatus.git 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)"