79 lines
1.9 KiB
C++
79 lines
1.9 KiB
C++
#include "./screen.h"
|
|
#include "include/config.h"
|
|
#include "include/metrics.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 BaseScreen::drawArrowLeft(int16_t x, int16_t y, uint16_t color)
|
|
{
|
|
this->getDisplay()->fillTriangle(
|
|
x + Metrics::HArrowWidth, y, // Top right
|
|
x, y + (Metrics::HArrowHeight / 2), // Middle left
|
|
x + Metrics::HArrowWidth, y + Metrics::HArrowHeight, // Bottom right
|
|
color);
|
|
}
|
|
|
|
|
|
void BaseScreen::drawArrowUp(int16_t x, int16_t y, uint16_t color)
|
|
{
|
|
this->getDisplay()->fillTriangle(
|
|
x + (Metrics::VArrowWidth / 2), y, // Top middle
|
|
x, y + Metrics::VArrowHeight, // Bottom left
|
|
x + Metrics::VArrowWidth, y + Metrics::VArrowHeight, // Bottom right
|
|
color);
|
|
}
|
|
|
|
|
|
void BaseScreen::drawArrowDown(int16_t x, int16_t y, uint16_t color)
|
|
{
|
|
this->getDisplay()->fillTriangle(
|
|
x, y, // Top left
|
|
x + Metrics::VArrowWidth, y, // Top right
|
|
x + (Metrics::VArrowWidth / 2), y + Metrics::VArrowHeight, // Bottom middle
|
|
color);
|
|
}
|
|
|
|
|
|
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);
|
|
}
|