Non blocking delay
Closed this issue · 7 comments
Line 150 in 3ad9ac8
Could you use a non blocking delay instead of the while?
In the previous line there is a yield()
, thus actually the loop is not blocking any scheduled task.
If you do not want to pause your main thread, why would you use the delay()
method? This method is intended to pause your main thread while still servicing the alarms during that period.
If you want to pause without servicing, use the general delay()
function.
If you want to do other things and still service the alarms, just insert serviceAlarms();
here and there in your code.
I am closing the issue. If you feel that this did not answer your question, please provide more information and reopen it.
Hey,
thanks for your answer. I want to still use serviceAlarms(); but the problem is, that it is a private function, that's why I asked if you could make the delay not pause the thread.
In file included from sketch\connection.h:19:0,
from sketch\timer.cpp:9:
C:\Users\patri\Documents\Arduino\libraries\CronAlarms\src/CronAlarms.h: In member function 'void CONNECTION::timerLoop()':
C:\Users\patri\Documents\Arduino\libraries\CronAlarms\src/CronAlarms.h:53:8: error: 'void CronClass::serviceAlarms()' is private
void serviceAlarms();
^
timer.cpp:44:22: error: within this context
Cron.serviceAlarms();
^
exit status 1
within this context
delay(0); ?
What? I don‘t get what you mean. I‘m talking about that serviceAlarms is a private function, so I can‘t call it from my code.
Have you tried Cron.delay(0);
which should have the same effect as calling serviceAlarms
directly (which is not possible)?
No but isn't it still calling the while, which might pause the thread for like a milli or micro second?
The story behind is that I'm running some LEDs and the effects should be look very smooth and clear. And thats not possible if something delays/pauses them.
The code needed to check whether an alarm should be fired takes much more time than the comparison, that will only be run once.
Check if it works for you the way it is designed. If not, you should not use this library, which is designed to be serviced in a loop (pooling). You should try to use time based interrupts for your alarms instead.