FabGL
ESP32 Display Controller and Graphics Library
VGA/LoopbackTerminal/LoopbackTerminal.ino

Loopback VT/ANSI Terminal

/*
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/>.
*/
#include "fabgl.h"
fabgl::VGATextController DisplayController;
fabgl::PS2Controller PS2Controller;
fabgl::Terminal Terminal;
void print_info()
{
Terminal.write("\e[37m* * FabGL - Loopback VT/ANSI Terminal\r\n");
Terminal.write("\e[34m* * 2019-2022 by Fabrizio Di Vittorio - www.fabgl.com\e[32m\r\n\n");
Terminal.printf("\e[32mScreen Size :\e[33m %d x %d\r\n", DisplayController.getViewPortWidth(), DisplayController.getViewPortHeight());
Terminal.printf("\e[32mTerminal Size :\e[33m %d x %d\r\n", Terminal.getColumns(), Terminal.getRows());
Terminal.printf("\e[32mKeyboard :\e[33m %s\r\n", PS2Controller.keyboard()->isKeyboardAvailable() ? "OK" : "Error");
Terminal.printf("\e[32mFree DMA Memory :\e[33m %d\r\n", heap_caps_get_free_size(MALLOC_CAP_DMA));
Terminal.printf("\e[32mFree 32 bit Memory :\e[33m %d\r\n\n", heap_caps_get_free_size(MALLOC_CAP_32BIT));
Terminal.write("\e[32mFree typing test - press ESC to introduce escape VT/ANSI codes\r\n\n");
}
void setup()
{
Serial.begin(115200);
PS2Controller.begin(PS2Preset::KeyboardPort0);
DisplayController.begin();
DisplayController.setResolution();
Terminal.begin(&DisplayController);
Terminal.connectLocally(); // to use Terminal.read(), available(), etc..
Terminal.clear();
print_info();
Terminal.enableCursor(true);
/*
// do you want sound on key press? ;-)
Terminal.onVirtualKey = [&](VirtualKey * vk, bool keyDown) {
if (keyDown)
Terminal.soundGenerator()->playSound(VICNoiseGenerator(), (*vk == VirtualKey::VK_RETURN ? 90 : 120), 10);;
Terminal.soundGenerator()->playSound(SquareWaveformGenerator(), (*vk == VirtualKey::VK_RETURN ? 1000 : 2000), 4);;
};
*/
}
void loop()
{
if (Terminal.available()) {
char c = Terminal.read();
switch (c) {
case 0x7F: // DEL -> backspace + ESC[K
Terminal.write("\b\e[K");
break;
case 0x0D: // CR -> CR + LF
Terminal.write("\r\n");
break;
default:
Terminal.write(c);
break;
}
}
}
int getViewPortHeight()
Determines vertical size of the viewport.
int getViewPortWidth()
Determines horizontal size of the viewport.
bool isKeyboardAvailable()
Checks if keyboard has been detected and correctly initialized.
Definition: keyboard.h:165
static Keyboard * keyboard()
Returns the instance of Keyboard object automatically created by PS2Controller.
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 connectLocally()
Permits using of terminal locally.
Definition: terminal.cpp:651
int getRows()
Returns the number of lines.
Definition: terminal.h:1217
void clear(bool moveCursor=true)
Clears the screen.
Definition: terminal.cpp:1010
int available()
Gets the number of codes available in the keyboard queue.
Definition: terminal.cpp:1697
int getColumns()
Returns the number of columns.
Definition: terminal.h:1210
size_t write(const uint8_t *buffer, size_t size)
Sends specified number of codes to the display.
Definition: terminal.cpp:1958
int read()
Reads codes from keyboard.
Definition: terminal.cpp:1703
void enableCursor(bool value)
Enables or disables cursor.
Definition: terminal.cpp:1115
void setBackgroundColor(Color color, bool setAsDefault=true)
Sets the background color.
Definition: terminal.cpp:920
bool begin(BaseDisplayController *displayController, int maxColumns=-1, int maxRows=-1, Keyboard *keyboard=nullptr)
Initializes the terminal.
Definition: terminal.cpp:323
void setForegroundColor(Color color, bool setAsDefault=true)
Sets the foreground color.
Definition: terminal.cpp:940
An ANSI-VT100 compatible display terminal.
Definition: terminal.h:953
void begin(gpio_num_t redGPIO, gpio_num_t greenGPIO, gpio_num_t blueGPIO, gpio_num_t HSyncGPIO, gpio_num_t VSyncGPIO)
This is the 8 colors (5 GPIOs) initializer.
void setResolution(char const *modeline=nullptr, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)
Sets fixed resolution.
Represents the VGA text-only controller.
This file is the all in one include file. Application can just include this file to use FabGL library...