This is a library for 4DGL screens from 4D Systems in Autralia (http://www.4dsystems.com.au). Most graphic, touch and text functions are supported
Fork of 4DGL by
Revision 9:4b25d5413a06, committed 2012-10-11
- Comitter:
- lucoby
- Date:
- Thu Oct 11 18:54:20 2012 +0000
- Parent:
- 8:b95348b8030e
- Commit message:
- n/a
Changed in this revision
--- a/TFT_4DGL.h Sun Oct 17 10:26:10 2010 +0000 +++ b/TFT_4DGL.h Thu Oct 11 18:54:20 2012 +0000 @@ -1,280 +1,280 @@ -// -// TFT_4DGL is a class to drive 4D Systems TFT touch screens -// -// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> -// -// TFT_4DGL 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. -// -// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. - -// @author Stephane Rochon - -#include "mbed.h" - -// Debug Verbose on terminal enabled -#ifndef DEBUGMODE -#define DEBUGMODE 1 -#endif - -// Common WAIT value in millisecond -#define TEMPO 5 - -// 4DGL Functions values -#define AUTOBAUD '\x55' -#define CLS '\x45' -#define BAUDRATE '\x51' -#define VERSION '\x56' -#define BCKGDCOLOR '\x42' -#define DISPCONTROL '\x59' -#define SETVOLUME '\x76' -#define CIRCLE '\x43' -#define TRIANGLE '\x47' -#define LINE '\x4C' -#define RECTANGLE '\x72' -#define ELLIPSE '\x65' -#define PIXEL '\x50' -#define READPIXEL '\x52' -#define SCREENCOPY '\x63' -#define PENSIZE '\x70' -#define SETFONT '\x46' -#define TEXTMODE '\x4F' -#define TEXTCHAR '\x54' -#define GRAPHCHAR '\x74' -#define TEXTSTRING '\x73' -#define GRAPHSTRING '\x53' -#define TEXTBUTTON '\x62' -#define GETTOUCH '\x6F' -#define WAITTOUCH '\x77' -#define SETTOUCH '\x75' - - -// Screen answers -#define ACK '\x06' -#define NAK '\x15' - -// Screen states -#define OFF '\x00' -#define ON '\x01' - -// Graphics modes -#define SOLID '\x00' -#define WIREFRAME '\x01' - -// Text modes -#define TRANSPARENT '\x00' -#define OPAQUE '\x01' - -// Fonts Sizes -#define FONT_5X7 '\x00' -#define FONT_8X8 '\x01' -#define FONT_8X12 '\x02' -#define FONT_12X16 '\x03' - -// Touch Values -#define WAIT '\x00' -#define PRESS '\x01' -#define RELEASE '\x02' -#define MOVE '\x03' -#define STATUS '\x04' -#define GETPOSITION '\x05' - -// Data speed -#define BAUD_110 '\x00' -#define BAUD_300 '\x01' -#define BAUD_600 '\x02' -#define BAUD_1200 '\x03' -#define BAUD_2400 '\x04' -#define BAUD_4800 '\x05' -#define BAUD_9600 '\x06' -#define BAUD_14400 '\x07' -#define BAUD_19200 '\x09' -#define BAUD_31250 '\x09' -#define BAUD_38400 '\x0A' -#define BAUD_56000 '\x0B' -#define BAUD_57600 '\x0C' -#define BAUD_115200 '\x0D' -#define BAUD_128000 '\x0E' -#define BAUD_256000 '\x0F' - -// Defined Colors -#define WHITE 0xFFFFFF -#define BLACK 0x000000 -#define RED 0xFF0000 -#define GREEN 0x00FF00 -#define BLUE 0x0000FF -#define LGREY 0xBFBFBF -#define DGREY 0x5F5F5F - -// Mode data -#define BACKLIGHT '\x00' -#define DISPLAY '\x01' -#define CONTRAST '\x02' -#define POWER '\x03' -#define ORIENTATION '\x04' -#define TOUCH_CTRL '\x05' -#define IMAGE_FORMAT '\x06' -#define PROTECT_FAT '\x08' - -// change this to your specific screen (newer versions) if needed -// Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y -#define SIZE_X 240 -#define SIZE_Y 320 - -#define IS_LANDSCAPE 0 -#define IS_PORTRAIT 1 - -// Screen orientation -#define LANDSCAPE '\x01' -#define LANDSCAPE_R '\x02' -#define PORTRAIT '\x03' -#define PORTRAIT_R '\x04' - -// Parameters -#define ENABLE '\x00' -#define DISABLE '\x01' -#define RESET '\x02' - -#define NEW '\x00' -#define OLD '\x01' - -#define DOWN '\x00' -#define UP '\x01' - -#define PROTECT '\x00' -#define UNPROTECT '\x02' - -//************************************************************************** -// \class TFT_4DGL TFT_4DGL.h -// \brief This is the main class. It shoud be used like this : TFT_4GDL myLCD(p9,p10,p11); -/** -Example: -* @code -* // Display a white circle on the screen -* #include "mbed.h" -* #include " TFT_4DGL.h" -* -* TFT_4GDL myLCD(p9,p10,p11); -* -* int main() { -* myLCD.circle(120, 160, 80, WHITE); -* } -* @endcode -*/ - -class TFT_4DGL { - -public : - - TFT_4DGL(PinName tx, PinName rx, PinName rst); - -// General Commands ******************************************************************************* - -/** Clear the entire screen using the current background colour */ - void cls(); - -/** Reset screen */ - void reset(); - -/** Launch Autobaud for serial communication. This function is automatically called at startup */ - void autobaud(); -/** Set serial Baud rate (both sides : screen and mbed) -* @param Speed Correct BAUD value (see TFT_4DGL.h) -*/ - void baudrate(int speed); - -/** Set background colour to the specified value -* @param color in HEX RGB like 0xFF00FF -*/ - void background_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 -* @param value Correct range is 8 - 127 -*/ - void set_volume(char value); - -// Graphics Commands ******************************************************************************* - -/** Draw a circle centered at x,y with a radius and a colour. It uses Pen Size stored value to draw a solid or wireframe circle -* @param x Horizontal position of the circle centre -* @param y Vertical position of the circle centre -* @param radius Radius of the circle -* @param color Circle color in HEX RGB like 0xFF00FF -*/ - void circle(int x , int y , int radius, int color); - - void triangle(int, int, int, int, int, int, int); - void line(int, int, int, int, int); - void rectangle(int, int, int, int, int); - void ellipse(int, int, int, int, int); - void pixel(int, int, int); - int read_pixel(int, int); - void screen_copy(int, int, int, int, int, int); - void pen_size(char); - -// Texts Commands - void set_font(char); - void text_mode(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); - void graphic_string(char *, int, int, char, int, char, char); - void text_button(char *, char, int, int, int, char, int, char, char); - - void locate(char, char); - void color(int); - void putc(char); - void puts(char *); - -// Touch Command - void touch_mode(char); - void get_touch(int *, int *); - void wait_touch(int); - void set_touch(int, int, int, int); - int touch_status(void); - -// Screen Data - int type; - int revision; - int firmware; - int reserved1; - int reserved2; - -// Text data - char current_col; - char current_row; - int current_color; - char current_font; - char current_orientation; - char max_col; - char max_row; - -protected : - - Serial _cmd; - DigitalOut _rst; - - void freeBUFFER (void); - void writeBYTE (char); - int writeCOMMAND(char *, int); - int readVERSION (char *, int); - void getTOUCH (char *, int, int *,int *); - int getSTATUS (char *, int); - void version (void); -}; - +// +// TFT_4DGL is a class to drive 4D Systems TFT touch screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// +// TFT_4DGL 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. +// +// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. + +// @author Stephane Rochon + +#include "mbed.h" + +// Debug Verbose on terminal enabled +#ifndef DEBUGMODE +#define DEBUGMODE 0 +#endif + +// Common WAIT value in millisecond +#define TEMPO 5 + +// 4DGL Functions values +#define AUTOBAUD '\x55' +#define CLS '\x45' +#define BAUDRATE '\x51' +#define VERSION '\x56' +#define BCKGDCOLOR '\x42' +#define DISPCONTROL '\x59' +#define SETVOLUME '\x76' +#define CIRCLE '\x43' +#define TRIANGLE '\x47' +#define LINE '\x4C' +#define RECTANGLE '\x72' +#define ELLIPSE '\x65' +#define PIXEL '\x50' +#define READPIXEL '\x52' +#define SCREENCOPY '\x63' +#define PENSIZE '\x70' +#define SETFONT '\x46' +#define TEXTMODE '\x4F' +#define TEXTCHAR '\x54' +#define GRAPHCHAR '\x74' +#define TEXTSTRING '\x73' +#define GRAPHSTRING '\x53' +#define TEXTBUTTON '\x62' +#define GETTOUCH '\x6F' +#define WAITTOUCH '\x77' +#define SETTOUCH '\x75' + + +// Screen answers +#define ACK '\x06' +#define NAK '\x15' + +// Screen states +#define OFF '\x00' +#define ON '\x01' + +// Graphics modes +#define SOLID '\x00' +#define WIREFRAME '\x01' + +// Text modes +#define TRANSPARENT '\x00' +#define OPAQUE '\x01' + +// Fonts Sizes +#define FONT_5X7 '\x00' +#define FONT_8X8 '\x01' +#define FONT_8X12 '\x02' +#define FONT_12X16 '\x03' + +// Touch Values +#define WAIT '\x00' +#define PRESS '\x01' +#define RELEASE '\x02' +#define MOVE '\x03' +#define STATUS '\x04' +#define GETPOSITION '\x05' + +// Data speed +#define BAUD_110 '\x00' +#define BAUD_300 '\x01' +#define BAUD_600 '\x02' +#define BAUD_1200 '\x03' +#define BAUD_2400 '\x04' +#define BAUD_4800 '\x05' +#define BAUD_9600 '\x06' +#define BAUD_14400 '\x07' +#define BAUD_19200 '\x09' +#define BAUD_31250 '\x09' +#define BAUD_38400 '\x0A' +#define BAUD_56000 '\x0B' +#define BAUD_57600 '\x0C' +#define BAUD_115200 '\x0D' +#define BAUD_128000 '\x0E' +#define BAUD_256000 '\x0F' + +// Defined Colors +#define WHITE 0xFFFFFF +#define BLACK 0x000000 +#define RED 0xFF0000 +#define GREEN 0x00FF00 +#define BLUE 0x0000FF +#define LGREY 0xBFBFBF +#define DGREY 0x5F5F5F + +// Mode data +#define BACKLIGHT '\x00' +#define DISPLAY '\x01' +#define CONTRAST '\x02' +#define POWER '\x03' +#define ORIENTATION '\x04' +#define TOUCH_CTRL '\x05' +#define IMAGE_FORMAT '\x06' +#define PROTECT_FAT '\x08' + +// change this to your specific screen (newer versions) if needed +// Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y +#define SIZE_X 240 +#define SIZE_Y 320 + +#define IS_LANDSCAPE 0 +#define IS_PORTRAIT 1 + +// Screen orientation +#define LANDSCAPE '\x01' +#define LANDSCAPE_R '\x02' +#define PORTRAIT '\x03' +#define PORTRAIT_R '\x04' + +// Parameters +#define ENABLE '\x00' +#define DISABLE '\x01' +#define RESET '\x02' + +#define NEW '\x00' +#define OLD '\x01' + +#define DOWN '\x00' +#define UP '\x01' + +#define PROTECT '\x00' +#define UNPROTECT '\x02' + +//************************************************************************** +// \class TFT_4DGL TFT_4DGL.h +// \brief This is the main class. It shoud be used like this : TFT_4GDL myLCD(p9,p10,p11); +/** +Example: +* @code +* // Display a white circle on the screen +* #include "mbed.h" +* #include " TFT_4DGL.h" +* +* TFT_4GDL myLCD(p9,p10,p11); +* +* int main() { +* myLCD.circle(120, 160, 80, WHITE); +* } +* @endcode +*/ + +class TFT_4DGL { + +public : + + TFT_4DGL(PinName tx, PinName rx, PinName rst); + +// General Commands ******************************************************************************* + +/** Clear the entire screen using the current background colour */ + void cls(); + +/** Reset screen */ + void reset(); + +/** Launch Autobaud for serial communication. This function is automatically called at startup */ + void autobaud(); +/** Set serial Baud rate (both sides : screen and mbed) +* @param Speed Correct BAUD value (see TFT_4DGL.h) +*/ + void baudrate(int speed); + +/** Set background colour to the specified value +* @param color in HEX RGB like 0xFF00FF +*/ + void background_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 +* @param value Correct range is 8 - 127 +*/ + void set_volume(char value); + +// Graphics Commands ******************************************************************************* + +/** Draw a circle centered at x,y with a radius and a colour. It uses Pen Size stored value to draw a solid or wireframe circle +* @param x Horizontal position of the circle centre +* @param y Vertical position of the circle centre +* @param radius Radius of the circle +* @param color Circle color in HEX RGB like 0xFF00FF +*/ + void circle(int x , int y , int radius, int color); + + void triangle(int, int, int, int, int, int, int); + void line(int, int, int, int, int); + void rectangle(int, int, int, int, int); + void ellipse(int, int, int, int, int); + void pixel(int, int, int); + int read_pixel(int, int); + void screen_copy(int, int, int, int, int, int); + void pen_size(char); + +// Texts Commands + void set_font(char); + void text_mode(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); + void graphic_string(char *, int, int, char, int, char, char); + void text_button(char *, char, int, int, int, char, int, char, char); + + void locate(char, char); + void color(int); + void putc(char); + void puts(char *); + +// Touch Command + void touch_mode(char); + void get_touch(int *, int *); + void wait_touch(int); + void set_touch(int, int, int, int); + int touch_status(void); + +// Screen Data + int type; + int revision; + int firmware; + int reserved1; + int reserved2; + +// Text data + char current_col; + char current_row; + int current_color; + char current_font; + char current_orientation; + char max_col; + char max_row; + +protected : + + Serial _cmd; + DigitalOut _rst; + + void freeBUFFER (void); + void writeBYTE (char); + int writeCOMMAND(char *, int); + int readVERSION (char *, int); + void getTOUCH (char *, int, int *,int *); + int getSTATUS (char *, int); + void version (void); +}; + typedef unsigned char BYTE; \ No newline at end of file
--- a/TFT_4DGL_Graphics.cpp Sun Oct 17 10:26:10 2010 +0000 +++ b/TFT_4DGL_Graphics.cpp Thu Oct 11 18:54:20 2012 +0000 @@ -1,258 +1,258 @@ -// -// TFT_4DGL is a class to drive 4D Systems TFT touch screens -// -// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> -// -// TFT_4DGL 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. -// -// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. - -#include "mbed.h" -#include "TFT_4DGL.h" - - -//**************************************************************************************************** -void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y) - char command[9]= ""; - - command[0] = CIRCLE; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - - command[5] = (radius >> 8) & 0xFF; - command[6] = radius & 0xFF; - - 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[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 9); -} - -//**************************************************************************************************** -void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle - char command[15]= ""; - - command[0] = TRIANGLE; - - command[1] = (x1 >> 8) & 0xFF; - command[2] = x1 & 0xFF; - - command[3] = (y1 >> 8) & 0xFF; - command[4] = y1 & 0xFF; - - command[5] = (x2 >> 8) & 0xFF; - command[6] = x2 & 0xFF; - - command[7] = (y2 >> 8) & 0xFF; - command[8] = y2 & 0xFF; - - command[9] = (x3 >> 8) & 0xFF; - command[10] = x3 & 0xFF; - - command[11] = (y3 >> 8) & 0xFF; - command[12] = y3 & 0xFF; - - 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[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 15); -} - -//**************************************************************************************************** -void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line - char command[11]= ""; - - command[0] = LINE; - - command[1] = (x1 >> 8) & 0xFF; - command[2] = x1 & 0xFF; - - command[3] = (y1 >> 8) & 0xFF; - command[4] = y1 & 0xFF; - - command[5] = (x2 >> 8) & 0xFF; - command[6] = x2 & 0xFF; - - command[7] = (y2 >> 8) & 0xFF; - command[8] = y2 & 0xFF; - - 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[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 11); -} - -//**************************************************************************************************** -void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle - char command[11]= ""; - - command[0] = RECTANGLE; - - command[1] = (x1 >> 8) & 0xFF; - command[2] = x1 & 0xFF; - - command[3] = (y1 >> 8) & 0xFF; - command[4] = y1 & 0xFF; - - command[5] = (x2 >> 8) & 0xFF; - command[6] = x2 & 0xFF; - - command[7] = (y2 >> 8) & 0xFF; - command[8] = y2 & 0xFF; - - 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[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 11); -} - -//**************************************************************************************************** -void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse - char command[11]= ""; - - command[0] = ELLIPSE; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - - command[5] = (radius_x >> 8) & 0xFF; - command[6] = radius_x & 0xFF; - - command[7] = (radius_y >> 8) & 0xFF; - command[8] = radius_y & 0xFF; - - 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[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 11); -} - -//**************************************************************************************************** -void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel - char command[7]= ""; - - command[0] = PIXEL; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - - 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[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 7); -} - -//****************************************************************************************************** -int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data - - char command[5]= ""; - - command[0] = READPIXEL; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - - int i, temp = 0, color = 0, resp = 0; - char response[2] = ""; - - freeBUFFER(); - - for (i = 0; i < 5; i++) { // send all chars to serial port - writeBYTE(command[i]); - } - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - while (_cmd.readable()) { - temp = _cmd.getc(); - response[resp++] = (char)temp; - } - - color = ((response[0] << 8) + response[1]); - - return color; // WARNING : this is 16bits color, not 24bits... need to be fixed -} - -//****************************************************************************************************** -void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) { - - char command[13]= ""; - - command[0] = SCREENCOPY; - - command[1] = (xs >> 8) & 0xFF; - command[2] = xs & 0xFF; - - command[3] = (ys >> 8) & 0xFF; - command[4] = ys & 0xFF; - - command[5] = (xd >> 8) & 0xFF; - command[6] = xd & 0xFF; - - command[7] = (yd >> 8) & 0xFF; - command[8] = yd & 0xFF; - - command[9] = (width >> 8) & 0xFF; - command[10] = width & 0xFF; - - command[11] = (height >> 8) & 0xFF; - command[12] = height & 0xFF; - - writeCOMMAND(command, 13); -} - -//**************************************************************************************************** -void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME - char command[2]= ""; - - command[0] = PENSIZE; - command[1] = mode; - - writeCOMMAND(command, 2); +// +// TFT_4DGL is a class to drive 4D Systems TFT touch screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// +// TFT_4DGL 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. +// +// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "TFT_4DGL.h" + + +//**************************************************************************************************** +void TFT_4DGL :: circle(int x, int y , int radius, int color) { // draw a circle in (x,y) + char command[9]= ""; + + command[0] = CIRCLE; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + command[5] = (radius >> 8) & 0xFF; + command[6] = radius & 0xFF; + + 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[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 9); +} + +//**************************************************************************************************** +void TFT_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) { // draw a traingle + char command[15]= ""; + + command[0] = TRIANGLE; + + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; + + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; + + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; + + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; + + command[9] = (x3 >> 8) & 0xFF; + command[10] = x3 & 0xFF; + + command[11] = (y3 >> 8) & 0xFF; + command[12] = y3 & 0xFF; + + 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[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 15); +} + +//**************************************************************************************************** +void TFT_4DGL :: line(int x1, int y1 , int x2, int y2, int color) { // draw a line + char command[11]= ""; + + command[0] = LINE; + + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; + + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; + + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; + + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; + + 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[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 11); +} + +//**************************************************************************************************** +void TFT_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) { // draw a rectangle + char command[11]= ""; + + command[0] = RECTANGLE; + + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; + + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; + + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; + + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; + + 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[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 11); +} + +//**************************************************************************************************** +void TFT_4DGL :: ellipse(int x, int y , int radius_x, int radius_y, int color) { // draw an ellipse + char command[11]= ""; + + command[0] = ELLIPSE; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + command[5] = (radius_x >> 8) & 0xFF; + command[6] = radius_x & 0xFF; + + command[7] = (radius_y >> 8) & 0xFF; + command[8] = radius_y & 0xFF; + + 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[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 11); +} + +//**************************************************************************************************** +void TFT_4DGL :: pixel(int x, int y, int color) { // draw a pixel + char command[7]= ""; + + command[0] = PIXEL; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + 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[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 7); +} + +//****************************************************************************************************** +int TFT_4DGL :: read_pixel(int x, int y) { // read screen info and populate data + + char command[5]= ""; + + command[0] = READPIXEL; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + int i, temp = 0, color = 0, resp = 0; + char response[2] = ""; + + freeBUFFER(); + + for (i = 0; i < 5; i++) { // send all chars to serial port + writeBYTE(command[i]); + } + + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + + while (_cmd.readable()) { + temp = _cmd.getc(); + response[resp++] = (char)temp; + } + + color = ((response[0] << 8) + response[1]); + + return color; // WARNING : this is 16bits color, not 24bits... need to be fixed +} + +//****************************************************************************************************** +void TFT_4DGL :: screen_copy(int xs, int ys , int xd, int yd , int width, int height) { + + char command[13]= ""; + + command[0] = SCREENCOPY; + + command[1] = (xs >> 8) & 0xFF; + command[2] = xs & 0xFF; + + command[3] = (ys >> 8) & 0xFF; + command[4] = ys & 0xFF; + + command[5] = (xd >> 8) & 0xFF; + command[6] = xd & 0xFF; + + command[7] = (yd >> 8) & 0xFF; + command[8] = yd & 0xFF; + + command[9] = (width >> 8) & 0xFF; + command[10] = width & 0xFF; + + command[11] = (height >> 8) & 0xFF; + command[12] = height & 0xFF; + + writeCOMMAND(command, 13); +} + +//**************************************************************************************************** +void TFT_4DGL :: pen_size(char mode) { // set pen to SOLID or WIREFRAME + char command[2]= ""; + + command[0] = PENSIZE; + command[1] = mode; + + writeCOMMAND(command, 2); } \ No newline at end of file
--- a/TFT_4DGL_Text.cpp Sun Oct 17 10:26:10 2010 +0000 +++ b/TFT_4DGL_Text.cpp Thu Oct 11 18:54:20 2012 +0000 @@ -1,270 +1,270 @@ -// -// TFT_4DGL is a class to drive 4D Systems TFT touch screens -// -// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> -// -// TFT_4DGL 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. -// -// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. - -#include "mbed.h" -#include "TFT_4DGL.h" - -//**************************************************************************************************** -void TFT_4DGL :: set_font(char mode) { // set font size - char command[2]= ""; - - int w, h, fx = 8, fy = 8; - - command[0] = SETFONT; - command[1] = mode; - - current_font = mode; - - if (current_orientation == IS_PORTRAIT) { - w = SIZE_X; - h = SIZE_Y; - } else { - w = SIZE_Y; - h = SIZE_X; - } - - switch (mode) { - case FONT_5X7 : - fx = 6; - fy = 8; - break; - case FONT_8X8 : - fx = 8; - fy = 8; - break; - case FONT_8X12 : - fx = 8; - fy = 12; - break; - case FONT_12X16 : - fx = 12; - fy = 16; - break; - } - - max_col = w / fx; - max_row = h / fy; - - writeCOMMAND(command, 2); -} - -//**************************************************************************************************** -void TFT_4DGL :: text_mode(char mode) { // set text mode - char command[2]= ""; - - command[0] = TEXTMODE; - command[1] = mode; - - writeCOMMAND(command, 2); -} - -//**************************************************************************************************** -void TFT_4DGL :: text_char(char c, char col, char row, int color) { // draw a text char - char command[6]= ""; - - command[0] = TEXTCHAR; - - command[1] = c; - command[2] = col; - command[3] = row; - - 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[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - writeCOMMAND(command, 8); -} - -//**************************************************************************************************** -void TFT_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height) { // draw a graphic char - char command[10]= ""; - - command[0] = GRAPHCHAR; - - command[1] = c; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - 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[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - command[8] = width; - - command[9] = height; - - writeCOMMAND(command, 10); -} - -//**************************************************************************************************** -void TFT_4DGL :: text_string(char *s, char col, char row, char font, int color) { // draw a text string - - char command[1000]= ""; - int size = strlen(s); - int i = 0; - - command[0] = TEXTSTRING; - - command[1] = col; - command[2] = row; - - command[3] = font; - - 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[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - for (i=0; i<size; i++) command[6+i] = s[i]; - - command[6+size] = 0; - - writeCOMMAND(command, 7 + size); -} - -//**************************************************************************************************** -void TFT_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height) { // draw a text string - - char command[1000]= ""; - int size = strlen(s); - int i = 0; - - command[0] = GRAPHSTRING; - - command[1] = (x >> 8) & 0xFF; - command[2] = x & 0xFF; - - command[3] = (y >> 8) & 0xFF; - command[4] = y & 0xFF; - - command[5] = font; - - 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[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - command[8] = width; - - command[9] = height; - - for (i=0; i<size; i++) command[10+i] = s[i]; - - command[10+size] = 0; - - writeCOMMAND(command, 11 + size); -} - -//**************************************************************************************************** -void TFT_4DGL :: text_button(char *s, char mode, int x, int y, int button_color, char font, int text_color, char width, char height) { // draw a text string - - char command[1000]= ""; - int size = strlen(s); - int i = 0, red5, green6, blue5; - - command[0] = TEXTBUTTON; - - command[1] = mode; - - command[2] = (x >> 8) & 0xFF; - command[3] = x & 0xFF; - - command[4] = (y >> 8) & 0xFF; - command[5] = y & 0xFF; - - red5 = (button_color >> (16 + 3)) & 0x1F; // get red on 5 bits - green6 = (button_color >> (8 + 2)) & 0x3F; // get green on 6 bits - blue5 = (button_color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - command[8] = font; - - red5 = (text_color >> (16 + 3)) & 0x1F; // get red on 5 bits - green6 = (text_color >> (8 + 2)) & 0x3F; // get green on 6 bits - blue5 = (text_color >> (0 + 3)) & 0x1F; // get blue on 5 bits - - command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color - command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color - - command[11] = width; - - command[12] = height; - - for (i=0; i<size; i++) command[13+i] = s[i]; - - command[13+size] = 0; - - writeCOMMAND(command, 14 + size); -} - -//**************************************************************************************************** -void TFT_4DGL :: locate(char col, char row) { // place text curssor at col, row - current_col = col; - current_row = row; -} - -//**************************************************************************************************** -void TFT_4DGL :: color(int color) { // set text color - current_color = color; -} - -//**************************************************************************************************** -void TFT_4DGL :: putc(char c) { // place char at current cursor position - - text_char(c, current_col++, current_row, current_color); - - if (current_col == max_col) { - current_col = 0; - current_row++; - } - if (current_row == max_row) { - current_row = 0; - } -} - -//**************************************************************************************************** -void TFT_4DGL :: puts(char *s) { // place string at current cursor position - - text_string(s, current_col, current_row, current_font, current_color); - - current_col += strlen(s); - - if (current_col >= max_col) { - current_row += current_col / max_col; - current_col %= max_col; - } - if (current_row >= max_row) { - current_row %= max_row; - } +// +// TFT_4DGL is a class to drive 4D Systems TFT touch screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// +// TFT_4DGL 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. +// +// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "TFT_4DGL.h" + +//**************************************************************************************************** +void TFT_4DGL :: set_font(char mode) { // set font size + char command[2]= ""; + + int w, h, fx = 8, fy = 8; + + command[0] = SETFONT; + command[1] = mode; + + current_font = mode; + + if (current_orientation == IS_PORTRAIT) { + w = SIZE_X; + h = SIZE_Y; + } else { + w = SIZE_Y; + h = SIZE_X; + } + + switch (mode) { + case FONT_5X7 : + fx = 6; + fy = 8; + break; + case FONT_8X8 : + fx = 8; + fy = 8; + break; + case FONT_8X12 : + fx = 8; + fy = 12; + break; + case FONT_12X16 : + fx = 12; + fy = 16; + break; + } + + max_col = w / fx; + max_row = h / fy; + + writeCOMMAND(command, 2); +} + +//**************************************************************************************************** +void TFT_4DGL :: text_mode(char mode) { // set text mode + char command[2]= ""; + + command[0] = TEXTMODE; + command[1] = mode; + + writeCOMMAND(command, 2); +} + +//**************************************************************************************************** +void TFT_4DGL :: text_char(char c, char col, char row, int color) { // draw a text char + char command[6]= ""; + + command[0] = TEXTCHAR; + + command[1] = c; + command[2] = col; + command[3] = row; + + 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[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + writeCOMMAND(command, 8); +} + +//**************************************************************************************************** +void TFT_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height) { // draw a graphic char + char command[10]= ""; + + command[0] = GRAPHCHAR; + + command[1] = c; + + command[2] = (x >> 8) & 0xFF; + command[3] = x & 0xFF; + + command[4] = (y >> 8) & 0xFF; + command[5] = y & 0xFF; + + 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[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + command[8] = width; + + command[9] = height; + + writeCOMMAND(command, 10); +} + +//**************************************************************************************************** +void TFT_4DGL :: text_string(char *s, char col, char row, char font, int color) { // draw a text string + + char command[1000]= ""; + int size = strlen(s); + int i = 0; + + command[0] = TEXTSTRING; + + command[1] = col; + command[2] = row; + + command[3] = font; + + 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[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + for (i=0; i<size; i++) command[6+i] = s[i]; + + command[6+size] = 0; + + writeCOMMAND(command, 7 + size); +} + +//**************************************************************************************************** +void TFT_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height) { // draw a text string + + char command[1000]= ""; + int size = strlen(s); + int i = 0; + + command[0] = GRAPHSTRING; + + command[1] = (x >> 8) & 0xFF; + command[2] = x & 0xFF; + + command[3] = (y >> 8) & 0xFF; + command[4] = y & 0xFF; + + command[5] = font; + + 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[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + command[8] = width; + + command[9] = height; + + for (i=0; i<size; i++) command[10+i] = s[i]; + + command[10+size] = 0; + + writeCOMMAND(command, 11 + size); +} + +//**************************************************************************************************** +void TFT_4DGL :: text_button(char *s, char mode, int x, int y, int button_color, char font, int text_color, char width, char height) { // draw a text string + + char command[1000]= ""; + int size = strlen(s); + int i = 0, red5, green6, blue5; + + command[0] = TEXTBUTTON; + + command[1] = mode; + + command[2] = (x >> 8) & 0xFF; + command[3] = x & 0xFF; + + command[4] = (y >> 8) & 0xFF; + command[5] = y & 0xFF; + + red5 = (button_color >> (16 + 3)) & 0x1F; // get red on 5 bits + green6 = (button_color >> (8 + 2)) & 0x3F; // get green on 6 bits + blue5 = (button_color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + command[8] = font; + + red5 = (text_color >> (16 + 3)) & 0x1F; // get red on 5 bits + green6 = (text_color >> (8 + 2)) & 0x3F; // get green on 6 bits + blue5 = (text_color >> (0 + 3)) & 0x1F; // get blue on 5 bits + + command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color + command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color + + command[11] = width; + + command[12] = height; + + for (i=0; i<size; i++) command[13+i] = s[i]; + + command[13+size] = 0; + + writeCOMMAND(command, 14 + size); +} + +//**************************************************************************************************** +void TFT_4DGL :: locate(char col, char row) { // place text curssor at col, row + current_col = col; + current_row = row; +} + +//**************************************************************************************************** +void TFT_4DGL :: color(int color) { // set text color + current_color = color; +} + +//**************************************************************************************************** +void TFT_4DGL :: putc(char c) { // place char at current cursor position + + text_char(c, current_col++, current_row, current_color); + + if (current_col == max_col) { + current_col = 0; + current_row++; + } + if (current_row == max_row) { + current_row = 0; + } +} + +//**************************************************************************************************** +void TFT_4DGL :: puts(char *s) { // place string at current cursor position + + text_string(s, current_col, current_row, current_font, current_color); + + current_col += strlen(s); + + if (current_col >= max_col) { + current_row += current_col / max_col; + current_col %= max_col; + } + if (current_row >= max_row) { + current_row %= max_row; + } } \ No newline at end of file
--- a/TFT_4DGL_Touch.cpp Sun Oct 17 10:26:10 2010 +0000 +++ b/TFT_4DGL_Touch.cpp Thu Oct 11 18:54:20 2012 +0000 @@ -1,89 +1,89 @@ -// -// TFT_4DGL is a class to drive 4D Systems TFT touch screens -// -// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> -// -// TFT_4DGL 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. -// -// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. - -#include "mbed.h" -#include "TFT_4DGL.h" - -//****************************************************************************************************** -void TFT_4DGL :: touch_mode(char mode) { // Send touch mode (WAIT, PRESS, RELEASE or MOVE) - - char command[2]= ""; - - command[0] = GETTOUCH; - command[1] = mode; - - writeCOMMAND(command, 2); -} - -//****************************************************************************************************** -void TFT_4DGL :: get_touch(int *x, int *y) { // Get the touch coordinates - - char command[2] = ""; - - command[0] = GETTOUCH; - command[1] = GETPOSITION; - - getTOUCH(command, 2, x, y); -} - -//****************************************************************************************************** -int TFT_4DGL :: touch_status(void) { // Get the touch screen status - - char command[2] = ""; - - command[0] = GETTOUCH; - command[1] = STATUS; - - return getSTATUS(command, 2); -} - - -//****************************************************************************************************** -void TFT_4DGL :: wait_touch(int delay) { // wait until touch within a delay in milliseconds - - char command[3]= ""; - - command[0] = WAITTOUCH; - - command[1] = (delay >> 8) & 0xFF; - command[2] = delay & 0xFF; - - writeCOMMAND(command, 3); -} - -//****************************************************************************************************** -void TFT_4DGL :: set_touch(int x1, int y1 , int x2, int y2) { // define touch area - - char command[9]= ""; - - command[0] = SETTOUCH; - - command[1] = (x1 >> 8) & 0xFF; - command[2] = x1 & 0xFF; - - command[3] = (y1 >> 8) & 0xFF; - command[4] = y1 & 0xFF; - - command[5] = (x2 >> 8) & 0xFF; - command[6] = x2 & 0xFF; - - command[7] = (y2 >> 8) & 0xFF; - command[8] = y2 & 0xFF; - - writeCOMMAND(command, 9); +// +// TFT_4DGL is a class to drive 4D Systems TFT touch screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// +// TFT_4DGL 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. +// +// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "TFT_4DGL.h" + +//****************************************************************************************************** +void TFT_4DGL :: touch_mode(char mode) { // Send touch mode (WAIT, PRESS, RELEASE or MOVE) + + char command[2]= ""; + + command[0] = GETTOUCH; + command[1] = mode; + + writeCOMMAND(command, 2); +} + +//****************************************************************************************************** +void TFT_4DGL :: get_touch(int *x, int *y) { // Get the touch coordinates + + char command[2] = ""; + + command[0] = GETTOUCH; + command[1] = GETPOSITION; + + getTOUCH(command, 2, x, y); +} + +//****************************************************************************************************** +int TFT_4DGL :: touch_status(void) { // Get the touch screen status + + char command[2] = ""; + + command[0] = GETTOUCH; + command[1] = STATUS; + + return getSTATUS(command, 2); +} + + +//****************************************************************************************************** +void TFT_4DGL :: wait_touch(int delay) { // wait until touch within a delay in milliseconds + + char command[3]= ""; + + command[0] = WAITTOUCH; + + command[1] = (delay >> 8) & 0xFF; + command[2] = delay & 0xFF; + + writeCOMMAND(command, 3); +} + +//****************************************************************************************************** +void TFT_4DGL :: set_touch(int x1, int y1 , int x2, int y2) { // define touch area + + char command[9]= ""; + + command[0] = SETTOUCH; + + command[1] = (x1 >> 8) & 0xFF; + command[2] = x1 & 0xFF; + + command[3] = (y1 >> 8) & 0xFF; + command[4] = y1 & 0xFF; + + command[5] = (x2 >> 8) & 0xFF; + command[6] = x2 & 0xFF; + + command[7] = (y2 >> 8) & 0xFF; + command[8] = y2 & 0xFF; + + writeCOMMAND(command, 9); } \ No newline at end of file
--- a/TFT_4DGL_main.cpp Sun Oct 17 10:26:10 2010 +0000 +++ b/TFT_4DGL_main.cpp Thu Oct 11 18:54:20 2012 +0000 @@ -1,380 +1,380 @@ -// -// TFT_4DGL is a class to drive 4D Systems TFT touch screens -// -// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> -// -// TFT_4DGL 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. -// -// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. - -#include "mbed.h" -#include "TFT_4DGL.h" - -Serial pc(USBTX,USBRX); - -//****************************************************************************************************** -TFT_4DGL :: TFT_4DGL(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx), _rst(rst) { // Constructor - -#if DEBUGMODE - pc.baud(115200); - - pc.printf("\n\n\n"); - pc.printf("********************\n"); - pc.printf("TFT_4DGL CONSTRUCTOR\n"); - pc.printf("********************\n"); -#endif - - _rst = 1; // put RESET pin to high to start TFT screen - - reset(); - autobaud(); // send autobaud command - version(); // get version information - cls(); // clear screen - - current_col = 0; // initial cursor col - 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 - text_mode(OPAQUE); // initial texr mode -} - -//****************************************************************************************************** -void TFT_4DGL :: writeBYTE(char c) { // send a BYTE command to screen - - _cmd.putc(c); - wait_ms(1); - -#if DEBUGMODE - pc.printf(" Char sent : 0x%02X\n",c); -#endif - -} - -//****************************************************************************************************** -void TFT_4DGL :: freeBUFFER(void) { // Clear serial buffer before writing command - - while (_cmd.readable()) _cmd.getc(); // clear buffer garbage -} - -//****************************************************************************************************** -int TFT_4DGL :: writeCOMMAND(char *command, int number) { // send several BYTES making a command and return an answer - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X\n", command[0]); -#endif - int i, resp = 0; - freeBUFFER(); - - for (i = 0; i < number; i++) writeBYTE(command[i]); // send command to serial port - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - if (_cmd.readable()) resp = _cmd.getc(); // read response if any - switch (resp) { - case ACK : // if OK return 1 - resp = 1; - break; - case NAK : // if NOK return -1 - resp = -1; - break; - default : - resp = 0; // else return 0 - break; - } -#if DEBUGMODE - pc.printf(" Answer received : %d\n",resp); -#endif - - return resp; -} - -//************************************************************************** -void TFT_4DGL :: reset() { // Reset Screen - - _rst = 0; // put RESET pin to low - wait_ms(TEMPO); // wait a few milliseconds for command reception - _rst = 1; // put RESET back to high - wait(3); // wait 3s for screen to restart - - freeBUFFER(); // clean buffer from possible garbage -} - -//************************************************************************** -void TFT_4DGL :: autobaud() { // send AutoBaud command (9600) - char command[1] = ""; - command[0] = AUTOBAUD; - writeCOMMAND(command, 1); -} - -//************************************************************************** -void TFT_4DGL :: cls() { // clear screen - char command[1] = ""; - command[0] = CLS; - writeCOMMAND(command, 1); -} - -//************************************************************************** -void TFT_4DGL :: version() { // get API version - char command[2] = ""; - command[0] = VERSION; - command[1] = OFF; - readVERSION(command, 2); -} - -//************************************************************************** -void TFT_4DGL :: baudrate(int speed) { // set screen baud rate - char command[2]= ""; - command[0] = BAUDRATE; - switch (speed) { - case 110 : - command[1] = BAUD_110; - break; - case 300 : - command[1] = BAUD_300; - break; - case 600 : - command[1] = BAUD_600; - break; - case 1200 : - command[1] = BAUD_1200; - break; - case 2400 : - command[1] = BAUD_2400; - break; - case 4800 : - command[1] = BAUD_4800; - break; - case 9600 : - command[1] = BAUD_9600; - break; - case 14400 : - command[1] = BAUD_14400; - break; - case 19200 : - command[1] = BAUD_19200; - break; - case 31250 : - command[1] = BAUD_31250; - break; - case 38400 : - command[1] = BAUD_38400; - break; - case 56000 : - command[1] = BAUD_56000; - break; - case 57600 : - command[1] = BAUD_57600; - break; - case 115200 : - command[1] = BAUD_115200; - break; - case 128000 : - command[1] = BAUD_128000; - break; - case 256000 : - command[1] = BAUD_256000; - break; - default : - command[1] = BAUD_9600; - speed = 9600; - break; - } - - int i, resp = 0; - - freeBUFFER(); - - for (i = 0; i <2; i++) writeBYTE(command[i]); // send command to serial port - _cmd.baud(speed); // set mbed to same speed - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - if (_cmd.readable()) resp = _cmd.getc(); // read response if any - switch (resp) { - case ACK : // if OK return 1 - resp = 1; - break; - case NAK : // if NOK return -1 - resp = -1; - break; - default : - resp = 0; // else return 0 - break; - } -} - -//****************************************************************************************************** -int TFT_4DGL :: readVERSION(char *command, int number) { // read screen info and populate data - - int i, temp = 0, resp = 0; - char response[5] = ""; - - freeBUFFER(); - - for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - while (_cmd.readable()) { - temp = _cmd.getc(); - response[resp++] = (char)temp; - } - switch (resp) { - case 5 : // if OK populate data and return 1 - type = response[0]; - revision = response[1]; - firmware = response[2]; - reserved1 = response[3]; - reserved2 = response[4]; - resp = 1; - break; - default : - resp = 0; // else return 0 - break; - } - return resp; -} - -//**************************************************************************************************** -void TFT_4DGL :: background_color(int color) { // set screen background color - char command[3]= ""; // input color is in 24bits like 0xRRGGBB - - command[0] = BCKGDCOLOR; - - 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 TFT_4DGL :: display_control(char mode, char value) { // set screen mode to value - char command[3]= ""; - - command[0] = DISPCONTROL; - command[1] = mode; - command[2] = value; - - if (mode == ORIENTATION) { - switch (value) { - case LANDSCAPE : - current_orientation = IS_LANDSCAPE; - break; - case LANDSCAPE_R : - current_orientation = IS_LANDSCAPE; - break; - case PORTRAIT : - current_orientation = IS_PORTRAIT; - break; - case PORTRAIT_R : - current_orientation = IS_PORTRAIT; - break; - } - } - writeCOMMAND(command, 3); - set_font(current_font); -} - -//**************************************************************************************************** -void TFT_4DGL :: set_volume(char value) { // set sound volume to value - char command[2]= ""; - - command[0] = SETVOLUME; - command[1] = value; - - writeCOMMAND(command, 2); -} - - -//****************************************************************************************************** -void TFT_4DGL :: getTOUCH(char *command, int number, int *x, int *y) { // read screen info and populate data - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X\n", command[0]); -#endif - int i, temp = 0, resp = 0; - char response[5] = ""; - - freeBUFFER(); - - for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - while (_cmd.readable()) { - temp = _cmd.getc(); - response[resp++] = (char)temp; - } - -#if DEBUGMODE - pc.printf(" Answer received %d : 0x%02X 0x%02X 0x%02X 0x%02X\n", resp, response[0], response[1], response[2], response[3]); -#endif - - switch (resp) { - case 4 : // if OK populate data - *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF); - *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF); - break; - default : - *x = -1; - *y = -1; - break; - } - -#if DEBUGMODE - pc.printf(" X,Y : %03d,%03d\n", *x, *y); -#endif -} - -//****************************************************************************************************** -int TFT_4DGL :: getSTATUS(char *command, int number) { // read screen info and populate data - -#if DEBUGMODE - pc.printf("\n"); - pc.printf("New COMMAND : 0x%02X\n", command[0]); -#endif - - int i, temp = 0, resp = 0; - char response[5] = ""; - - freeBUFFER(); - - for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port - - while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer - - while (_cmd.readable()) { - temp = _cmd.getc(); - response[resp++] = (char)temp; - } - switch (resp) { - case 4 : - resp = (int)response[1]; // if OK populate data - break; - default : - resp = -1; // else return 0 - break; - } - -#if DEBUGMODE - pc.printf(" Answer received : %d\n", resp); -#endif - - return resp; +// +// TFT_4DGL is a class to drive 4D Systems TFT touch screens +// +// Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> +// +// TFT_4DGL 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. +// +// TFT_4DGL 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 TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. + +#include "mbed.h" +#include "TFT_4DGL.h" + +Serial pc(USBTX,USBRX); + +//****************************************************************************************************** +TFT_4DGL :: TFT_4DGL(PinName tx, PinName rx, PinName rst) : _cmd(tx, rx), _rst(rst) { // Constructor + +#if DEBUGMODE + pc.baud(115200); + + pc.printf("\n\n\n"); + pc.printf("********************\n"); + pc.printf("TFT_4DGL CONSTRUCTOR\n"); + pc.printf("********************\n"); +#endif + + _rst = 1; // put RESET pin to high to start TFT screen + + reset(); + autobaud(); // send autobaud command + version(); // get version information + cls(); // clear screen + + current_col = 0; // initial cursor col + 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 + text_mode(OPAQUE); // initial texr mode +} + +//****************************************************************************************************** +void TFT_4DGL :: writeBYTE(char c) { // send a BYTE command to screen + + _cmd.putc(c); + wait_ms(1); + +#if DEBUGMODE + pc.printf(" Char sent : 0x%02X\n",c); +#endif + +} + +//****************************************************************************************************** +void TFT_4DGL :: freeBUFFER(void) { // Clear serial buffer before writing command + + while (_cmd.readable()) _cmd.getc(); // clear buffer garbage +} + +//****************************************************************************************************** +int TFT_4DGL :: writeCOMMAND(char *command, int number) { // send several BYTES making a command and return an answer + +#if DEBUGMODE + pc.printf("\n"); + pc.printf("New COMMAND : 0x%02X\n", command[0]); +#endif + int i, resp = 0; + freeBUFFER(); + + for (i = 0; i < number; i++) writeBYTE(command[i]); // send command to serial port + + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + if (_cmd.readable()) resp = _cmd.getc(); // read response if any + switch (resp) { + case ACK : // if OK return 1 + resp = 1; + break; + case NAK : // if NOK return -1 + resp = -1; + break; + default : + resp = 0; // else return 0 + break; + } +#if DEBUGMODE + pc.printf(" Answer received : %d\n",resp); +#endif + + return resp; +} + +//************************************************************************** +void TFT_4DGL :: reset() { // Reset Screen + + _rst = 0; // put RESET pin to low + wait_ms(TEMPO); // wait a few milliseconds for command reception + _rst = 1; // put RESET back to high + wait(3); // wait 3s for screen to restart + + freeBUFFER(); // clean buffer from possible garbage +} + +//************************************************************************** +void TFT_4DGL :: autobaud() { // send AutoBaud command (9600) + char command[1] = ""; + command[0] = AUTOBAUD; + writeCOMMAND(command, 1); +} + +//************************************************************************** +void TFT_4DGL :: cls() { // clear screen + char command[1] = ""; + command[0] = CLS; + writeCOMMAND(command, 1); +} + +//************************************************************************** +void TFT_4DGL :: version() { // get API version + char command[2] = ""; + command[0] = VERSION; + command[1] = OFF; + readVERSION(command, 2); +} + +//************************************************************************** +void TFT_4DGL :: baudrate(int speed) { // set screen baud rate + char command[2]= ""; + command[0] = BAUDRATE; + switch (speed) { + case 110 : + command[1] = BAUD_110; + break; + case 300 : + command[1] = BAUD_300; + break; + case 600 : + command[1] = BAUD_600; + break; + case 1200 : + command[1] = BAUD_1200; + break; + case 2400 : + command[1] = BAUD_2400; + break; + case 4800 : + command[1] = BAUD_4800; + break; + case 9600 : + command[1] = BAUD_9600; + break; + case 14400 : + command[1] = BAUD_14400; + break; + case 19200 : + command[1] = BAUD_19200; + break; + case 31250 : + command[1] = BAUD_31250; + break; + case 38400 : + command[1] = BAUD_38400; + break; + case 56000 : + command[1] = BAUD_56000; + break; + case 57600 : + command[1] = BAUD_57600; + break; + case 115200 : + command[1] = BAUD_115200; + break; + case 128000 : + command[1] = BAUD_128000; + break; + case 256000 : + command[1] = BAUD_256000; + break; + default : + command[1] = BAUD_9600; + speed = 9600; + break; + } + + int i, resp = 0; + + freeBUFFER(); + + for (i = 0; i <2; i++) writeBYTE(command[i]); // send command to serial port + _cmd.baud(speed); // set mbed to same speed + + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + + if (_cmd.readable()) resp = _cmd.getc(); // read response if any + switch (resp) { + case ACK : // if OK return 1 + resp = 1; + break; + case NAK : // if NOK return -1 + resp = -1; + break; + default : + resp = 0; // else return 0 + break; + } +} + +//****************************************************************************************************** +int TFT_4DGL :: readVERSION(char *command, int number) { // read screen info and populate data + + int i, temp = 0, resp = 0; + char response[5] = ""; + + freeBUFFER(); + + for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port + + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + + while (_cmd.readable()) { + temp = _cmd.getc(); + response[resp++] = (char)temp; + } + switch (resp) { + case 5 : // if OK populate data and return 1 + type = response[0]; + revision = response[1]; + firmware = response[2]; + reserved1 = response[3]; + reserved2 = response[4]; + resp = 1; + break; + default : + resp = 0; // else return 0 + break; + } + return resp; +} + +//**************************************************************************************************** +void TFT_4DGL :: background_color(int color) { // set screen background color + char command[3]= ""; // input color is in 24bits like 0xRRGGBB + + command[0] = BCKGDCOLOR; + + 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 TFT_4DGL :: display_control(char mode, char value) { // set screen mode to value + char command[3]= ""; + + command[0] = DISPCONTROL; + command[1] = mode; + command[2] = value; + + if (mode == ORIENTATION) { + switch (value) { + case LANDSCAPE : + current_orientation = IS_LANDSCAPE; + break; + case LANDSCAPE_R : + current_orientation = IS_LANDSCAPE; + break; + case PORTRAIT : + current_orientation = IS_PORTRAIT; + break; + case PORTRAIT_R : + current_orientation = IS_PORTRAIT; + break; + } + } + writeCOMMAND(command, 3); + set_font(current_font); +} + +//**************************************************************************************************** +void TFT_4DGL :: set_volume(char value) { // set sound volume to value + char command[2]= ""; + + command[0] = SETVOLUME; + command[1] = value; + + writeCOMMAND(command, 2); +} + + +//****************************************************************************************************** +void TFT_4DGL :: getTOUCH(char *command, int number, int *x, int *y) { // read screen info and populate data + +#if DEBUGMODE + pc.printf("\n"); + pc.printf("New COMMAND : 0x%02X\n", command[0]); +#endif + int i, temp = 0, resp = 0; + char response[5] = ""; + + freeBUFFER(); + + for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port + + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + + while (_cmd.readable()) { + temp = _cmd.getc(); + response[resp++] = (char)temp; + } + +#if DEBUGMODE + pc.printf(" Answer received %d : 0x%02X 0x%02X 0x%02X 0x%02X\n", resp, response[0], response[1], response[2], response[3]); +#endif + + switch (resp) { + case 4 : // if OK populate data + *x = ((response[0]<<8)+ response[1]) * (response[0] != 0xFF); + *y = ((response[2]<<8)+ response[3]) * (response[2] != 0xFF); + break; + default : + *x = -1; + *y = -1; + break; + } + +#if DEBUGMODE + pc.printf(" X,Y : %03d,%03d\n", *x, *y); +#endif +} + +//****************************************************************************************************** +int TFT_4DGL :: getSTATUS(char *command, int number) { // read screen info and populate data + +#if DEBUGMODE + pc.printf("\n"); + pc.printf("New COMMAND : 0x%02X\n", command[0]); +#endif + + int i, temp = 0, resp = 0; + char response[5] = ""; + + freeBUFFER(); + + for (i = 0; i < number; i++) writeBYTE(command[i]); // send all chars to serial port + + while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer + + while (_cmd.readable()) { + temp = _cmd.getc(); + response[resp++] = (char)temp; + } + switch (resp) { + case 4 : + resp = (int)response[1]; // if OK populate data + break; + default : + resp = -1; // else return 0 + break; + } + +#if DEBUGMODE + pc.printf(" Answer received : %d\n", resp); +#endif + + return resp; } \ No newline at end of file