Created
May 30, 2020 15:59
-
-
Save anisbhsl/d905d1b65cf6c5db40896225587518a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package service | |
import "github.com/bettercap/gatt" | |
func NewBatteryService() *gatt.Service { | |
lv := byte(100) | |
s := gatt.NewService(gatt.UUID16(0x180F)) | |
c := s.AddCharacteristic(gatt.UUID16(0x2A19)) | |
c.HandleReadFunc( | |
func(rsp gatt.ResponseWriter, req *gatt.ReadRequest) { | |
rsp.Write([]byte{lv}) | |
lv-- | |
}) | |
// Characteristic User Description | |
c.AddDescriptor(gatt.UUID16(0x2901)).SetStringValue("Battery level between 0 and 100 percent") | |
// Characteristic Presentation Format | |
c.AddDescriptor(gatt.UUID16(0x2904)).SetValue([]byte{4, 1, 39, 173, 1, 0, 0}) | |
return s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment