Skip to the content.

MycilaTaskManager

License: MIT Continuous Integration PlatformIO Registry

Arduino / ESP32 Task Manager Library

This is a simple task manager for Arduino / ESP32, to schedule tasks at a given frequency. Tasks are represented by anonymous function, so they must be small, non-blocking and cooperative.

Usage

Please have a look at the API and examples.

Simple task

Mycila::Task sayHello("sayHello", [](void* params) { Serial.println("Hello"); });

void setup() {
  sayHello.setEnabled(true);
  sayHello.setType(Mycila::Task::Type::FOREVER); // this is the default
  sayHello.setInterval(1000);
  sayHello.onDone([](const Mycila::Task& me, uint32_t elapsed) {
    ESP_LOGD("app", "Task '%s' executed in %" PRIu32 " us", me.name(), elapsed);
  });
}

void loop() {
  sayHello.tryRun();
}

With a TaskManager

Mycila::TaskManager loopTaskManager("loop()", 2);

Mycila::Task sayHello("sayHello", [](void* params) { Serial.println("Hello"); });
Mycila::Task sayGoodbye("sayGoodbye", [](void* params) { Serial.println("Hello"); });

void setup() {
  sayHello.setEnabled(true);
  sayHello.setType(Mycila::Task::Type::FOREVER); // this is the default
  sayHello.setInterval(1000);
  sayHello.onDone([](const Mycila::Task& me, uint32_t elapsed) { sayGoodbye.resume(); });
  loopTaskManager.addTask(sayHello);

  sayGoodbye.setEnabled(true);
  sayGoodbye.setType(Mycila::Task::Type::ONCE);
  loopTaskManager.addTask(sayGoodbye);
}

void loop() {
  loopTaskManager.loop();
}

Have a look at the API for more!

Async

Launch an async task with:

sayHello.asyncStart();

Launch an async task manager with:

loopTaskManager.asyncStart();

Watchdog Timer Support (Task WTD)

Mycila::TaskManager::configureWDT(); // Default Arduino settings
Mycila::TaskManager::configureWDT(5, false); // no panic restart

// start an async task manager with WDT (true at the end)
taskManager1.asyncStart(4096, -1, -1, 10, true);