From 3f79b9e4e8ed298077c69e39c91f1a3d6ec979e1 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 20 Feb 2023 22:32:56 +0100 Subject: [PATCH] Added Indicate support to Windows driver --- gattc_windows.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gattc_windows.go b/gattc_windows.go index 5cd9176..3dbb5fe 100644 --- a/gattc_windows.go +++ b/gattc_windows.go @@ -19,7 +19,7 @@ var ( errNoWriteWithoutResponse = errors.New("bluetooth: write without response not supported") errWriteFailed = errors.New("bluetooth: write failed") errNoRead = errors.New("bluetooth: read not supported") - errNoNotify = errors.New("bluetooth: notify not supported") + errNoNotify = errors.New("bluetooth: notify/indicate not supported") errEnableNotificationsFailed = errors.New("bluetooth: enable notifications failed") ) @@ -365,7 +365,8 @@ func (c *DeviceCharacteristic) Read(data []byte) (int, error) { // notification with a new value every time the value of the characteristic // changes. func (c DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) error { - if c.properties&genericattributeprofile.GattCharacteristicPropertiesNotify == 0 { + if (c.properties&genericattributeprofile.GattCharacteristicPropertiesNotify == 0) && + (c.properties&genericattributeprofile.GattCharacteristicPropertiesIndicate == 0) { return errNoNotify } @@ -403,7 +404,12 @@ func (c DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) err return err } - writeOp, err := c.characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(genericattributeprofile.GattClientCharacteristicConfigurationDescriptorValueNotify) + var writeOp *foundation.IAsyncOperation + if c.properties&genericattributeprofile.GattCharacteristicPropertiesNotify != 0 { + writeOp, err = c.characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(genericattributeprofile.GattClientCharacteristicConfigurationDescriptorValueNotify) + } else { + writeOp, err = c.characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(genericattributeprofile.GattClientCharacteristicConfigurationDescriptorValueIndicate) + } if err != nil { return err }