#include "display.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


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

void displayPrint(char *data, char position, int row, int size, char colour){
  display.setTextSize(size);

  if(colour == 'w' || colour == 'W') display.setTextColor(SSD1306_WHITE);
  else if(colour == 'b' || colour == 'B') display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);

  int rdk = 0;

  if(row == 0) rdk = 0;
  if(size == 1) rdk = row * 8;
  else if(size == 2) rdk = row * 16;
  else if(size == 3) rdk = row * 24;
  
  if(position == 'l' || position == 'L'){
    display.setCursor(0,rdk);
    display.print(data);
  }

  if(position == 'r' || position == 'R'){
    if(size == 1) display.setCursor((128) - strlen(data)*6,rdk);
    else if(size == 2) display.setCursor((128) - strlen(data)*12,rdk);
    else if(size == 3) display.setCursor((128) - strlen(data)*18,rdk);
    display.print(data);
  }

  if(position == 'c' || position == 'C'){
    if(size == 1) display.setCursor((128/2) - strlen(data)*3,rdk);
    else if(size == 2) display.setCursor((128/2) - strlen(data)*6,rdk);
    else if(size == 3) display.setCursor((128/2) - strlen(data)*9,rdk);
    display.print(data);
  }
}

void displayPrint(int data, char position, int row, int size, char colour){
    char buffer [33];
    displayPrint(itoa(data, buffer, 10), position, row, size, colour);
}

void displayPrint(char *data, char position, int row, int size, bool colour){
  if(colour == 0) displayPrint(data, position, row, size, 'B');
  else displayPrint(data, position, row, size, 'W');
}

void displayPrint(int data, char position, int row, int size, bool colour){
  if(colour == 0) displayPrint(data, position, row, size, 'B');
  else displayPrint(data, position, row, size, 'W');
}