#define TFT_SCK 18
#define TFT_MOSI 23
#define TFT_DC 22
#define TFT_RESET 21
#define TFT_SPIBUS VSPI_HOST
void setup()
{
DisplayController.
begin(TFT_SCK, TFT_MOSI, TFT_DC, TFT_RESET, -1, TFT_SPIBUS);
Terminal.
begin(&DisplayController);
}
void slowPrintf(const char * format, ...)
{
va_list ap;
va_start(ap, format);
int size = vsnprintf(nullptr, 0, format, ap) + 1;
if (size > 0) {
va_end(ap);
va_start(ap, format);
char buf[size + 1];
vsnprintf(buf, size, format, ap);
for (int i = 0; i < size; ++i) {
delay(25);
}
}
va_end(ap);
}
void demo1()
{
Terminal.
write(
"\e[40;92m");
Terminal.
write(
"\e[1;1H");
slowPrintf("**** WELCOME TO FabGL ****\r\n");
slowPrintf("by Fabrizio Di Vittorio\r\nwww.fabgl.com\r\n");
slowPrintf("==========================\r\n\n");
slowPrintf("This is a Display Controller, PS2 Mouse and Keyboard Controller, Graphics Library, Game Engine and ANSI/VT Terminal for the ESP32\r\n\n");
slowPrintf("Current settings\r\n");
slowPrintf(
"Terminal Size : %d x %d\r\n", Terminal.
getColumns(), Terminal.
getRows());
slowPrintf("Free Memory : %d bytes\r\n\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
void demo2()
{
Terminal.
write(
"\e[40;92m");
slowPrintf("8 or 64 colors supported (depends by GPIOs used)\r\n");
slowPrintf("ANSI colors:\r\n");
Terminal.
write(
"\e[31mRED\t"); delay(500);
Terminal.
write(
"\e[32mGREEN\r\n"); delay(500);
Terminal.
write(
"\e[33mYELLOW\t"); delay(500);
Terminal.
write(
"\e[34mBLUE\r\n"); delay(500);
Terminal.
write(
"\e[35mMAGENTA\t"); delay(500);
Terminal.
write(
"\e[36mCYAN\r\n"); delay(500);
Terminal.
write(
"\e[37mWHITE\t"); delay(500);
Terminal.
write(
"\e[90mHBLACK\r\n"); delay(500);
Terminal.
write(
"\e[91mHRED\t"); delay(500);
Terminal.
write(
"\e[92mHGREEN\r\n"); delay(500);
Terminal.
write(
"\e[93mHYELLOW\t"); delay(500);
Terminal.
write(
"\e[94mHBLUE\r\n"); delay(500);
Terminal.
write(
"\e[95mHMAGENTA\t"); delay(500);
Terminal.
write(
"\e[96mHCYAN\r\n"); delay(500);
Terminal.
write(
"\e[97mHWHITE\t"); delay(500);
Terminal.
write(
"\e[40mBLACK\r\n"); delay(500);
Terminal.
write(
"\e[41mRED\e[40m\t"); delay(500);
Terminal.
write(
"\e[42mGREEN\e[40m\r\n"); delay(500);
Terminal.
write(
"\e[43mYELLOW\e[40m\t"); delay(500);
Terminal.
write(
"\e[44mBLUE\e[40m\r\n"); delay(500);
Terminal.
write(
"\e[45mMAGENTA\e[40m\t"); delay(500);
Terminal.
write(
"\e[46mCYAN\e[40m\r\n"); delay(500);
Terminal.
write(
"\e[47mWHITE\e[40m\t"); delay(500);
Terminal.
write(
"\e[100mHBLACK\e[40m\r\n"); delay(500);
Terminal.
write(
"\e[101mHRED\e[40m\t"); delay(500);
Terminal.
write(
"\e[102mHGREEN\e[40m\r\n"); delay(500);
Terminal.
write(
"\e[103mHYELLOW\e[40m\t"); delay(500);
Terminal.
write(
"\e[104mHBLUE\e[40m\r\n"); delay(500);
Terminal.
write(
"\e[105mHMAGENTA\e[40m\t"); delay(500);
Terminal.
write(
"\e[106mHCYAN\e[40m\r\n"); delay(500);
}
void demo3()
{
Terminal.
write(
"\e[40;92m");
slowPrintf("\nSupported styles:\r\n");
slowPrintf("\e[0mNormal\r\n");
slowPrintf("\e[1mBold\e[0m\r\n");
slowPrintf("\e[3mItalic\e[0m\r\n");
slowPrintf("\e[4mUnderlined\e[0m\r\n");
slowPrintf("\e[5mBlink\e[0m\r\n");
slowPrintf("\e[7mInverse\e[0m\r\n");
slowPrintf("\e[1;3mBoldItalic\e[0m\r\n");
slowPrintf("\e[1;3;4mBoldItalicUnderlined\e[0m\r\n");
slowPrintf("\e[1;3;4;5mBoldItalicUnderlinedBlinking\e[0m\r\n");
slowPrintf("\e[1;3;4;5;7mBoldItalicUnderlinedBlinkingInverse\e[0m\r\n");
slowPrintf("\e#6Double Width Line\r\n");
slowPrintf("\e#6\e#3Double Height Line\r\n");
slowPrintf("\e#6\e#4Double Height Line\r\n");
}
void demo4()
{
Canvas cv(&DisplayController);
Terminal.
write(
"\e[40;92m");
slowPrintf("\nMixed text and graphics:\r\n");
slowPrintf("Points...\r\n");
for (int i = 0; i < 500; ++i) {
cv.setPenColor(random(256), random(256), random(256));
cv.setPixel(random(cv.getWidth()), random(cv.getHeight()));
delay(15);
}
delay(500);
slowPrintf("\e[40;92mLines...\r\n");
for (int i = 0; i < 50; ++i) {
cv.setPenColor(random(256), random(256), random(256));
cv.drawLine(random(cv.getWidth()), random(cv.getHeight()), random(cv.getWidth()), random(cv.getHeight()));
delay(50);
}
delay(500);
slowPrintf("\e[40;92mRectangles...\r\n");
for (int i = 0; i < 50; ++i) {
cv.setPenColor(random(256), random(256), random(256));
cv.drawRectangle(random(cv.getWidth()), random(cv.getHeight()), random(cv.getWidth()), random(cv.getHeight()));
delay(50);
}
delay(500);
slowPrintf("\e[40;92mEllipses...\r\n");
for (int i = 0; i < 50; ++i) {
cv.setPenColor(random(256), random(256), random(256));
cv.drawEllipse(random(cv.getWidth()), random(cv.getHeight()), random(cv.getWidth()), random(cv.getHeight()));
delay(50);
}
for (int i = 0; i < 15; ++i) {
Terminal.
write(
"\e[40;92mScrolling...\r\n");
delay(250);
}
cv.clear();
}
void loop()
{
delay(1000);
demo1();
delay(4000);
demo2();
delay(4000);
demo3();
delay(4000);
demo4();
delay(4000);
}
int getScreenHeight()
Determines the screen height in pixels.
int getScreenWidth()
Determines the screen width in pixels.
Implements ST7789 display driver controller.
void begin(SPIClass *spi, gpio_num_t DC, gpio_num_t RESX=GPIO_UNUSED, gpio_num_t CS=GPIO_UNUSED)
Initializes TFT display controller with Arduino style SPIClass object.
void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets TFT resolution and viewport size.
int getRows()
Returns the number of lines.
int getColumns()
Returns the number of columns.
void loadFont(FontInfo const *font)
Sets the font to use.
size_t write(const uint8_t *buffer, size_t size)
Sends specified number of codes to the display.
void enableCursor(bool value)
Enables or disables cursor.
bool begin(BaseDisplayController *displayController, int maxColumns=-1, int maxRows=-1, Keyboard *keyboard=nullptr)
Initializes the terminal.
An ANSI-VT100 compatible display terminal.
This file is the all in one include file. Application can just include this file to use FabGL library...