arkhipenko / TaskScheduler

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers
http://playground.arduino.cc/Code/TaskScheduler
BSD 3-Clause "New" or "Revised" License
1.23k stars 224 forks source link

Example of std::function usage #32

Closed BlackEdder closed 7 years ago

BlackEdder commented 7 years ago

Example of std::function usage as requested in #28.

BlackEdder commented 7 years ago

Note that this PR is for the testing branch.

arkhipenko commented 7 years ago

Hi Edwin,

Thank you.

Wow,. This is definitely different from all the code I wrote for Arduino.

And it's not that anything is wrong with it, it's all in my mind: the OO abstraction somehow always ends at the library level, and the sketches are always non-OO, with tasks and scheduler always created static and being very explicit.

I have not thought of encapsulating tasks inside another class.

One of the reasons is that effective scheduling could be achieved if [almost] nothing else is going on in the "loop()" (which is the case in your example, so no complaints).

The other reason was that callback methods of one task manipulated the execution parameters of other tasks, and therefore needed free access to all task objects running.

I will need to think long and hard how to use OO way you just introduced. But that's ok, thanks for your help.

Let me merge it and get testing.

Still planning to rename the callback types [😊]

Regards,

Anatoli

'


From: Edwin van Leeuwen notifications@github.com Sent: Friday, April 28, 2017 5:29 PM To: arkhipenko/TaskScheduler Cc: Subscribed Subject: Re: [arkhipenko/TaskScheduler] Example of std::function usage (#32)

Note that this PR is against the testing branch.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/arkhipenko/TaskScheduler/pull/32#issuecomment-298111156, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AATGTUiZ_w1yzywOsucm5G_yaqkWzEauks5r0lpCgaJpZM4NL_aX.

arkhipenko commented 7 years ago

ok. here is the first test result:

Arduino: 1.8.2 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from C:\Users\anatoli\Documents\Arduino\libraries\TaskScheduler\examples\Scheduler_example15_STDFunction\Scheduler_example15_STDFunction.ino:6:0:

C:\Users\anatoli\Documents\Arduino\libraries\TaskScheduler\src/TaskScheduler.h:212:22: fatal error: functional: No such file or directory

include \<functional>

                  ^

compilation terminated.

exit status 1 Error compiling for board Arduino/Genuino Uno.

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

compiling for Arduino Uno.

What am I doing wrong?

arkhipenko commented 7 years ago

Update: example 15 compiled successfully for ESP8266, but still does not compile for Arduino boards. Thoughts?

BlackEdder commented 7 years ago

I only ever tried it on the ESP8266. Looks like the standard arduino libraries don't include the functional header file at all. Sorry, I should have checked that.

arkhipenko commented 7 years ago

So we can limit this functionality to esp only, or find a way to include it into Arduino core (ourselves, or petition the Arduino dev team).

Is there a way to add this to Arduino core ourselves?

Sent from a mobile device. Apologies for accidental typos.

-------- Original message -------- From: Edwin van Leeuwen notifications@github.com Date: 4/29/17 7:54 AM (GMT-05:00) To: arkhipenko/TaskScheduler TaskScheduler@noreply.github.com Cc: Anatoli Arkhipenko arkhipenko@hotmail.com, Comment comment@noreply.github.com Subject: Re: [arkhipenko/TaskScheduler] Example of std::function usage (#32)

I only ever tried it on the ESP8266. Looks like the standard arduino libraries don't include the functional header file at all. Sorry, I should have checked that.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/arkhipenko/TaskScheduler/pull/32#issuecomment-298164441, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AATGTSPqWt45CWNzzqvJzlLBmIPd9di0ks5r0yTugaJpZM4NL_aX.

BlackEdder commented 7 years ago

So on my machine functional is added from here:

$HOME/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/functional

I had a look at that header, but it also depends on multiple other includes (that might not be part of arduino libraries). Do you happen to know which toolchain arduino uses?

arkhipenko commented 7 years ago

On my linux box I have it in

$HOME/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2

Looks like you are using platform.io, and I still use the IDE

The arduino includes seem to be in this folder (I installed IDE into /opt): /opt/arduino/hardware/tools/avr/avr/include and it seems to be considerably pruned (compared to the ESP8266 for sure: no c++ subfolder at all, much fewer .h files).

Looks like we'll have to limit the functionality to ESP boards only... I have already made the changes and testing.


From: Edwin van Leeuwen notifications@github.com Sent: Thursday, May 4, 2017 4:15 PM To: arkhipenko/TaskScheduler Cc: Anatoli Arkhipenko; Comment Subject: Re: [arkhipenko/TaskScheduler] Example of std::function usage (#32)

So on my machine functional is added from here:

$HOME/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/functional

I had a look at that header, but it also depends on multiple other includes (that might not be part of arduino libraries). Do you happen to know which toolchain arduino uses?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/arkhipenko/TaskScheduler/pull/32#issuecomment-299296551, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AATGTYthCthLbkcHlmDspkSxaaAQgCwEks5r2jHogaJpZM4NL_aX.