blynkkk / blynk-library

Blynk library for IoT boards. Works with Arduino, ESP32, ESP8266, Raspberry Pi, Particle, ARM Mbed, etc.
https://blynk.io
MIT License
3.84k stars 1.39k forks source link

Add supporting of lambda-expressions in BlynkTimer functions #461

Closed EvsanDlg closed 3 years ago

EvsanDlg commented 5 years ago

It is unable now to use setTimeout or any other blynk timer functions with lambdas like this:

int testParameter = 45;
timer.setTimeout(1000L, [=]()  {
      Serial.println("Lambda gets:" + (String)testParameter);
    } );

Getting an error: "no matching function for call to 'BlynkTimer::setTimeout(long int, setup()::__lambda0)'"

This issue was also disscussed at blynk community forum

Supposedly, BlynkTimer does not support lambda (as far as the way it should be), because it is a fork of Marcello Romani’s Simple timer, that neither does. But there is another fork on github, where the support of lambdas stated as a feature.

Some changes with timer_callback (timer_callback_p) typedefs and style of calling passed functions needed.

As a result of fix, supporting std::function or lambda-expressions known from C++11 will get an ability to pass local vars to lambda, and thanks to it use deffered actions with fixed values in lambda-manner

blynkkk commented 5 years ago

You are very welcome to make enhancements and propose a pull request. We’d be happy to review and merge.

Thanks!

EvsanDlg commented 5 years ago

Ohh, forgot to answer the thread.. I have poor skills in C++. I tried just to change typedef-s like in forked SimpleTimer but it doesn't help. Obviously, some deeper changes needed with BlynkTimer. It would be great if your team or someone managed this. Thanks!