I'm trying to use the last version of leOS2 scheduler from Leonardo Miliani ( https://github.com/leomil72/leOS2 ) but I have a strange behavior with a very simplistic ONETIME task.
Platform : Arduino Uno clone, so Atmel Atmega 328P CPU.
My code is very straightforward :
#include "leOS2.h"
leOS2 myOS; //create a new istance of the class leOS
bool test = true;
void setup()
{
myOS.begin(); //initialize the scheduler
}
void loop()
{
// Do some stuff ...
if(test)
{
DoAndUndo(3000);
test = false;
}
}
void DoAndUndo(unsigned long duration)
{
doSomething();
myOS.addTask(cancelTheThing, myOS.convertMs(duration), ONETIME);
}
void doSomething()
{
Serial.println("thing on");
}
void cancelTheThing()
{
Serial.println("thing is off");
}
In case it can be some kind of conflict, my code also relies on the following :
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <IRremote.h>
The problem is : myOS.addTask(cancelTheThing, myOS.convertMs(duration), ONETIME); is supposed to call asynchronously the "cancelTheThing" method 3 seconds later, and for only one time, and then forget it. But for an unknown reason, it's called after the expected delay, but it loops infinitely on this method ! In the example case above, my serial stream is filled with a lot of "thing is off" messages, and the µc is unresponsive to anything apart a reset.
The call to DoAndUndo() will produce a such like output :
thing on
And 3s later, in a very fast infinite loop :
thing is off
thing is off
thing is off
thing is off
If I remove the "ONETIME" flag, the task is called every three seconds (exactly as it's suppose to do, so the scheduler works, but it's not what I want in my use case).
note : As a try of workaround, I've tried some tricks like calling haltScheduler() inside my cancelTheThing() and reenable it with restartScheduler() in DoAndUndo(), and also tried to call removeTask once it has ran, but it didn't help.
Thank you for your help