-
Notifications
You must be signed in to change notification settings - Fork 142
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
hci: implement write handler #236
Conversation
a896c7a
to
8e05d2c
Compare
This device has been working without error for over 24 hours now on this PR and #235 |
@@ -22,6 +22,7 @@ type hciAdapter struct { | |||
|
|||
connectedDevices []Device | |||
notificationsStarted bool | |||
charWriteHandlers []charWriteHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious why this isn't a Go map, keyed by handle uint16?
type callback func(connection Connection, offset int, value []byte)
map[uint16]callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied the implementation from https://github.com/tinygo-org/bluetooth/blob/dev/adapter_sd.go#L49 to keep things uniform.
return nil | ||
|
||
case (time.Now().UnixNano()-start)/int64(time.Second) > defaultTimeoutSeconds: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is outside the scope of the PR, but is this equivalent code for the time math?
timeout := time.Now().Add(defaultTimeoutSeconds)
for {
...
switch {
case time.Now().After(timeout):
return ErrATTTimeout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would guess it might be a little faster due to the integer part of the calculation? I also copied that from elsewhere, so perhaps @aykevl can elaborate on why (or why not?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly no idea, you'd have to look at the source of .Add
or do a benchmark to check.
In general, when in doubt (or without a benchmark) I recommend taking the simpler approach - in this case, time.Now().Add
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to replace some of these sprinkled thru my code...
Signed-off-by: deadprogram <[email protected]>
Signed-off-by: deadprogram <[email protected]>
8e05d2c
to
3dd0b2c
Compare
This PR extends the
hci
to implements theWriteHandler
onCharacteristic
.Note this PR depends on #235 and will need to be rebased once that PR is merged.