FabGL
ESP32 Display Controller and Graphics Library
SSD1306_OLED/128x64/UI/UI.ino

Graphic User Interface - GUI demo

/*
Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
Copyright (c) 2019-2022 Fabrizio Di Vittorio.
All rights reserved.
* Please contact fdivitto2013@gmail.com if you need a commercial license.
* This library and related software is available under GPL v3.
FabGL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FabGL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FabGL. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* OLED - SDA => GPIO 4
* OLED - SCL => GPIO 15
*/
#include "fabgl.h"
#include "fabui.h"
#define OLED_SDA GPIO_NUM_4
#define OLED_SCL GPIO_NUM_15
#define OLED_ADDR 0x3C
// if your display hasn't RESET set to GPIO_UNUSED
#define OLED_RESET GPIO_UNUSED // ie Heltec has GPIO_NUM_16 for reset
fabgl::PS2Controller PS2Controller;
fabgl::SSD1306Controller DisplayController;
void setup()
{
Serial.begin(115200); delay(500); Serial.write("\n\n\n"); // DEBUG ONLY
PS2Controller.begin(PS2Preset::KeyboardPort0_MousePort1, KbdMode::GenerateVirtualKeys);
I2C.begin(OLED_SDA, OLED_SCL);
DisplayController.begin(&I2C, OLED_ADDR, OLED_RESET);
DisplayController.setResolution(OLED_128x64);
while (DisplayController.available() == false) {
Serial.write("Error, SSD1306 not available!\n");
delay(5000);
}
}
class MyApp : public uiApp {
void init() {
appProps().realtimeReshaping = true;
rootWindow()->frameStyle().backgroundColor = Color::Black;
auto label1 = new uiLabel(rootWindow(), "Enter you name", Point(0, 0));
label1->labelStyle().backgroundColor = Color::Black;
label1->labelStyle().textColor = Color::White;
auto textEdit1 = new uiTextEdit(rootWindow(), "", Point(0, 19), Size(128, 20));
setFocusedWindow(textEdit1);
auto button1 = new uiButton(rootWindow(), "OK", Point(48, 42), Size(30, 20));
button1->onClick = [=]() { button1Click(textEdit1->text()); };
}
void button1Click(char const * txt) {
auto frame = new uiFrame(rootWindow(), " ", Point(10, 10), Size(108, 44));
auto label1 = new uiLabel(frame, "", Point(10, 20));
label1->labelStyle().textFont = &fabgl::FONT_std_16;
label1->setTextFmt("Hello %s!!", txt);
setActiveWindow(frame);
}
} app;
void loop()
{
app.run(&DisplayController);
}
I2C class allows multiple tasks to communicate with I2C devices, serializing read/write jobs.
Definition: tsi2c.h:85
static void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)
Initializes PS2 device controller.
The PS2 device controller class.
Definition: ps2controller.h:82
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.
This file is the all in one include file. Application can just include this file to use FabGL library...
#define OLED_128x64
Definition: fabglconf.h:329
This file contains all classes related to FabGL Graphical User Interface.