Skip to content

Commit 3f79b9e

Browse files
Alexdeadprogram
Alex
authored andcommitted
Added Indicate support to Windows driver
1 parent 4c798a1 commit 3f79b9e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

gattc_windows.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
errNoWriteWithoutResponse = errors.New("bluetooth: write without response not supported")
2020
errWriteFailed = errors.New("bluetooth: write failed")
2121
errNoRead = errors.New("bluetooth: read not supported")
22-
errNoNotify = errors.New("bluetooth: notify not supported")
22+
errNoNotify = errors.New("bluetooth: notify/indicate not supported")
2323
errEnableNotificationsFailed = errors.New("bluetooth: enable notifications failed")
2424
)
2525

@@ -365,7 +365,8 @@ func (c *DeviceCharacteristic) Read(data []byte) (int, error) {
365365
// notification with a new value every time the value of the characteristic
366366
// changes.
367367
func (c DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) error {
368-
if c.properties&genericattributeprofile.GattCharacteristicPropertiesNotify == 0 {
368+
if (c.properties&genericattributeprofile.GattCharacteristicPropertiesNotify == 0) &&
369+
(c.properties&genericattributeprofile.GattCharacteristicPropertiesIndicate == 0) {
369370
return errNoNotify
370371
}
371372

@@ -403,7 +404,12 @@ func (c DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) err
403404
return err
404405
}
405406

406-
writeOp, err := c.characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(genericattributeprofile.GattClientCharacteristicConfigurationDescriptorValueNotify)
407+
var writeOp *foundation.IAsyncOperation
408+
if c.properties&genericattributeprofile.GattCharacteristicPropertiesNotify != 0 {
409+
writeOp, err = c.characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(genericattributeprofile.GattClientCharacteristicConfigurationDescriptorValueNotify)
410+
} else {
411+
writeOp, err = c.characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(genericattributeprofile.GattClientCharacteristicConfigurationDescriptorValueIndicate)
412+
}
407413
if err != nil {
408414
return err
409415
}

0 commit comments

Comments
 (0)