#define OLED_SDA GPIO_NUM_4
#define OLED_SCL GPIO_NUM_15
#define OLED_ADDR 0x3C
#define OLED_RESET GPIO_UNUSED
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(45);
}
}
va_end(ap);
}
void demo1()
{
Terminal.
write(
"\e[40;32m");
Terminal.
write(
"\e[1;1H");
slowPrintf("\e[1mWELCOME TO FabGL\e[0m\r\n");
slowPrintf("www.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:\r\n \e[1m%d x %d\e[0m\r\n", Terminal.
getColumns(), Terminal.
getRows());
slowPrintf("Free Memory:\r\n \e[1m%d bytes\e[0m\r\n\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
}
void demo3()
{
Terminal.
write(
"\e[40;32m");
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#6Double W.\r\n");
slowPrintf("\e#6\e#3Double H.\r\n");
slowPrintf("\e#6\e#4Double H.\r\n");
}
void demo4()
{
Canvas cv(&DisplayController);
Terminal.
write(
"\e[40;32m");
slowPrintf("\nMixed text and graphics:\r\n");
slowPrintf("Points...\r\n");
for (int i = 0; i < 100; ++i) {
cv.setPenColor(random(256), random(256), random(256));
cv.setPixel(random(cv.getWidth()), random(cv.getHeight()));
delay(15);
}
delay(500);
slowPrintf("\e[40;32mLines...\r\n");
for (int i = 0; i < 10; ++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;32mRectangles...\r\n");
for (int i = 0; i < 10; ++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;32mEllipses...\r\n");
for (int i = 0; i < 10; ++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 < 30; ++i) {
Terminal.
write(
"\e[40;32mScrolling...\r\n");
delay(250);
}
cv.clear();
}
void setup()
{
Serial.begin(115200); delay(500); Serial.write("\n\n\n");
I2C.begin(OLED_SDA, OLED_SCL);
DisplayController.
begin(&I2C, OLED_ADDR, OLED_RESET);
while (DisplayController.
available() ==
false) {
Serial.write("Error, SSD1306 not available!\n");
delay(5000);
}
Terminal.
begin(&DisplayController);
}
void loop()
{
delay(1000);
demo1();
delay(4000);
demo3();
delay(4000);
demo4();
}
int getScreenHeight()
Determines the screen height in pixels.
int getScreenWidth()
Determines the screen width in pixels.
I2C class allows multiple tasks to communicate with I2C devices, serializing read/write jobs.
void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets SSD1306 resolution and viewport size.
bool available()
Checks the SSD1306 device availability.
void begin(I2C *i2c, int address=0x3C, gpio_num_t resetGPIO=GPIO_UNUSED)
Initializes SSD1306 assigning I2C bus, reset pin and address.
Display driver for SSD1306 based OLED display, with I2C connection.
int getRows()
Returns the number of lines.
void setLogStream(Stream &stream)
Sets the stream where to output debugging logs.
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...