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

Use std::function to allow C++ 11 lambda functions #29

Merged
merged 1 commit into from Sep 12, 2021

Conversation

jacobdekeizer
Copy link
Contributor

@jacobdekeizer jacobdekeizer commented Sep 11, 2021

Hi,

Thank you for making this library.
I needed to access the this context from a callback in my project, so that I could update a counter in my class.
Having the CallbackFunction use std::function, makes it possible to use the C++11 lambda functions.

My example:

void DevicesScreenActivity::begin()
{
  this->_inputManager->left.setReleasedHandler([&](Button2 &b) {
    Serial.println("test");

    this->selected++;
  });
}

@LennartHennigs LennartHennigs merged commit 85e9445 into LennartHennigs:master Sep 12, 2021
@LennartHennigs
Copy link
Owner

Hey,
thanks for pointing this out and adding this.
Will merge it!

@ItsFlo
Copy link

ItsFlo commented Sep 16, 2021

This breaks compiling for Arduino for me. Compiling for ESP32 and ESP8266 both worked.
I also tried a clean install of the Arduino IDE, only downloaded this library and only added #include "Button2.h" to an empty sketch and it didn´t compile:

fatal error: functional: No such file or directory

I tried to compile for both Uno and Nano.

@jacobdekeizer are you using an Arduino for your project or something else?

@jacobdekeizer
Copy link
Contributor Author

Hi, I am using an esp32. I didn't know the arduino uno does not support the c++ standard library. I found this example so we can target both esp32/esp8266 and arduino: https://github.com/blynkkk/blynk-library/blob/master/src/Blynk/BlynkConsole.h#L31.

@LennartHennigs
Copy link
Owner

Hey, I add pre-processor directives to detect ESP8266 & EPS32s and pushed a new released. The code now compiles on Arduino and these two platforms. I will keep it now as it is and maybe revisit it later to find a better solution.

Thanks @ItsFlo for finding the error and thanks @jacobdekeizer for suggesting a fix.
Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants