| 1 |
package service |
| 2 |
|
| 3 |
import "github.com/bettercap/gatt" |
| 4 |
|
| 5 |
func NewBatteryService() *gatt.Service { |
| 6 |
lv := byte(100) |
| 7 |
s := gatt.NewService(gatt.UUID16(0x180F)) |
| 8 |
c := s.AddCharacteristic(gatt.UUID16(0x2A19)) |
| 9 |
c.HandleReadFunc( |
| 10 |
func(rsp gatt.ResponseWriter, req *gatt.ReadRequest) { |
| 11 |
rsp.Write([]byte{lv}) |
| 12 |
lv-- |
| 13 |
}) |
| 14 |
|
| 15 |
|
| 16 |
c.AddDescriptor(gatt.UUID16(0x2901)).SetStringValue("Battery level between 0 and 100 percent") |
| 17 |
|
| 18 |
|
| 19 |
c.AddDescriptor(gatt.UUID16(0x2904)).SetValue([]byte{4, 1, 39, 173, 1, 0, 0}) |
| 20 |
|
| 21 |
return s |
| 22 |
} |