-
Notifications
You must be signed in to change notification settings - Fork 120
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
Context aware callback methods. #39
Open
murrellrr
wants to merge
29
commits into
adafruit:development
Choose a base branch
from
murrellrr:master
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.. in order for it to work in the context of flow control with hardware serial
added pinMode declaration for the RTS pin..
This allows a pointer to an object to be passed in while registering for callbacks. In turn, when the callback is invoked, the pointer will be included. This allows an instance added information, including an instance handler, for the more C++ types. This pattern is similar to the pattern followed in POSIX for thread creation.
Need to double check to see if system_events can only happen one at a time.
Will change when deprecated methods are removed.
Updated the GATT calback mechanism to separate setting the callback function pointer and enabling attributes. This is a cleaner method in the callback context world.
Context aware UART callback tested and successful. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To better facilitate C++/OO I've updated the Adafruit_BluefruitLE_nRF51 libraries for my personal use to include a context pointer (void*) that is passed in all callback methods. This is similar to the POSIX pthread_create method.
This allows for a more OO style handling of callbacks. Example:
Somewhere, in a setup method far, far, away.
ble.setCallbackContext(this);
ble.setConnectCallback(SomeClass::connect);
ble.setDisconnectCallback(SomeClass::disconnect);
SomeClass.h
// class definition
public:
static void connect(void* context) {
((SomeClass*)context)->deviceConnected();
}
// class definition
SomeClass.cpp
void SomeClass::deviceConnected() {
// do something
}
I've effectively modified all the call back function to support this behavior while still maintaining the original API for backward compatibility while the old API is deprecated and removed, should you choose.
I've also marked the deprecated methods as @deprecated in the doxygen comments. Furthermore, I split up the responsibilities of registering a GATT callback function pointer and the GATT events to get call backs for. To do this I've added the following:
ble.enableBleGattCallback(chars_idx);
ble.disableBleGattCallback(chars_idx);
I have only tested the connect and disconnect callbacks. I'm testing the UART soon. It does compile though.
Thanks for all the help and dedication for the API, it's much appreciated. The least I could do is give back a little.