Skip to content

Commit

Permalink
Added Indicate support to Windows driver
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex authored and deadprogram committed Feb 26, 2023
1 parent 4c798a1 commit 3f79b9e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions gattc_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 3f79b9e

Please sign in to comment.