Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 4DGL-uLCD-SE by
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) // 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 00204 } 00205 00206 00207 //**************************************************************************************************** 00208 void uLCD_4DGL :: text_string(char *s, char col, char row, char font, int color) // 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 } 00238 00239 00240 00241 //**************************************************************************************************** 00242 void uLCD_4DGL :: locate(char col, char row) // place text curssor at col, row 00243 { 00244 char command[5] = ""; 00245 current_col = col; 00246 current_row = row; 00247 command[0] = MOVECURSOR; //move cursor 00248 command[1] = 0; 00249 command[2] = current_row; 00250 command[3] = 0; 00251 command[4] = current_col; 00252 writeCOMMAND(command, 5); 00253 } 00254 00255 //**************************************************************************************************** 00256 void uLCD_4DGL :: color(int color) // set text color 00257 { 00258 char command[5] = ""; 00259 current_color = color; 00260 command[0] = 0x7F; //set color 00261 00262 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits 00263 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits 00264 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits 00265 00266 command[1] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color 00267 command[2] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color 00268 writeCOMMAND(command, 3); 00269 } 00270 00271 //**************************************************************************************************** 00272 void uLCD_4DGL :: putc(char c) // place char at current cursor position 00273 //used by virtual printf function _putc 00274 { 00275 char command[6] =""; 00276 if(c<0x20) { 00277 if(c=='\n') { 00278 current_col = 0; 00279 current_row++; 00280 command[0] = MOVECURSOR; //move cursor to start of next line 00281 command[1] = 0; 00282 command[2] = current_row; 00283 command[3] = 0; 00284 command[4] = current_col; 00285 writeCOMMAND(command, 5); 00286 } 00287 if(c=='\r') { 00288 current_col = 0; 00289 command[0] = MOVECURSOR; //move cursor to start of line 00290 command[1] = 0; 00291 command[2] = current_row; 00292 command[3] = 0; 00293 command[4] = current_col; 00294 writeCOMMAND(command, 5); 00295 } 00296 if(c=='\f') { 00297 uLCD_4DGL::cls(); //clear screen on form feed 00298 } 00299 } else { 00300 command[0] = PUTCHAR; 00301 command[1] = 0x00; 00302 command[2] = c; 00303 writeCOMMAND(command,3); 00304 current_col++; 00305 } 00306 if (current_col == max_col) { 00307 current_col = 0; 00308 current_row++; 00309 command[0] = MOVECURSOR; //move cursor to next line 00310 command[1] = 0; 00311 command[2] = current_row; 00312 command[3] = 0; 00313 command[4] = current_col; 00314 writeCOMMAND(command, 5); 00315 } 00316 if (current_row == max_row) { 00317 current_row = 0; 00318 command[0] = MOVECURSOR; //move cursor back to start 00319 command[1] = 0; 00320 command[2] = current_row; 00321 command[3] = 0; 00322 command[4] = current_col; 00323 writeCOMMAND(command, 5); 00324 } 00325 } 00326 00327 00328 //**************************************************************************************************** 00329 void uLCD_4DGL :: puts(char *s) // place string at current cursor position 00330 { 00331 00332 text_string(s, current_col, current_row, current_font, current_color); 00333 00334 current_col += strlen(s); 00335 00336 if (current_col >= max_col) { 00337 current_row += current_col / max_col; 00338 current_col %= max_col; 00339 } 00340 if (current_row >= max_row) { 00341 current_row %= max_row; 00342 } 00343 }
Generated on Mon Jul 18 2022 15:35:45 by
1.7.2
