Extended library to include a screensaver

Dependencies:   SDFileSystem

Fork of 4DGL-uLCD-SE by Jay Danner

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers uLCD_4DGL.h Source File

uLCD_4DGL.h

00001 //
00002 // uLCD_4DGL is a class to drive 4D Systems TFT touch screens
00003 //
00004 // Fork of 4DGL library for 4D Systems LCD displays
00005 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
00006 // Modifed for Goldelox processor <2013> Jim Hamblen
00007 //
00008 // uLCD_4DGL is free software: you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation, either version 3 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // uLCD_4DGL is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with uLCD_4DGL.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021 // @author Stephane Rochon
00022 
00023 #include "mbed.h"
00024 #include "time.h"
00025 #include "rtos.h"
00026 #include "SDFileSystem.h"
00027 #include <fstream>
00028 #include <cstring>
00029 
00030 // Debug Verbose off - SGE commands echoed to USB serial for debugmode=1
00031 #ifndef DEBUGMODE
00032 #define DEBUGMODE 0
00033 #endif
00034 
00035 #ifndef MYDEBUG
00036 #define MYDEBUG 0
00037 #endif
00038 
00039 // Common WAIT value in milliseconds between commands
00040 #define TEMPO 0
00041 
00042 // 4DGL SGE Function values for Goldelox Processor
00043 #define CLS          '\xD7'
00044 #define BAUDRATE     '\x0B' //null prefix
00045 #define VERSION      '\x08' //null prefix
00046 #define BCKGDCOLOR   '\x6E'
00047 #define TXTBCKGDCOLOR '\x7E'
00048 #define DISPCONTROL  '\x68'
00049 #define SETVOLUME    '\x76'
00050 #define CIRCLE       '\xCD'
00051 #define FCIRCLE      '\xCC'
00052 #define TRIANGLE     '\xC9'
00053 #define LINE         '\xD2'
00054 #define FRECTANGLE   '\xCE'
00055 #define RECTANGLE    '\xCF'
00056 #define ELLIPSE      '\x65' //na
00057 #define PIXEL        '\xCB'
00058 #define READPIXEL    '\xCA'
00059 #define SCREENCOPY   '\x63'  //na?
00060 #define PENSIZE      '\xD8'
00061 #define SETFONT      '\x7D'
00062 #define TEXTMODE     '\x77'
00063 #define TEXTBOLD     '\x76'
00064 #define TEXTITALIC   '\x75'
00065 #define TEXTINVERSE  '\x74'
00066 #define TEXTUNDERLINE '\x73'
00067 #define TEXTWIDTH    '\x7C'
00068 #define TEXTHEIGHT   '\x7B'
00069 #define TEXTCHAR     '\xFE'
00070 #define TEXTSTRING   '\x06'  //null prefix
00071 #define MOVECURSOR   '\xE4'
00072 #define BLITCOM      '\x0A'
00073 #define PUTCHAR      '\xFE'
00074 #define DISPPOWER    '\x66'
00075 //media commands for uSD card
00076 #define MINIT        '\xB1'
00077 #define SBADDRESS    '\xB9'
00078 #define SSADDRESS    '\xB8'
00079 #define READBYTE     '\xB7'
00080 #define READWORD     '\xB6'
00081 #define WRITEBYTE    '\xB5'
00082 #define WRITEWORD    '\xB4'
00083 #define FLUSHMEDIA   '\xB2'
00084 #define DISPLAYIMAGE '\xB3'
00085 #define DISPLAYVIDEO '\xBB'
00086 #define DISPLAYFRAME '\xBA'
00087 
00088 
00089 
00090 // Screen answers
00091 #define ACK          '\x06'
00092 #define NAK          '\x15'
00093 
00094 
00095 
00096 // Screen states
00097 #define OFF          '\x00'
00098 #define ON           '\x01'
00099 
00100 // Graphics modes
00101 #define SOLID        '\x00'
00102 #define WIREFRAME    '\x01'
00103 
00104 // Text modes
00105 #define TRANSPARENT  '\x00'
00106 #define OPAQUE       '\x01'
00107 
00108 // Fonts Sizes
00109 #define FONT_7X8     '\x00' //only builtin font 
00110 #define FONT_5X7     '\x04'
00111 #define FONT_8X8     '\x01'
00112 #define FONT_8X12    '\x02'
00113 #define FONT_12X16   '\x03'
00114 #define MEDIAFONT    '\x07'
00115 
00116 
00117 // Data speed
00118 #define BAUD_110     27271
00119 #define BAUD_300     9999
00120 #define BAUD_600     4999
00121 #define BAUD_1200    2499
00122 #define BAUD_2400    1249
00123 #define BAUD_4800    624
00124 #define BAUD_9600    312
00125 #define BAUD_14400   207
00126 #define BAUD_19200   155
00127 #define BAUD_31250   95
00128 #define BAUD_38400   77
00129 #define BAUD_56000   53
00130 #define BAUD_57600   51
00131 #define BAUD_115200  25
00132 #define BAUD_128000  22
00133 #define BAUD_256000  11
00134 #define BAUD_300000  10
00135 #define BAUD_375000  8
00136 #define BAUD_500000  6
00137 #define BAUD_600000  4
00138 #define BAUD_750000  3
00139 #define BAUD_1000000 2
00140 #define BAUD_1500000 1
00141 #define BAUD_3000000 0
00142 
00143 // Defined Colors
00144 #define WHITE 0xFFFFFF
00145 #define BLACK 0x000000
00146 #define RED   0xFF0000
00147 #define GREEN 0x00FF00
00148 #define BLUE  0x0000FF
00149 #define LGREY 0xBFBFBF
00150 #define DGREY 0x5F5F5F
00151 
00152 // Mode data
00153 #define BACKLIGHT    '\x00'
00154 #define DISPLAY      '\x01'
00155 #define CONTRAST     '\x02'
00156 #define POWER        '\x03'
00157 #define ORIENTATION  '\x04'
00158 #define TOUCH_CTRL   '\x05'
00159 #define IMAGE_FORMAT '\x06'
00160 #define PROTECT_FAT  '\x08'
00161 
00162 // change this to your specific screen (newer versions) if needed
00163 // Startup orientation is PORTRAIT so SIZE_X must be lesser than SIZE_Y
00164 //uLCD144-G2 is a 128 by 128 pixel display
00165 #define SIZE_X       128
00166 #define SIZE_Y       128
00167 
00168 #define IS_LANDSCAPE 0
00169 #define IS_PORTRAIT  1
00170 
00171 // Screen orientation
00172 #define LANDSCAPE    '\x00'
00173 #define LANDSCAPE_R  '\x01'
00174 #define PORTRAIT     '\x02'
00175 #define PORTRAIT_R   '\x03'
00176 
00177 // Parameters
00178 #define ENABLE       '\x00'
00179 #define DISABLE      '\x01'
00180 #define RESET        '\x02'
00181 
00182 #define NEW          '\x00'
00183 #define OLD          '\x01'
00184 
00185 #define DOWN         '\x00'
00186 #define UP           '\x01'
00187 
00188 #define PROTECT      '\x00'
00189 #define UNPROTECT    '\x02'
00190 
00191 //**************************************************************************
00192 // \class uLCD_4DGL uLCD_4DGL.h
00193 // \brief This is the main class. It shoud be used like this : uLCD_4GDL myLCD(p9,p10,p11);
00194 /**
00195 Example:
00196 * @code
00197 * // Display a white circle on the screen
00198 * #include "mbed.h"
00199 * #include " uLCD_4DGL.h"
00200 *
00201 * uLCD_4GDL myLCD(p9,p10,p11);
00202 *
00203 * int main() {
00204 *     myLCD.circle(120, 160, 80, WHITE);
00205 * }
00206 * @endcode
00207 */
00208 class uLCD_4DGL : public Stream
00209 {
00210 public :
00211     uLCD_4DGL(PinName tx, PinName rx, PinName rst);
00212 
00213 // General Commands *******************************************************************************
00214 
00215     /** Clear the entire screen using the current background colour */
00216     void cls();
00217 
00218     /** Reset screen */
00219     void reset();
00220 
00221 
00222     /** Set serial Baud rate (both sides : screen and mbed)
00223     * @param Speed Correct BAUD value (see uLCD_4DGL.h)
00224     */
00225     void baudrate(int speed);
00226 
00227     /** Set background colour to the specified value
00228     * @param color in HEX RGB like 0xFF00FF
00229     */
00230     void background_color(int color);
00231 
00232     /** Set screen display mode to specific values
00233     * @param mode See 4DGL documentation
00234     * @param value See 4DGL documentation
00235     */
00236     void textbackground_color(int color);
00237 
00238     /** Set screen display mode to specific values
00239     * @param mode See 4DGL documentation
00240     * @param value See 4DGL documentation
00241     */
00242     void display_control(char mode);
00243     void display_power(char mode);
00244     /** Set internal speaker to specified value
00245     * @param value Correct range is 8 - 127
00246     */
00247     void set_volume(char value);
00248 
00249 // Graphics Commands *******************************************************************************
00250 
00251     /** 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
00252     * @param x Horizontal position of the circle centre
00253     * @param y Vertical position of the circle centre
00254     * @param radius Radius of the circle
00255     * @param color Circle color in HEX RGB like 0xFF00FF
00256     */
00257     void circle(int x , int y , int radius, int color, bool isScreenSaverCommand=false);
00258     void filled_circle(int x , int y , int radius, int color, bool isScreenSaverCommand=false);
00259     void triangle(int, int, int, int, int, int, int, bool isScreenSaverCommand=false);
00260     void line(int, int, int, int, int, bool isScreenSaverCommand=false);
00261     void rectangle(int, int, int, int, int, bool isScreenSaverCommand=false);
00262     void filled_rectangle(int, int, int, int, int, bool isScreenSaverCommand=false);
00263     void pixel(int, int, int, bool isScreenSaverCommand=false);
00264     int  read_pixel(int, int);
00265     void pen_size(char);
00266     void BLIT(int x, int y, int w, int h, int *colors, bool isScreenSaverCommand=false);
00267 
00268 // Text Commands
00269     void set_font(char);
00270     void set_font_size(char width, char height);  
00271     void text_mode(char);
00272     void text_bold(char);
00273     void text_italic(char);
00274     void text_inverse(char);
00275     void text_underline(char);
00276     void text_width(char);
00277     void text_height(char);
00278     void text_char(char, char, char, int, bool isScreenSaverCommand=false);
00279     void text_string(char *, char, char, char, int, bool isScreenSaverCommand=false);
00280     void locate(char, char, bool isScreenSaverCommand=false);
00281     void color(int);
00282     void putc(char, bool isScreenSaverCommand=false);
00283     void puts(char *, bool isScreenSaverCommand=false);
00284 
00285 //Media Commands
00286     int media_init();
00287     void set_byte_address(int, int);
00288     void set_sector_address(int, int);
00289     char read_byte();
00290     int  read_word();
00291     void write_byte(int);
00292     void write_word(int);
00293     void flush_media();
00294     void display_image(int, int, bool isScreenSaverCommand=false);
00295     void display_video(int, int, bool isScreenSaverCommand=false);
00296     void display_frame(int, int, int, bool isScreenSaverCommand=false);
00297     
00298 // Screensaver commands
00299     void checkActiveScreenTime();
00300     void setActiveScreenInterval(int newInterval);
00301     int  getActiveScreenInterval();
00302     void reportScreenInteraction();
00303     bool isInScreensaverMode();
00304     void enableScreensaverMode();
00305     void exitScreensaverMode();
00306     void backupStateOfScreen();
00307     void restoreStateOfScreen();
00308 
00309 // Screen Data
00310     int type;
00311     int revision;
00312     int firmware;
00313     int reserved1;
00314     int reserved2;
00315     time_t now;
00316     time_t lastDisplayActivityTime;
00317     time_t lastScreensaverInit;
00318     int    max_active_screen_interval;
00319     bool inScreensaverMode;
00320     bool inScreensaverHysteresis;
00321     SDFileSystem sd; // mosi, miso, sclk, cs
00322 
00323 // Text data
00324     char current_col;
00325     char current_row;
00326     int  current_color;
00327     char current_font;
00328     char current_orientation;
00329     char max_col;
00330     char max_row;
00331     int current_w, current_h;
00332     int current_fx, current_fy;
00333     int current_wf, current_hf;
00334 
00335 
00336 protected :
00337 
00338     Serial     _cmd;
00339     DigitalOut _rst;
00340     //used by printf
00341     virtual int _putc(int c) {
00342         putc(c, false);
00343         return 0;
00344     };
00345     virtual int _getc() {
00346         return -1;
00347     }
00348 
00349     void freeBUFFER  (void);
00350     void writeBYTE   (char);
00351     void writeBYTEfast   (char);
00352     int  writeCOMMAND(char *, int);
00353     int  writeCOMMANDnull(char *, int);
00354     int  readVERSION (char *, int);
00355     int  getSTATUS   (char *, int);
00356     int  version     (void);
00357     Serial pc;
00358 };
00359 
00360 typedef unsigned char BYTE;
00361 
00362 
00363 
00364 
00365 
00366 
00367 
00368