Skip to content
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

docs: add docs for lambda-with-context use-case #114

Merged
merged 2 commits into from
May 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ void loop() {
```


### Usage with lambdas that capture context

You **can't pass** a lambda-**with-context** to an argument which expects a **function pointer**. To work that around,
use `paramtererizedCallbackFunction`. We pass the context (so the pointer to the object we want to access) to the library
and it will give it back to the lambda.

```CPP
okBtn.attachClick([](void *ctx){Serial.println(*(((BtnHandler*)(ctx))) -> state}}), this);
```


## State Events

Here's a full list of events handled by this library:
Expand Down Expand Up @@ -157,4 +168,4 @@ If your buttons aren't acting they way they should, check these items:
1. Check your wiring and pin numbers.
2. Did you call `tick()` on each button instance in your loop?
3. Did you alter your clock timers in any way without adjusting ticks?