#include "./screen.h"
#include "include/config.h"


Adafruit_GFX* BaseScreen::getDisplay()
{
  return this->screenManager->getDisplay();
}


uint16_t BaseScreen::printCentered(const char* text, int16_t y)
{
  auto display = this->getDisplay();

  int16_t textX;
  int16_t textY;
  uint16_t textW;
  uint16_t textH;
  display->getTextBounds(text, 0, 0, &textX, &textY, &textW, &textH);

  textX = (Config::DisplayWidth - textW) / 2;
  display->setCursor(textX, y);
  display->print(text);

  return textW;
}


void ScreenManager::init()
{
  pinMode(Config::DisplayPinBL, OUTPUT);
  digitalWrite(Config::DisplayPinBL, HIGH);
}


void ScreenManager::displayOff()
{
  digitalWrite(Config::DisplayPinBL, LOW);
  this->display->sendCommand(ST77XX_SLPIN);
}


void ScreenManager::displayOn()
{
  this->display->sendCommand(ST77XX_SLPOUT);
  digitalWrite(Config::DisplayPinBL, HIGH);
}
