summaryrefslogtreecommitdiffstats
path: root/examples/tools
diff options
context:
space:
mode:
Diffstat (limited to 'examples/tools')
-rwxr-xr-xexamples/tools/bluetooth.sh13
1 files changed, 11 insertions, 2 deletions
diff --git a/examples/tools/bluetooth.sh b/examples/tools/bluetooth.sh
index a3af0f9..c00c853 100755
--- a/examples/tools/bluetooth.sh
+++ b/examples/tools/bluetooth.sh
@@ -16,7 +16,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# bluetooth.sh: whether bluetooth is on, the connected devices with their
-# kind (BlueZ icon name) and battery when the device reports one, and the
+# kind (BlueZ icon name) and battery when it is known, and the
# paired devices that are not connected. Only show, devices and info run
# here: nothing connects, pairs or scans.
@@ -35,7 +35,16 @@ while read -r _ mac _; do
if grep -q $'^\tConnected: yes' <<<"$info"; then
kind=$(sed -n 's/^\tIcon: //p' <<<"$info")
battery=$(sed -n 's/^\tBattery Percentage: .*(\([0-9]*\))$/\1/p' <<<"$info")
- echo "connected: $alias (${kind:-unknown kind}${battery:+, battery $battery%})"
+ # Game controllers report it through their kernel driver instead
+ # (hid-playstation, hid-sony, hid-nintendo): a power supply named
+ # after the device's address.
+ charging=""
+ for supply in /sys/class/power_supply/*"${mac,,}"*; do
+ [ -r "$supply/capacity" ] || continue
+ battery=$(<"$supply/capacity")
+ [ "$(cat "$supply/status" 2>/dev/null)" = Charging ] && charging=", charging"
+ done
+ echo "connected: $alias (${kind:-unknown kind}${battery:+, battery $battery%}$charging)"
connected=$((connected + 1))
else
others+=("$alias")