简介: CSDN博客专家、《Android系统多媒体进阶实战》一书作者
新书发布:《Android系统多媒体进阶实战》🚀
优质专栏: Audio工程师进阶系列【原创干货持续更新中……】🚀
优质专栏: 多媒体系统工程师系列【原创干货持续更新中……】🚀
优质视频课程:AAOS车载系统+AOSP14系统攻城狮入门视频实战课 🚀
人生格言: 人生从来没有捷径,只有行动才是治疗恐惧和懒惰的唯一良药.
🌻1.前言
本篇目的:Ubuntu22.04之获取蓝牙键盘、蓝牙鼠标电量
🌻2.开发需求
通过命令获取蓝牙鼠标、蓝牙键盘电池电量
🌻3.解决方案
🐓3.1 方式一
- bluetoothctl命令
- 1.获取蓝牙设备的Mac地址(用它获取电量)
# bluetoothctl devices
Device 00:xx:xx:xx:xx:11 Bluetooth Keyboard
Device xx:xx:xx:xx:xx:22 Mouse BT3.0
- 2.获取蓝牙鼠标和键盘电量
# bluetoothctl
获取蓝牙键盘电量
# info 00:xx:xx:xx:xx:11
- 3.获取蓝牙鼠标电量
# 00:xx:xx:xx:xx:22
搜索:Battery关键字
注意:如果以上没有:Battery关键字,请继续看下面第二种方式。
🐓3.2 方式二
- upower命令
- 1.获取设备
# upower -e
/org/freedesktop/UPower/devices/battery_Mouse
/org/freedesktop/UPower/devices/keyboard_battery
2.获取蓝牙键盘电池电量:
# upower -i /org/freedesktop/UPower/devices/keyboard_battery
native-path: hid-00:xx:xx:xx:xx:xx-battery
model: xxx Keyboard
power supply: no
has history: yes
has statistics: yes
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 66%
icon-name: 'battery-full-symbolic'
- 注意:蓝牙键盘电量剩余:66%
3.获取蓝牙鼠标电池电量:
# upower -i /org/freedesktop/UPower/devices/battery_Mouse
native-path: hid-00:xx:xx:xx:xx:22-battery
model: xxx Mouse
power supply: no
has history: yes
has statistics: yes
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 88%
icon-name: 'battery-full-symbolic'
- 注意:蓝牙鼠标电量剩余:88%
4.dump所有蓝牙设备电量信息
# upower -d
native-path: hid-00:xx:xx:xx:xx:22-battery
model: xxx Mouse
power supply: no
has history: yes
has statistics: yes
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 88%
icon-name: 'battery-full-symbolic'
native-path: hid-00:xx:xx:xx:xx:xx-battery
model: xxx Keyboard
power supply: no
has history: yes
has statistics: yes
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 66%
icon-name: 'battery-full-symbolic'