开源 Windows 版蓝牙电池监控器
Open source Bluetooth battery monitor for Windows
I'm not using UWP, only classic C/C++ API (check out misc directory for more C++ examples).
SetupDiGetClassDevs / SetupDiEnumDeviceInfo for getting a list of all bluetooth devices.SetupDiGetDeviceRegistryProperty / SPDRP_HARDWAREID for filtering by device address.BluetoothGATTGetServices / BluetoothGATTGetCharacteristics for BLE properties.SetupDiGetDeviceProperty / DEVPKEY_DeviceContainer_IsConnected for connection status.{e0cbf06c-cd8b-4647-bb8a-263b43f0f974} (Bluetooth Device) for SetupDiGetClassDevs.{00001800-0000-1000-8000-00805F9B34FB} (Generic Attribute) for Appearance (0x2A01).{0000180F-0000-1000-8000-00805F9B34FB} (Battery Service) for Battery Level (0x2A19).{0000180A-0000-1000-8000-00805F9B34FB} (Device Information) for Manufacturer (0x2A29).HFPGetBatteryLevel accordingly).
HFP devices also expose HID interface, probably it's all doable with HID API or a system-wide dll hook. Will implement later.BLUETOOTH_GATT_FLAG_FORCE_READ_FROM_DEVICE (0x00000004) timeouts on disconnected devices, check their status first.{00001800-0000-1000-8000-00805F9B34FB} (Generic Attribute) is read only, don't use GENERIC_WRITE in CreateFile.暂无开放 Issues,或尚未同步最近议题。