In order to use my GLCD + Arduino as a display for LCD4Linux, using the LCD4Linux SimpleLCD Driver which sends out a subset of VT100 codes (CR and LF).
I have managed to isolate the VT100 codes from regular text using the following code:
// include the library code:
#include <glcd.h>
// include the Fonts
#include <fonts/allFonts.h>
void setup() {
// Initialize the GLCD
GLCD.Init();
// Select the font for the default text area
GLCD.SelectFont(System5x7);
GLCD.ClearScreen();
GLCD.println("Please wait: "); // output using Print class
GLCD.println(" System initializing"); // output using Print class
// could also use gText string output routine
// GLCD.Puts("Listening...\n");
Serial.begin(9600);
}
void loop()
{
char c;
// when characters arrive over the serial port...
if (Serial.available())
{
// read character from serial library buffer
c = Serial.read();
switch(c)
{
case 27:
if(handleVT100Code())
{
GLCD.ClearScreen();
}
break;
default:
// display character on glcd
GLCD.write(c); // use Print class for output
break;
}
}
}
boolean handleVT100Code()
{
char c;
String vt100Code;
while(Serial.available())
{
c = Serial.read();
vt100Code.concat(c);
if(c == 'H')
{
break;
}
}
if(vt100Code != "")
{
return(true);
}
}
So for now it should only clear the screen when a VT100 code is detected (nasty, but to test things out). What happens, however, is that the VT100 codes get printed out anyway, probably because GLCD.ClearScreen()
takes up too much cpu time (?). When I don't use ClearScreen
, but simple println
the vt100Code
variable (which I return from handleVT100Code()
) the code gets printed (albeit with some false positives).
What would I have to do to make my program understand these two VT100 Codes (Carriage return and Line feed). I have done quite some searches for an out of the box implementation of a simple VT100 terminal, but there seem to be none. If there is some easier way of using the GLCD with LCD4Linux, you are more than welcome to tell me.