Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the EnableNotifications Method, add the parameter to specifing… #293

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

lemongGH
Copy link

update the EnableNotifications Method,
add the parameter to specifing the notify or indicate mode of characters,
just for windows os

… the notify or indicate mode of characters, just for windows os
@lemongGH
Copy link
Author

sorry
I add a new argument to the method and this will throw an new error
I will try to fix this in a new PR

@lemongGH
Copy link
Author

I has fixed the error of new argument

@@ -360,14 +361,29 @@ func (c DeviceCharacteristic) Read(data []byte) (int, error) {
return len(readBuffer), nil
}

// EnableNotifications enables notifications in the Client Characteristic
// Configuration Descriptor (CCCD). Just the Notify mode is supported.
func (c DeviceCharacteristic) EnableNotifications(callback func(buf []byte)) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnableNotifications enables notifications or indications, whatever is available. And it favors notifications over indications. This PR should not change that behaviour.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i will update to keep the original behavior

gattc_windows.go Outdated
if (c.properties&genericattributeprofile.GattCharacteristicPropertiesNotify == 0) &&
(c.properties&genericattributeprofile.GattCharacteristicPropertiesIndicate == 0) {
return errNoNotify
func (c DeviceCharacteristic) EnableNotificationsWithMode(usingIndicate bool, callback func(buf []byte)) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan of using boolean flags for this. It may make sense for methods that enable or disable something. But I think that in this case it is confusing as the user needs to know what true or false means.

An enum may be a better option. Maybe something like this?

type NotificationMode = genericattributeprofile.GattCharacteristicProperties

const (
	NotificationModeNotify   NotificationMode = genericattributeprofile.GattCharacteristicPropertiesNotify
	NotificationModeIndicate NotificationMode = genericattributeprofile.GattCharacteristicPropertiesIndicate
)

This also allows simplifying the branching inside the method:

func (c DeviceCharacteristic) EnableNotificationsWithMode(mode NotifyMode, callback func(buf []byte)) error {
	if mode != NotificationModeIndicate && mode != NotificationModeNotify {
		return errInvalidNotificationMode
	}
	if c.properties&mode == 0 {
		return errNoNotify
	}
	...
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well , using enum makes code easier to understand.
Thanks for your advice.
I had changed my code and commit again.
If you have any other ideas, please let me know. Thank you

Copy link
Author

@lemongGH lemongGH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updates:
update to keep the original behavior of EnableNotification
update to using a mode enum instead of the bool param of EnableNotifacationWithMode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants