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.22k stars 224 forks source link

Time when next Task should be run #109

Closed Schrolli91 closed 3 years ago

Schrolli91 commented 3 years ago

I think thats not possible at the moment - but maybe a nice-to-have feature.


Is it possible to get the time from scheduler, when the next task should be run? If i know, when next task should be run, i can sleep until this time. Maybe this can reduce power consumption a lot.

I have tested this in a little proof of concept where i calc the shortest time to the next task run in the sleep callback. At a first look it looks like working properly - maybe thats a nice feature for the future?

Have you thought about such a function till now - and do you think that there are some architecture problems for code this in a fast and stable way?

My quick-and.dirty test has reduced my power consumtion round about 50% (calced sleep time <> sleep time fixed 1000us)

arkhipenko commented 3 years ago

I did think about this. It would work only in very simple cases, and there are other issues with putting MCU to sleep for longer than 1 ms:

Since I have to maintain TS for general purpose I chose not to implement longer sleep intervals.

You can use this method: https://github.com/arkhipenko/TaskScheduler/wiki/API-Task-Scheduler#long-timeuntilnextiteration-task-atask for simple cases with just a few tasks, but remember - you need to reset the scheduling after wake up since millis() will be off.

Schrolli91 commented 3 years ago

thank you for your comments. I think you are right with the points given.