tinygo-org / bluetooth

Cross-platform Bluetooth API for Go and TinyGo. Supports Linux, macOS, Windows, and bare metal using Nordic SoftDevice or HCI
https://tinygo.org
Other
744 stars 137 forks source link

EnableNotifications not handling callbacks correctly #291

Open TheRealDJ opened 1 month ago

TheRealDJ commented 1 month ago

In the EnableNotifications functions, there is no check to see if the callback passed is already on the list. For example, if you do:

c.EnableNotifications(notification_callback)
c.EnableNotifications(notification_callback)

the notification_callback function will run twice for each notification.

The callback is also not removed from the list when nil is passed as the callback, the code just sets the attribute to [0x00, 0x00]. For example:

c.EnableNotifications(notification_callback)
c.EnableNotifications(nil)
c.EnableNotifications(notification_callback)

the notification_callback function will run twice for each notification.