Extended library to include a screensaver
Fork of 4DGL-uLCD-SE by
Embed:
(wiki syntax)
Show/hide line numbers
uLCD_4DGL_Text.cpp
00001 // 00002 // uLCD_4DGL is a class to drive 4D Systems TFT touch screens 00003 // 00004 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> 00005 // Modifed for Goldelox processor <2013> Jim Hamblen 00006 // 00007 // uLCD_4DGL is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // uLCD_4DGL is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>. 00019 00020 #include "mbed.h" 00021 #include "uLCD_4DGL.h" 00022 00023 //**************************************************************************************************** 00024 void uLCD_4DGL :: set_font_size(char width, char height) // set font size 00025 { 00026 if (current_orientation == IS_PORTRAIT) { 00027 current_fx = width; 00028 current_fy = height; 00029 } else { 00030 current_fy = height; 00031 current_fx = width; 00032 } 00033 max_col = current_w / (current_fx*current_wf); 00034 max_row = current_h / (current_fy*current_hf); 00035 } 00036 00037 //**************************************************************************************************** 00038 void uLCD_4DGL :: set_font(char mode) // set font - system or SD media 00039 { 00040 char command[3]= ""; 00041 00042 command[0] = SETFONT; 00043 command[1] = 0; 00044 command[2] = mode; 00045 00046 current_font = mode; 00047 00048 if (current_orientation == IS_PORTRAIT) { 00049 current_w = SIZE_X; 00050 current_h = SIZE_Y; 00051 } else { 00052 current_w = SIZE_Y; 00053 current_h = SIZE_X; 00054 } 00055 00056 switch (mode) { 00057 case FONT_5X7 : 00058 00059 current_fx = 6; 00060 current_fy = 8; 00061 break; 00062 case FONT_7X8 : 00063 current_fx = 7; 00064 current_fy = 8; 00065 break; 00066 case FONT_8X8 : 00067 current_fx = 8; 00068 current_fy = 8; 00069 break; 00070 case FONT_8X12 : 00071 current_fx = 8; 00072 current_fy = 12; 00073 break; 00074 case FONT_12X16 : 00075 current_fx = 12; 00076 current_fy = 16; 00077 break; 00078 default: 00079 current_fx = 8; 00080 current_fy = 8; 00081 } 00082 00083 max_col = current_w / (current_fx*current_wf); 00084 max_row = current_h / (current_fy*current_hf); 00085 00086 writeCOMMAND(command, 3); 00087 } 00088 00089 00090 00091 //**************************************************************************************************** 00092 void uLCD_4DGL :: text_mode(char mode) // set text mode 00093 { 00094 char command[3]= ""; 00095 00096 command[0] = TEXTMODE; 00097 command[1] = 0; 00098 command[2] = mode; 00099 00100 writeCOMMAND(command, 3); 00101 } 00102 00103 //**************************************************************************************************** 00104 void uLCD_4DGL :: text_bold(char mode) // set text mode 00105 { 00106 char command[3]= ""; 00107 00108 command[0] = TEXTBOLD; 00109 command[1] = 0; 00110 command[2] = mode; 00111 00112 writeCOMMAND(command, 3); 00113 } 00114 00115 //**************************************************************************************************** 00116 void uLCD_4DGL :: text_italic(char mode) // set text mode 00117 { 00118 char command[3]= ""; 00119 00120 command[0] = TEXTITALIC; 00121 command[1] = 0; 00122 command[2] = mode; 00123 00124 writeCOMMAND(command, 3); 00125 } 00126 00127 //**************************************************************************************************** 00128 void uLCD_4DGL :: text_inverse(char mode) // set text mode 00129 { 00130 char command[3]= ""; 00131 00132 command[0] = TEXTINVERSE; 00133 command[1] = 0; 00134 command[2] = mode; 00135 00136 writeCOMMAND(command, 3); 00137 } 00138 00139 //**************************************************************************************************** 00140 void uLCD_4DGL :: text_underline(char mode) // set text mode 00141 { 00142 char command[3]= ""; 00143 00144 command[0] = TEXTUNDERLINE; 00145 command[1] = 0; 00146 command[2] = mode; 00147 00148 writeCOMMAND(command, 3); 00149 } 00150 00151 //**************************************************************************************************** 00152 void uLCD_4DGL :: text_width(char width) // set text width 00153 { 00154 char command[3]= ""; 00155 00156 command[0] = TEXTWIDTH; 00157 command[1] = 0; 00158 command[2] = width; 00159 current_wf = width; 00160 max_col = current_w / (current_fx*current_wf); 00161 writeCOMMAND(command, 3); 00162 } 00163 00164 //**************************************************************************************************** 00165 void uLCD_4DGL :: text_height(char height) // set text height 00166 { 00167 char command[3]= ""; 00168 00169 command[0] = TEXTHEIGHT; 00170 command[1] = 0; 00171 command[2] = height; 00172 current_hf = height; 00173 max_row = current_h / (current_fy*current_hf); 00174 writeCOMMAND(command, 3); 00175 } 00176 00177 00178 //**************************************************************************************************** 00179 void uLCD_4DGL :: text_char(char c, char col, char row, int color, bool isScreenSaverCommand) // draw a text char 00180 { 00181 char command[6]= ""; 00182 command[0] = 0xE4; //move cursor 00183 command[1] = 0; 00184 command[2] = row; 00185 command[3] = 0; 00186 command[4] = col; 00187 writeCOMMAND(command, 5); 00188 00189 command[0] = 0x7F; //set color 00190 00191 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits 00192 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits 00193 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00194 00195 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00196 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00197 writeCOMMAND(command, 3); 00198 00199 command[0] = TEXTCHAR; //print char 00200 command[1] = 0; 00201 command[2] = c; 00202 writeCOMMAND(command, 3); 00203 if (!isScreenSaverCommand) reportScreenInteraction(); 00204 } 00205 00206 00207 //**************************************************************************************************** 00208 void uLCD_4DGL :: text_string(char *s, char col, char row, char font, int color, bool isScreenSaverCommand) // draw a text string 00209 { 00210 00211 char command[1000]= ""; 00212 int size = strlen(s); 00213 int i = 0; 00214 00215 set_font(font); 00216 00217 command[0] = 0xE4; //move cursor 00218 command[1] = 0; 00219 command[2] = row; 00220 command[3] = 0; 00221 command[4] = col; 00222 writeCOMMAND(command, 5); 00223 00224 command[0] = 0x7F; //set color 00225 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits 00226 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits 00227 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00228 00229 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00230 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00231 writeCOMMAND(command, 3); 00232 00233 command[0] = TEXTSTRING; 00234 for (i=0; i<size; i++) command[1+i] = s[i]; 00235 command[1+size] = 0; 00236 writeCOMMANDnull(command, 2 + size); 00237 if (!isScreenSaverCommand) reportScreenInteraction(); 00238 } 00239 00240 00241 00242 //**************************************************************************************************** 00243 void uLCD_4DGL :: locate(char col, char row, bool isScreenSaverCommand) // place text curssor at col, row 00244 { 00245 char command[5] = ""; 00246 current_col = col; 00247 current_row = row; 00248 command[0] = MOVECURSOR; //move cursor 00249 command[1] = 0; 00250 command[2] = current_row; 00251 command[3] = 0; 00252 command[4] = current_col; 00253 writeCOMMAND(command, 5); 00254 if (!isScreenSaverCommand) reportScreenInteraction(); 00255 } 00256 00257 //**************************************************************************************************** 00258 void uLCD_4DGL :: color(int color) // set text color 00259 { 00260 char command[5] = ""; 00261 current_color = color; 00262 command[0] = 0x7F; //set color 00263 00264 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits 00265 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits 00266 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00267 00268 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00269 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00270 writeCOMMAND(command, 3); 00271 } 00272 00273 //**************************************************************************************************** 00274 void uLCD_4DGL :: putc(char c, bool isScreenSaverCommand) // place char at current cursor position 00275 //used by virtual printf function _putc 00276 { 00277 char command[6] =""; 00278 if(c<0x20) { 00279 if(c=='\n') { 00280 current_col = 0; 00281 current_row++; 00282 command[0] = MOVECURSOR; //move cursor to start of next line 00283 command[1] = 0; 00284 command[2] = current_row; 00285 command[3] = 0; 00286 command[4] = current_col; 00287 writeCOMMAND(command, 5); 00288 } 00289 if(c=='\r') { 00290 current_col = 0; 00291 command[0] = MOVECURSOR; //move cursor to start of line 00292 command[1] = 0; 00293 command[2] = current_row; 00294 command[3] = 0; 00295 command[4] = current_col; 00296 writeCOMMAND(command, 5); 00297 } 00298 if(c=='\f') { 00299 uLCD_4DGL::cls(); //clear screen on form feed 00300 } 00301 } else { 00302 command[0] = PUTCHAR; 00303 command[1] = 0x00; 00304 command[2] = c; 00305 writeCOMMAND(command,3); 00306 current_col++; 00307 } 00308 if (current_col == max_col) { 00309 current_col = 0; 00310 current_row++; 00311 command[0] = MOVECURSOR; //move cursor to next line 00312 command[1] = 0; 00313 command[2] = current_row; 00314 command[3] = 0; 00315 command[4] = current_col; 00316 writeCOMMAND(command, 5); 00317 } 00318 if (current_row == max_row) { 00319 current_row = 0; 00320 command[0] = MOVECURSOR; //move cursor back to start 00321 command[1] = 0; 00322 command[2] = current_row; 00323 command[3] = 0; 00324 command[4] = current_col; 00325 writeCOMMAND(command, 5); 00326 } 00327 if (!isScreenSaverCommand) reportScreenInteraction(); 00328 } 00329 00330 00331 //**************************************************************************************************** 00332 void uLCD_4DGL :: puts(char *s, bool isScreenSaverCommand) // place string at current cursor position 00333 { 00334 text_string(s, current_col, current_row, current_font, current_color); 00335 00336 current_col += strlen(s); 00337 00338 if (current_col >= max_col) { 00339 current_row += current_col / max_col; 00340 current_col %= max_col; 00341 } 00342 if (current_row >= max_row) { 00343 current_row %= max_row; 00344 } 00345 if (!isScreenSaverCommand) reportScreenInteraction(); 00346 }
Generated on Fri Jul 15 2022 01:44:25 by 1.7.2