diff --git a/gatts.go b/gatts.go index aa9b64d6..92abdaf0 100644 --- a/gatts.go +++ b/gatts.go @@ -18,6 +18,7 @@ type CharacteristicConfig struct { Value []byte Flags CharacteristicPermissions WriteEvent func(client Connection, offset int, value []byte) + ReadEvent func(client Connection) ([]byte, error) } // CharacteristicPermissions lists a number of basic permissions/capabilities diff --git a/gatts_linux.go b/gatts_linux.go index 21a4c81a..4d486e46 100644 --- a/gatts_linux.go +++ b/gatts_linux.go @@ -1,3 +1,4 @@ +//go:build !baremetal // +build !baremetal package bluetooth @@ -83,6 +84,14 @@ func (a *Adapter) AddService(s *Service) error { }) } + // Lazy read value + if char.ReadEvent != nil { + callback := char.ReadEvent + bluezChar.OnRead(func(c *service.Char, options map[string]interface{}) ([]byte, error) { + return callback(0) + }) + } + // Add characteristic to the service, to activate it. err = bluezService.AddChar(bluezChar) if err != nil {