#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.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]

Generic_Display display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

Led leds[NUM_LEDS](&display);
unsigned long curr_time;

void setup()
{
  Serial.begin(9600);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }

  display.clearDisplay();

  int y = (SCREEN_HEIGHT / 2), slim = ((SCREEN_WIDTH / NUM_LEDS)), rad = slim / 2;
  for (int i = 0; i < NUM_LEDS; ++i)
  {
    // Set the coords for leds
    leds[i].set_y(y - 10); // Add 10px to led name
    leds[i].set_x(slim / 2 + (slim * i));

    // 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();
  }
  
  display.display();
}

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

  // The Led Class Method only manipulates display memory
  display.display();
}