Shift X2 status from legacy to archived
[khatus.git] / x2 / src / bash / exe / khatus_sensor_bluetooth.sh
CommitLineData
b9592ab6
SK
1#! /bin/sh
2
3set -e
4
5# TODO: Centralize the definitions of the constants, as in AWK code.
6FS1='|' # Fields separator, level 1 (a record's fields)
7FS2=':' # Fields separator, level 2 (a field's subfields)
8
9count_powered_controllers() {
1cae185e 10 echo show | bluetoothctl | grep -c 'Powered: yes'
b9592ab6
SK
11}
12
13count_connected_devices() {
1cae185e
SK
14 echo paired-devices \
15 | bluetoothctl \
16 | awk '/^Device +[0-9a-zA-Z][0-9a-zA-Z]:/ {print $2}' \
17 | xargs -I % sh -c 'echo info % | bluetoothctl' \
b9592ab6
SK
18 | grep -c 'Connected: yes'
19}
20
21printf "%s%s%d\n" 'count_powered_controllers' "$FS1" "$(count_powered_controllers)"
22printf "%s%s%d\n" 'count_connected_devices' "$FS1" "$(count_connected_devices)"
This page took 0.027271 seconds and 5 git commands to generate.