This is the same 4DGL-uLCD-SE library as what it's forked from with just an #ifndef statement.
Fork of 4DGL-uLCD-SE by
Revision 2:edae99e4abe7, committed 2013-11-17
- Comitter:
- 4180_1
- Date:
- Sun Nov 17 04:36:12 2013 +0000
- Parent:
- 1:8b656995301f
- Child:
- 3:9ba47197d94f
- Commit message:
- ver 1.01
Changed in this revision
--- a/uLCD_4DGL.h Mon Nov 11 01:22:41 2013 +0000 +++ b/uLCD_4DGL.h Sun Nov 17 04:36:12 2013 +0000 @@ -22,7 +22,7 @@ // Debug Verbose on terminal enabled #ifndef DEBUGMODE -#define DEBUGMODE 1 +#define DEBUGMODE 0 #endif // Common WAIT value in millisecond @@ -34,6 +34,7 @@ #define BAUDRATE '\x0B' //null prefix #define VERSION '\x08' //null prefix #define BCKGDCOLOR '\x6E' +#define TXTBCKGDCOLOR '\x7E' #define DISPCONTROL '\x68' #define SETVOLUME '\x76' #define CIRCLE '\xCC' @@ -44,9 +45,11 @@ #define PIXEL '\xCB' #define READPIXEL '\xCA' #define SCREENCOPY '\x63' //na? -#define PENSIZE '\x70' //na +#define PENSIZE '\xD8' #define SETFONT '\x7D' #define TEXTMODE '\x77' +#define TEXTWIDTH '\x7C' +#define TEXTHEIGHT '\x7B' #define TEXTCHAR '\xFE' #define GRAPHCHAR '\x74' #define TEXTSTRING '\x06' //null prefix @@ -55,6 +58,7 @@ #define GETTOUCH '\x6F' #define WAITTOUCH '\x77' #define SETTOUCH '\x75' +#define PUTCHAR '\xFE' // Screen answers @@ -74,7 +78,8 @@ #define OPAQUE '\x01' // Fonts Sizes -#define FONT_5X7 '\x00' +#define FONT_7X8 '\x00' //only builtin font +#define FONT_5X7 '\x04' #define FONT_8X8 '\x01' #define FONT_8X12 '\x02' #define FONT_12X16 '\x03' @@ -170,7 +175,7 @@ * @endcode */ -class uLCD_4DGL +class uLCD_4DGL : public Stream { public : @@ -201,6 +206,12 @@ * @param mode See 4DGL documentation * @param value See 4DGL documentation */ + void textbackground_color(int color); + + /** Set screen display mode to specific values + * @param mode See 4DGL documentation + * @param value See 4DGL documentation + */ void display_control(char mode, char value); /** Set internal speaker to specified value @@ -230,6 +241,8 @@ // Texts Commands void set_font(char); void text_mode(char); + void text_width(char); + void text_height(char); void text_char(char, char, char, int); void graphic_char(char, int, int, int, char, char); void text_string(char *, char, char, char, int); @@ -241,6 +254,8 @@ void putc(char); void puts(char *); + + // Touch Command void touch_mode(char); void get_touch(int *, int *); @@ -263,11 +278,24 @@ char current_orientation; char max_col; char max_row; + int current_w, current_h; + int current_fx, current_fy; + int current_wf, current_hf; + protected : Serial _cmd; DigitalOut _rst; + //used by printf + virtual int _putc(int c) { + putc(c); + return 0; + }; + virtual int _getc() { + return 0; + } + void freeBUFFER (void); void writeBYTE (char); @@ -285,3 +313,4 @@ typedef unsigned char BYTE; +
--- a/uLCD_4DGL_Text.cpp Mon Nov 11 01:22:41 2013 +0000 +++ b/uLCD_4DGL_Text.cpp Sun Nov 17 04:36:12 2013 +0000 @@ -24,8 +24,6 @@ { char command[3]= ""; - int w, h, fx = 8, fy = 8; - command[0] = SETFONT; command[1] = 0; command[2] = mode; @@ -33,34 +31,38 @@ current_font = mode; if (current_orientation == IS_PORTRAIT) { - w = SIZE_X; - h = SIZE_Y; + current_w = SIZE_X; + current_h = SIZE_Y; } else { - w = SIZE_Y; - h = SIZE_X; + current_w = SIZE_Y; + current_h = SIZE_X; } switch (mode) { case FONT_5X7 : - fx = 6; - fy = 8; + current_fx = 6; + current_fy = 8; + break; + case FONT_7X8 : + current_fx = 7; + current_fy = 8; break; case FONT_8X8 : - fx = 8; - fy = 8; + current_fx = 8; + current_fy = 8; break; case FONT_8X12 : - fx = 8; - fy = 12; + current_fx = 8; + current_fy = 12; break; case FONT_12X16 : - fx = 12; - fy = 16; + current_fx = 12; + current_fy = 16; break; } - max_col = w / fx; - max_row = h / fy; + max_col = current_w / (current_fx*current_wf); + max_row = current_h / (current_fy*current_hf); writeCOMMAND(command, 3); } @@ -78,6 +80,33 @@ } //**************************************************************************************************** +void uLCD_4DGL :: text_width(char width) // set text width +{ + char command[3]= ""; + + command[0] = TEXTWIDTH; + command[1] = 0; + command[2] = width; + current_wf = width; + max_col = current_w / (current_fx*current_wf); + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** +void uLCD_4DGL :: text_height(char height) // set text height +{ + char command[3]= ""; + + command[0] = TEXTHEIGHT; + command[1] = 0; + command[2] = height; + current_hf = height; + max_row = current_h / (current_fy*current_hf); + writeCOMMAND(command, 3); +} + + +//**************************************************************************************************** void uLCD_4DGL :: text_char(char c, char col, char row, int color) // draw a text char { char command[6]= ""; @@ -250,31 +279,76 @@ //**************************************************************************************************** void uLCD_4DGL :: locate(char col, char row) // place text curssor at col, row { + char command[5] = ""; current_col = col; current_row = row; + command[0] = 0xE4; //move cursor + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); } //**************************************************************************************************** void uLCD_4DGL :: color(int color) // set text color { + char command[5] = ""; current_color = color; + command[0] = 0x7F; //set color + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + writeCOMMAND(command, 3); } //**************************************************************************************************** -void uLCD_4DGL :: putc(char c) // place char at current cursor position +void uLCD_4DGL :: putc(char c) // place char at current cursor position +//used by virtual printf function _putc { + char command[6] =""; - text_char(c, current_col++, current_row, current_color); - + if(c=='\n') { + current_col = 0; + current_row++; + command[0] = 0xE4; //move cursor to start of next line + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); + } else { + command[0] = PUTCHAR; + command[1] = 0x00; + command[2] = c; + writeCOMMAND(command,3); + } if (current_col == max_col) { current_col = 0; current_row++; + command[0] = 0xE4; //move cursor to next line + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); } if (current_row == max_row) { current_row = 0; + command[0] = 0xE4; //move cursor back to start + command[1] = 0; + command[2] = current_row; + command[3] = 0; + command[4] = current_col; + writeCOMMAND(command, 5); } } + //**************************************************************************************************** void uLCD_4DGL :: puts(char *s) // place string at current cursor position {
--- a/uLCD_4DGL_main.cpp Mon Nov 11 01:22:41 2013 +0000 +++ b/uLCD_4DGL_main.cpp Sun Nov 17 04:36:12 2013 +0000 @@ -1,5 +1,5 @@ // -// uLCD_4DGL is a class to drive 4D Systems TFT touch screens +// uLCD_4DGL is a class to drive 4D Systems uLCD 144 G2 // // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> // @@ -53,8 +53,9 @@ current_row = 0; // initial cursor row current_color = WHITE; // initial text color current_orientation = IS_PORTRAIT; // initial screen orientation - - set_font(FONT_5X7); // initial font + current_hf = 1; + current_wf = 1; + set_font(FONT_7X8); // initial font // text_mode(OPAQUE); // initial texr mode } @@ -132,7 +133,7 @@ #endif int i, resp = 0; freeBUFFER(); - writeBYTE(0x00); + writeBYTE(0x00); //command has a null prefix byte for (i = 0; i < number; i++) writeBYTE(command[i]); // send command to serial port while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer @@ -172,6 +173,9 @@ command[0] = CLS; writeCOMMAND(command, 1); + current_hf = 1; + current_wf = 1; + set_font(FONT_7X8); // initial font } //************************************************************************** @@ -322,6 +326,23 @@ } //**************************************************************************************************** +void uLCD_4DGL :: textbackground_color(int color) // set screen background color +{ + char command[3]= ""; // input color is in 24bits like 0xRRGGBB + + command[0] = TXTBCKGDCOLOR; + + int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits + int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits + int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 3); +} + +//**************************************************************************************************** void uLCD_4DGL :: display_control(char mode, char value) // set screen mode to value { char command[3]= ""; @@ -440,4 +461,4 @@ #endif return resp; -} \ No newline at end of file +}