h2zero / esp-nimble-cpp

C++ library for the esp32 NimBLE stack based on and mostly compatible with @nkolban cpp_utils BLE library.
https://h2zero.github.io/esp-nimble-cpp/
Apache License 2.0
181 stars 62 forks source link

[BREAKING] - Refactor NimBLEScan #231

Closed h2zero closed 6 days ago

h2zero commented 1 week ago

Fixes #73

thekurtovic commented 1 week ago

NimBLEScan::stop will no longer call the onScanEnd callback as the caller should know its been stopped when this is called.

There are some spots where NimBLEScan::stop is called internally, I think it would be good to still call the onScanEnd callback in such cases. What about adding a parameter which defaults to false, else will call onScanEnd? I don't stop the scan explicitly before connecting as I liked how the NimBLE Async Client handles it.

h2zero commented 1 week ago

The reason for the change is so the application can make use of the callback to attempt to restart it. When connecting it will always be stopped first and that's about the only time that it is internally called other than when the app specifies to reset.

h2zero commented 1 week ago

Hmm, now that I think about it, a reason code parameter should be added to the callback so the application can decide what to do from there.

thekurtovic commented 1 week ago

I don't understand how can the application use the callback if it's never called? Do you mean the proper usage would be to always have the application stop the scan explicitly, and not use the convenience of the connect function?

h2zero commented 1 week ago

The purpose of the callback is to let the application know when the scan stopped due to a timeout or error. The stack itself doesn't generate an event when the scan is stopped manually, likely for the same reason.