- KEYWORDS: Module,VT100,Terminal,Console
- USES: Graphics
[[VT100.js]] is a VT100 terminal emulator - it takes a series of characters and draws them on a [[Graphics]] object, interpretering newline/carriage return/up/down/left/right/etc correctly.
It isn't a full emulator, but emulates enough of a terminal to correctly display everything that comes out of Espruino.
The main use for this is allow you to display Espruino's console on a screen connected to Espruino itself.
To do this you'd want to use LoopbackA
and LoopbackB
:
// take characters from Espruino, and push them into the VT100 terminal
LoopbackB.on('data',function(e){
// USB.write(e); // optionally mirror back to the PC
// Send characters to the terminal
for (var i in e) term.char(e[i]);
// update the screen
g.flip();
});
// copy characters coming down USB into the 'loopback' device
USB.on('data',function(e){ LoopbackB.write(e); });
// Now move the console to Loopback
LoopbackA.setConsole();
For example, assuming you have an LCD connected as described in the [[Pico LCD Hello World]] tutorial:
A5.write(0); // LCD GND
A7.write(1); // LCD VCC
A6.write(1); // TLCD backlight
var g; // Graphics
var term; // the terminal
function onInit() {
// Setup SPI for LCD
var spi = new SPI();
spi.setup({ sck:B1, mosi:B10 });
// Initialise the LCD
g = require("PCD8544").connect(spi,B13,B14,B15, function() {
// LCD initialised...
// Set up the terminal
term = require("VT100").connect(g, {
charWidth : 4,
charHeight : 8
});
// take characters from Espruino, and push them into the VT100 terminal
LoopbackB.on('data',function(e){
// USB.write(e); // optionally mirror back to the PC
// Send characters to the terminal
for (var i in e) term.char(e[i]);
// update the screen
g.flip();
});
// copy characters coming down USB into the 'loopback' device
USB.on('data',function(e){ LoopbackB.write(e); });
// Now move the console to Loopback
LoopbackA.setConsole();
});
}
You'll need to manually run onInit()
after uploading.
If you were to then add a keyboard to Espruino, you would have a complete computer!
- APPEND_JSDOC: VT100.js
- APPEND_USES: VT100