gatt/darwin: macOS implementation and ensure pointer usage
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
47770f6c59
commit
97f17e93f1
@ -162,5 +162,9 @@ func (pd *peripheralDelegate) DidUpdateValueForCharacteristic(prph cbgo.Peripher
|
|||||||
if char != nil && char.callback != nil {
|
if char != nil && char.callback != nil {
|
||||||
go char.callback(chr.Value())
|
go char.callback(chr.Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if char.readChan != nil {
|
||||||
|
char.readChan <- nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,7 @@ type DeviceCharacteristic struct {
|
|||||||
|
|
||||||
characteristic cbgo.Characteristic
|
characteristic cbgo.Characteristic
|
||||||
callback func(buf []byte)
|
callback func(buf []byte)
|
||||||
|
readChan chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
// UUID returns the UUID for this DeviceCharacteristic.
|
// UUID returns the UUID for this DeviceCharacteristic.
|
||||||
@ -147,6 +148,18 @@ func (c *DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read reads the current characteristic value.
|
// Read reads the current characteristic value.
|
||||||
func (c DeviceCharacteristic) Read() (data []byte, err error) {
|
func (c *DeviceCharacteristic) Read() (data []byte, err error) {
|
||||||
return nil, nil
|
c.readChan = make(chan error)
|
||||||
|
c.service.device.prph.ReadCharacteristic(c.characteristic)
|
||||||
|
|
||||||
|
// wait for result
|
||||||
|
select {
|
||||||
|
case <-c.readChan:
|
||||||
|
c.readChan = nil
|
||||||
|
case <-time.NewTimer(10 * time.Second).C:
|
||||||
|
c.readChan = nil
|
||||||
|
return nil, errors.New("timeout on Read()")
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.characteristic.Value(), nil
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ func (c *DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read reads the current characteristic value.
|
// Read reads the current characteristic value.
|
||||||
func (c DeviceCharacteristic) Read() ([]byte, error) {
|
func (c *DeviceCharacteristic) Read() ([]byte, error) {
|
||||||
options := make(map[string]interface{})
|
options := make(map[string]interface{})
|
||||||
return c.characteristic.ReadValue(options)
|
return c.characteristic.ReadValue(options)
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ var readingCharacteristic struct {
|
|||||||
// Read reads the current characteristic value up to MTU length.
|
// Read reads the current characteristic value up to MTU length.
|
||||||
// A future enhancement would be to be able to retrieve a longer
|
// A future enhancement would be to be able to retrieve a longer
|
||||||
// value by making multiple calls.
|
// value by making multiple calls.
|
||||||
func (c DeviceCharacteristic) Read() ([]byte, error) {
|
func (c *DeviceCharacteristic) Read() ([]byte, error) {
|
||||||
errCode := C.sd_ble_gattc_read(c.connectionHandle, c.valueHandle, 0)
|
errCode := C.sd_ble_gattc_read(c.connectionHandle, c.valueHandle, 0)
|
||||||
if errCode != 0 {
|
if errCode != 0 {
|
||||||
return nil, Error(errCode)
|
return nil, Error(errCode)
|
||||||
|
Loading…
Reference in New Issue
Block a user