Skip to content

Modify OnTick_t typedef for ESP8266 platform#16

Open
gmag11 wants to merge 3 commits intoPaulStoffregen:masterfrom
gmag11:ESP_std_function
Open

Modify OnTick_t typedef for ESP8266 platform#16
gmag11 wants to merge 3 commits intoPaulStoffregen:masterfrom
gmag11:ESP_std_function

Conversation

@gmag11
Copy link
Copy Markdown

@gmag11 gmag11 commented Aug 19, 2016

Having this change does not modify library interface but enables the possibility to use class member methods as callback with the help of std::bind().
Unfortunately I've not found a way to do the same with Arduino platform, so I've filtered it using preprocessor.

I've added an example on how to use this feature.

gmag11 added 3 commits August 19, 2016 11:00
Having this change does not modify library interface but enables the possibility to use class member methods as callback with the help of `std::bind()`.
Unfortunately I've not found a way to do the same with Arduino platform, so I've filtered it using preprocessor..
Add TimeAlarm example for ESP8266 using class methods
*/

#define YOUR_WIFI_SSID "Your_SSID"
#define YOUR_WIFI_SSID "Your_Pw"
Copy link
Copy Markdown

@pierangelof pierangelof Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi gmag11,
thank you very much for your job.

The line 21 should be corrected as follows:

-#define YOUR_WIFI_SSID "Your_Pw"
+#define YOUR_WIFI_PASSWD "Your_Pw"

@jhagberg
Copy link
Copy Markdown

Since Arduino esp8266 release 2.4.0 makes the TimeLib not needed it would be interesting to build a newlib time.h version of TimeAlarms.

}
if (TickHandler != NULL) {
(*TickHandler)(); // call the handler
TickHandler(); // call the handler
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request was not merged because of this change.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, even though I'm not the author of the pull request, I'm still wondering why line 245 is preventing the PR from being merged. Would you mind elaborating? To me the proposed extension seem to be implemented exactly as it is in other libraries (e.g. the ubiquitous "PubSubClient" MQTT client). The syntax change of line 245 simply ensures that the calling syntax is compatible with both cases: plain old function pointer and std::function.

I'd quite like to see this extension implemented in TimeAlarms. It allows for more elegant OOP design.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like you can have a try of my fork of the TimeAlarm. I rewrote it using the latest ESP 2.4 that is using Newlib C time functions.
https://github.com/jhagberg/ESP8266TimeAlarms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out! Personally I try as much as possible to use the libraries available through platform.io's package manager and treat those as the "canonical" versions. That's why I'm interested in contributing some minor ESP8266-relatex fixes. A second consideration is to use platform-agnostic libraries (AVR vs ESP) whenever possible.
But then again, having a rebased library specifically for the ESP8266's C library is quite nice, too. Thanks!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this code is not reviewed by anyone yet. But it will handle Timezones and Daylight savings very nicely without any extra library. And works for me for the moment at least!

@tonilopezmr
Copy link
Copy Markdown

tonilopezmr commented Nov 13, 2019

Edit: I'm trying to do this on Arduino not ESP8266

@gmag11 finally did you use your branch? I'd like to use std::bind on Arduino with timeAlarms like this:

auto activation = std::bind(activateEvenDay, sector.id);   
Alarm.alarmRepeat(hour, minutes, 0, activation);     

I tried with lambda functions too but cannot convert Context::<lambda()> to OnTick_t {aka void (*)()} with this code:

unsigned char id = sector.id;
auto activation = [id]() { activateEvenDay(id); };
Alarm.alarmRepeat(hour, minutes, 0, activation);

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.

6 participants