Skip to content

Commit ef974ef

Browse files
committed
Bluetooth (macOS): support battery level detection
1 parent 40671c7 commit ef974ef

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/detection/bluetooth/bluetooth_apple.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
#import <IOBluetooth/IOBluetooth.h>
44

5+
@interface IOBluetoothDevice()
6+
@property (nonatomic) uint8_t batteryPercentCase;
7+
@property (nonatomic) uint8_t batteryPercentCombined;
8+
@property (nonatomic) uint8_t batteryPercentLeft;
9+
@property (nonatomic) uint8_t batteryPercentRight;
10+
@property (nonatomic) uint8_t batteryPercentSingle;
11+
@end
12+
513
const char* ffDetectBluetooth(FFlist* devices /* FFBluetoothResult */)
614
{
715
NSArray<IOBluetoothDevice*>* ioDevices = IOBluetoothDevice.pairedDevices;
@@ -14,7 +22,14 @@
1422
ffStrbufInitS(&device->name, ioDevice.name.UTF8String);
1523
ffStrbufInitS(&device->address, ioDevice.addressString.UTF8String);
1624
ffStrbufInit(&device->type);
17-
device->battery = 0;
25+
26+
if (ioDevice.batteryPercentSingle)
27+
device->battery = ioDevice.batteryPercentSingle;
28+
else if (ioDevice.batteryPercentCombined)
29+
device->battery = ioDevice.batteryPercentCombined;
30+
else if (ioDevice.batteryPercentCase)
31+
device->battery = ioDevice.batteryPercentCase;
32+
1833
device->connected = !!ioDevice.isConnected;
1934
if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorLimitedDiscoverableMode)
2035
ffStrbufAppendS(&device->type, "Limited Discoverable Mode, ");

0 commit comments

Comments
 (0)