Skip to content

Commit 04fbc0e

Browse files
kevin-activdeadprogram
authored andcommitted
Fix for darwin enable-notifications API to allow disabling of
notifications by passing in nil as the callback argument
1 parent cd4f1c2 commit 04fbc0e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

gattc_darwin.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,17 @@ func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error)
211211
// Configuration Descriptor (CCCD). This means that most peripherals will send a
212212
// notification with a new value every time the value of the characteristic
213213
// changes.
214+
// Users may call EnableNotifications with a nil callback to disable notifications.
214215
func (c DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) error {
216+
// If callback is nil, disable notifications
215217
if callback == nil {
216-
return errors.New("must provide a callback for EnableNotifications")
218+
c.service.device.prph.SetNotify(false, c.characteristic)
219+
c.callback = nil // Clear notification callback
220+
} else {
221+
// Enable notifications and set notification callback
222+
c.callback = callback
223+
c.service.device.prph.SetNotify(true, c.characteristic)
217224
}
218-
219-
c.callback = callback
220-
c.service.device.prph.SetNotify(true, c.characteristic)
221-
222225
return nil
223226
}
224227

0 commit comments

Comments
 (0)