forked from muka/go-bluetooth
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app_char_rw.go
45 lines (36 loc) · 981 Bytes
/
app_char_rw.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package service
import (
"github.com/godbus/dbus"
log "github.com/sirupsen/logrus"
)
//ReadValue read a value
func (s *Char) ReadValue(options map[string]interface{}) ([]byte, *dbus.Error) {
log.Debug("Characteristic.ReadValue")
if s.readCallback != nil {
b, err := s.readCallback(s, options)
if err != nil {
return nil, dbus.MakeFailedError(err)
}
return b, nil
}
return s.Properties.Value, nil
}
//WriteValue write a value
func (s *Char) WriteValue(value []byte, options map[string]interface{}) *dbus.Error {
log.Trace("Characteristic.WriteValue")
val := value
if s.writeCallback != nil {
log.Trace("Used write callback")
b, err := s.writeCallback(s, value)
val = b
if err != nil {
return dbus.MakeFailedError(err)
}
} else {
log.Trace("Store directly to value (no callback)")
}
// TODO update on Properties interface
s.Properties.Value = val
s.iprops.Instance().Set(s.Interface(), "Value", dbus.MakeVariant(value))
return nil
}