Skip to content

Commit

Permalink
all: use 'debug' variable protected by build tags for debug logging
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Jan 16, 2024
1 parent dc7d1b4 commit 564b0ba
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 102 deletions.
3 changes: 0 additions & 3 deletions adapter.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package bluetooth

// Set this to true to print debug messages, for example for unknown events.
const debug = false

// SetConnectHandler sets a handler function to be called whenever the adaptor connects
// or disconnects. You must call this before you call adaptor.Connect() for centrals
// or adaptor.Start() for peripherals in order for it to work.
Expand Down
12 changes: 6 additions & 6 deletions adapter_ninafw.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (a *Adapter) startNotifications() {
return
}

if _debug {
if debug {
println("starting notifications...")
}

Expand All @@ -166,7 +166,7 @@ func (a *Adapter) startNotifications() {
for {
if err := a.att.poll(); err != nil {
// TODO: handle error
if _debug {
if debug {
println("error polling for notifications:", err.Error())
}
}
Expand All @@ -180,21 +180,21 @@ func (a *Adapter) startNotifications() {
for {
select {
case not := <-a.att.notifications:
if _debug {
if debug {
println("notification received", not.connectionHandle, not.handle, not.data)
}

d := a.findDevice(not.connectionHandle)
if d.deviceInternal == nil {
if _debug {
if debug {
println("no device found for handle", not.connectionHandle)
}
continue
}

n := d.findNotificationRegistration(not.handle)
if n == nil {
if _debug {
if debug {
println("no notification registered for handle", not.handle)
}
continue
Expand All @@ -215,7 +215,7 @@ func (a *Adapter) startNotifications() {
func (a *Adapter) findDevice(handle uint16) Device {
for _, d := range a.connectedDevices {
if d.handle == handle {
if _debug {
if debug {
println("found device", handle, d.Address.String(), "with notifications registered", len(d.notificationRegistrations))
}

Expand Down
Loading

0 comments on commit 564b0ba

Please sign in to comment.