#include <TFT_eSPI.h>
#include <SPI.h>

#include "Display.h"
#include "Led.h"

#define NUM_LEDS 3

char names[NUM_LEDS] = {'R', 'G', 'B'};
unsigned long colors[NUM_LEDS] = {TFT_RED, TFT_GREEN, TFT_BLUE};
unsigned int delays[NUM_LEDS][2] = { {2000, 2000}, {1500, 500}, {200, 800} }; // [on, off]

TFT_eSPI display = TFT_eSPI();

Led leds[NUM_LEDS];
unsigned long curr_time;

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

  display.init();
  display.setRotation(1);
  display.fillScreen(TFT_BLACK);

  int y = (SCREEN_HEIGHT / 2), slim = ((SCREEN_WIDTH / NUM_LEDS)), rad = slim / 2;
  for (int i = 0; i < NUM_LEDS; ++i)
  {
    leds[i] = Led(&display, slim / 2 + (slim * i), y - 10);

    // Adjust the size to evitate overlap
    leds[i].set_ext_rad(rad - 5);         // Set 5px margin with the col
    leds[i].set_intern_rad(rad - 5 - 5);  // Set 5px margin whth the extern circle

    // Add color and names
    leds[i].set_name(names[i]);
    leds[i].set_color(colors[i]);

    // Set delays
    leds[i].set_on_delay(delays[i][0]);
    leds[i].set_off_delay(delays[i][1]);

    // Draw base structure
    leds[i].init();
  }
}

void loop()
{
  curr_time = millis();
  for (int i = 0; i < NUM_LEDS; ++i)
  {
    leds[i].handle(curr_time);
  }
}