// https://forum.arduino.cc/t/what-would-be-a-good-synonym-for-delay/1004293
// https://forum.arduino.cc/t/how-to-use-millis-to-control-multi-period/1034904

#include "scheduler.h"

Scheduler scheduler;


bool taskOne(Task&) {
  Serial.println("Task one.");
  return true;
}

bool taskTwo(Task&) {
  Serial.println("Task two.");
  return true;
}


bool stateOne(Task&) {
  Serial.println("State one.");

  static size_t i = 0;
  i = (i + 1) % 3;
  if (not i) {
    scheduler.add(500, stateTwo);
    return true;
  }

  return false;
}

bool stateTwo(Task&) {
  Serial.println("State two.");
  scheduler.add(500, stateThree);
  return true;
}

bool stateThree(Task&) {
  Serial.println("State three.");
  scheduler.add(500, stateOne);
  return true;
}


bool stateAlpha(Task& task) {
  Serial.println("State alpha.");
  if (task.expired) {
    scheduler.add(0, 500, stateBeta);
    return true;
  }
  return false;
}

bool stateBeta(Task& task) {
  Serial.println("State beta.");
  if (task.expired) {
    scheduler.add(0, 500, stateAlpha);
    return true;
  }
  return false;
}


void setup() {
  Serial.begin(9600);

  /*
  // Simple tasks.
  scheduler.add(2000, taskOne);
  scheduler.add(4000, taskTwo);

  // Simple state machine.
  scheduler.add(6000, stateOne);
  */

  scheduler.add(0, 500, stateAlpha);
}

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