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.setType(Mycila::TaskType::FOREVER); // this is the default
  sayHello.setInterval(1 * Mycila::TaskDuration::SECONDS);
  sayHello.setCallback([](const Mycila::Task& me, const uint32_t elapsed) {
    ESP_LOGD("app", "Task '%s' executed in %" PRIu32 " us", me.getName(), 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.setType(Mycila::TaskType::FOREVER); // this is the default
  sayHello.setManager(loopTaskManager);
  sayHello.setInterval(1 * Mycila::TaskDuration::SECONDS);
  sayHello.setCallback([](const Mycila::Task& me, const uint32_t elapsed) { sayGoodbye.resume(); });

  sayGoodbye.setType(Mycila::TaskType::ONCE);
  sayGoodbye.setManager(loopTaskManager);
}

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);