Skip to content

Commit 241e700

Browse files
committed
Add BatteryLevel parse function
1 parent 94064f2 commit 241e700

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • PluginSDK/Examples/BatteryLevel/Sources/BatteryLevel
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Plugin.swift
3+
// BatteryLevel
4+
//
5+
// The only file a plugin author writes: a pure function from ParseInput to Fields.
6+
// Decodes the GATT Battery Level characteristic (0x2A19), a single percentage byte.
7+
//
8+
9+
import BLEPluginSDK
10+
11+
func parseCharacteristic(_ input: ParseInput) -> Fields? {
12+
// Routing already guarantees 0x2A19, but check so the plugin is correct standalone.
13+
guard input.uuid?.assignedNumber16 == 0x2A19 else { return nil }
14+
15+
var payload = input.payload
16+
guard let level = payload.readUInt8() else { return nil }
17+
18+
var fields = Fields(summary: "Battery")
19+
fields.uint("level", label: "Battery Level", UInt64(level), unit: "%")
20+
return fields
21+
}

0 commit comments

Comments
 (0)