Kamil Ondrousek
/
Rikitake
Rikitake chaotic system
TFT_4DGL_Text.cpp@0:0e1b2bdda33f, 2011-03-02 (annotated)
- Committer:
- JLS
- Date:
- Wed Mar 02 18:27:55 2011 +0000
- Revision:
- 0:0e1b2bdda33f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JLS | 0:0e1b2bdda33f | 1 | // |
JLS | 0:0e1b2bdda33f | 2 | // TFT_4DGL is a class to drive 4D Systems TFT touch screens |
JLS | 0:0e1b2bdda33f | 3 | // |
JLS | 0:0e1b2bdda33f | 4 | // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr> |
JLS | 0:0e1b2bdda33f | 5 | // |
JLS | 0:0e1b2bdda33f | 6 | // TFT_4DGL is free software: you can redistribute it and/or modify |
JLS | 0:0e1b2bdda33f | 7 | // it under the terms of the GNU General Public License as published by |
JLS | 0:0e1b2bdda33f | 8 | // the Free Software Foundation, either version 3 of the License, or |
JLS | 0:0e1b2bdda33f | 9 | // (at your option) any later version. |
JLS | 0:0e1b2bdda33f | 10 | // |
JLS | 0:0e1b2bdda33f | 11 | // TFT_4DGL is distributed in the hope that it will be useful, |
JLS | 0:0e1b2bdda33f | 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
JLS | 0:0e1b2bdda33f | 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
JLS | 0:0e1b2bdda33f | 14 | // GNU General Public License for more details. |
JLS | 0:0e1b2bdda33f | 15 | // |
JLS | 0:0e1b2bdda33f | 16 | // You should have received a copy of the GNU General Public License |
JLS | 0:0e1b2bdda33f | 17 | // along with TFT_4DGL. If not, see <http://www.gnu.org/licenses/>. |
JLS | 0:0e1b2bdda33f | 18 | |
JLS | 0:0e1b2bdda33f | 19 | #include "mbed.h" |
JLS | 0:0e1b2bdda33f | 20 | #include "TFT_4DGL.h" |
JLS | 0:0e1b2bdda33f | 21 | |
JLS | 0:0e1b2bdda33f | 22 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 23 | void TFT_4DGL :: set_font(char mode) { // set font size |
JLS | 0:0e1b2bdda33f | 24 | char command[2]= ""; |
JLS | 0:0e1b2bdda33f | 25 | |
JLS | 0:0e1b2bdda33f | 26 | int w, h, fx = 8, fy = 8; |
JLS | 0:0e1b2bdda33f | 27 | |
JLS | 0:0e1b2bdda33f | 28 | command[0] = SETFONT; |
JLS | 0:0e1b2bdda33f | 29 | command[1] = mode; |
JLS | 0:0e1b2bdda33f | 30 | |
JLS | 0:0e1b2bdda33f | 31 | current_font = mode; |
JLS | 0:0e1b2bdda33f | 32 | |
JLS | 0:0e1b2bdda33f | 33 | if (current_orientation == IS_PORTRAIT) { |
JLS | 0:0e1b2bdda33f | 34 | w = SIZE_X; |
JLS | 0:0e1b2bdda33f | 35 | h = SIZE_Y; |
JLS | 0:0e1b2bdda33f | 36 | } else { |
JLS | 0:0e1b2bdda33f | 37 | w = SIZE_Y; |
JLS | 0:0e1b2bdda33f | 38 | h = SIZE_X; |
JLS | 0:0e1b2bdda33f | 39 | } |
JLS | 0:0e1b2bdda33f | 40 | |
JLS | 0:0e1b2bdda33f | 41 | switch (mode) { |
JLS | 0:0e1b2bdda33f | 42 | case FONT_5X7 : |
JLS | 0:0e1b2bdda33f | 43 | fx = 6; |
JLS | 0:0e1b2bdda33f | 44 | fy = 8; |
JLS | 0:0e1b2bdda33f | 45 | break; |
JLS | 0:0e1b2bdda33f | 46 | case FONT_8X8 : |
JLS | 0:0e1b2bdda33f | 47 | fx = 8; |
JLS | 0:0e1b2bdda33f | 48 | fy = 8; |
JLS | 0:0e1b2bdda33f | 49 | break; |
JLS | 0:0e1b2bdda33f | 50 | case FONT_8X12 : |
JLS | 0:0e1b2bdda33f | 51 | fx = 8; |
JLS | 0:0e1b2bdda33f | 52 | fy = 12; |
JLS | 0:0e1b2bdda33f | 53 | break; |
JLS | 0:0e1b2bdda33f | 54 | case FONT_12X16 : |
JLS | 0:0e1b2bdda33f | 55 | fx = 12; |
JLS | 0:0e1b2bdda33f | 56 | fy = 16; |
JLS | 0:0e1b2bdda33f | 57 | break; |
JLS | 0:0e1b2bdda33f | 58 | } |
JLS | 0:0e1b2bdda33f | 59 | |
JLS | 0:0e1b2bdda33f | 60 | max_col = w / fx; |
JLS | 0:0e1b2bdda33f | 61 | max_row = h / fy; |
JLS | 0:0e1b2bdda33f | 62 | |
JLS | 0:0e1b2bdda33f | 63 | writeCOMMAND(command, 2); |
JLS | 0:0e1b2bdda33f | 64 | } |
JLS | 0:0e1b2bdda33f | 65 | |
JLS | 0:0e1b2bdda33f | 66 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 67 | void TFT_4DGL :: text_mode(char mode) { // set text mode |
JLS | 0:0e1b2bdda33f | 68 | char command[2]= ""; |
JLS | 0:0e1b2bdda33f | 69 | |
JLS | 0:0e1b2bdda33f | 70 | command[0] = TEXTMODE; |
JLS | 0:0e1b2bdda33f | 71 | command[1] = mode; |
JLS | 0:0e1b2bdda33f | 72 | |
JLS | 0:0e1b2bdda33f | 73 | writeCOMMAND(command, 2); |
JLS | 0:0e1b2bdda33f | 74 | } |
JLS | 0:0e1b2bdda33f | 75 | |
JLS | 0:0e1b2bdda33f | 76 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 77 | void TFT_4DGL :: text_char(char c, char col, char row, int color) { // draw a text char |
JLS | 0:0e1b2bdda33f | 78 | char command[6]= ""; |
JLS | 0:0e1b2bdda33f | 79 | |
JLS | 0:0e1b2bdda33f | 80 | command[0] = TEXTCHAR; |
JLS | 0:0e1b2bdda33f | 81 | |
JLS | 0:0e1b2bdda33f | 82 | command[1] = c; |
JLS | 0:0e1b2bdda33f | 83 | command[2] = col; |
JLS | 0:0e1b2bdda33f | 84 | command[3] = row; |
JLS | 0:0e1b2bdda33f | 85 | |
JLS | 0:0e1b2bdda33f | 86 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
JLS | 0:0e1b2bdda33f | 87 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
JLS | 0:0e1b2bdda33f | 88 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
JLS | 0:0e1b2bdda33f | 89 | |
JLS | 0:0e1b2bdda33f | 90 | command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
JLS | 0:0e1b2bdda33f | 91 | command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
JLS | 0:0e1b2bdda33f | 92 | |
JLS | 0:0e1b2bdda33f | 93 | writeCOMMAND(command, 8); |
JLS | 0:0e1b2bdda33f | 94 | } |
JLS | 0:0e1b2bdda33f | 95 | |
JLS | 0:0e1b2bdda33f | 96 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 97 | void TFT_4DGL :: graphic_char(char c, int x, int y, int color, char width, char height) { // draw a graphic char |
JLS | 0:0e1b2bdda33f | 98 | char command[10]= ""; |
JLS | 0:0e1b2bdda33f | 99 | |
JLS | 0:0e1b2bdda33f | 100 | command[0] = GRAPHCHAR; |
JLS | 0:0e1b2bdda33f | 101 | |
JLS | 0:0e1b2bdda33f | 102 | command[1] = c; |
JLS | 0:0e1b2bdda33f | 103 | |
JLS | 0:0e1b2bdda33f | 104 | command[2] = (x >> 8) & 0xFF; |
JLS | 0:0e1b2bdda33f | 105 | command[3] = x & 0xFF; |
JLS | 0:0e1b2bdda33f | 106 | |
JLS | 0:0e1b2bdda33f | 107 | command[4] = (y >> 8) & 0xFF; |
JLS | 0:0e1b2bdda33f | 108 | command[5] = y & 0xFF; |
JLS | 0:0e1b2bdda33f | 109 | |
JLS | 0:0e1b2bdda33f | 110 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
JLS | 0:0e1b2bdda33f | 111 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
JLS | 0:0e1b2bdda33f | 112 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
JLS | 0:0e1b2bdda33f | 113 | |
JLS | 0:0e1b2bdda33f | 114 | command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
JLS | 0:0e1b2bdda33f | 115 | command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
JLS | 0:0e1b2bdda33f | 116 | |
JLS | 0:0e1b2bdda33f | 117 | command[8] = width; |
JLS | 0:0e1b2bdda33f | 118 | |
JLS | 0:0e1b2bdda33f | 119 | command[9] = height; |
JLS | 0:0e1b2bdda33f | 120 | |
JLS | 0:0e1b2bdda33f | 121 | writeCOMMAND(command, 10); |
JLS | 0:0e1b2bdda33f | 122 | } |
JLS | 0:0e1b2bdda33f | 123 | |
JLS | 0:0e1b2bdda33f | 124 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 125 | void TFT_4DGL :: text_string(char *s, char col, char row, char font, int color) { // draw a text string |
JLS | 0:0e1b2bdda33f | 126 | |
JLS | 0:0e1b2bdda33f | 127 | char command[1000]= ""; |
JLS | 0:0e1b2bdda33f | 128 | int size = strlen(s); |
JLS | 0:0e1b2bdda33f | 129 | int i = 0; |
JLS | 0:0e1b2bdda33f | 130 | |
JLS | 0:0e1b2bdda33f | 131 | command[0] = TEXTSTRING; |
JLS | 0:0e1b2bdda33f | 132 | |
JLS | 0:0e1b2bdda33f | 133 | command[1] = col; |
JLS | 0:0e1b2bdda33f | 134 | command[2] = row; |
JLS | 0:0e1b2bdda33f | 135 | |
JLS | 0:0e1b2bdda33f | 136 | command[3] = font; |
JLS | 0:0e1b2bdda33f | 137 | |
JLS | 0:0e1b2bdda33f | 138 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
JLS | 0:0e1b2bdda33f | 139 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
JLS | 0:0e1b2bdda33f | 140 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
JLS | 0:0e1b2bdda33f | 141 | |
JLS | 0:0e1b2bdda33f | 142 | command[4] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
JLS | 0:0e1b2bdda33f | 143 | command[5] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
JLS | 0:0e1b2bdda33f | 144 | |
JLS | 0:0e1b2bdda33f | 145 | for (i=0; i<size; i++) command[6+i] = s[i]; |
JLS | 0:0e1b2bdda33f | 146 | |
JLS | 0:0e1b2bdda33f | 147 | command[6+size] = 0; |
JLS | 0:0e1b2bdda33f | 148 | |
JLS | 0:0e1b2bdda33f | 149 | writeCOMMAND(command, 7 + size); |
JLS | 0:0e1b2bdda33f | 150 | } |
JLS | 0:0e1b2bdda33f | 151 | |
JLS | 0:0e1b2bdda33f | 152 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 153 | void TFT_4DGL :: graphic_string(char *s, int x, int y, char font, int color, char width, char height) { // draw a text string |
JLS | 0:0e1b2bdda33f | 154 | |
JLS | 0:0e1b2bdda33f | 155 | char command[1000]= ""; |
JLS | 0:0e1b2bdda33f | 156 | int size = strlen(s); |
JLS | 0:0e1b2bdda33f | 157 | int i = 0; |
JLS | 0:0e1b2bdda33f | 158 | |
JLS | 0:0e1b2bdda33f | 159 | command[0] = GRAPHSTRING; |
JLS | 0:0e1b2bdda33f | 160 | |
JLS | 0:0e1b2bdda33f | 161 | command[1] = (x >> 8) & 0xFF; |
JLS | 0:0e1b2bdda33f | 162 | command[2] = x & 0xFF; |
JLS | 0:0e1b2bdda33f | 163 | |
JLS | 0:0e1b2bdda33f | 164 | command[3] = (y >> 8) & 0xFF; |
JLS | 0:0e1b2bdda33f | 165 | command[4] = y & 0xFF; |
JLS | 0:0e1b2bdda33f | 166 | |
JLS | 0:0e1b2bdda33f | 167 | command[5] = font; |
JLS | 0:0e1b2bdda33f | 168 | |
JLS | 0:0e1b2bdda33f | 169 | int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits |
JLS | 0:0e1b2bdda33f | 170 | int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits |
JLS | 0:0e1b2bdda33f | 171 | int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
JLS | 0:0e1b2bdda33f | 172 | |
JLS | 0:0e1b2bdda33f | 173 | command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
JLS | 0:0e1b2bdda33f | 174 | command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
JLS | 0:0e1b2bdda33f | 175 | |
JLS | 0:0e1b2bdda33f | 176 | command[8] = width; |
JLS | 0:0e1b2bdda33f | 177 | |
JLS | 0:0e1b2bdda33f | 178 | command[9] = height; |
JLS | 0:0e1b2bdda33f | 179 | |
JLS | 0:0e1b2bdda33f | 180 | for (i=0; i<size; i++) command[10+i] = s[i]; |
JLS | 0:0e1b2bdda33f | 181 | |
JLS | 0:0e1b2bdda33f | 182 | command[10+size] = 0; |
JLS | 0:0e1b2bdda33f | 183 | |
JLS | 0:0e1b2bdda33f | 184 | writeCOMMAND(command, 11 + size); |
JLS | 0:0e1b2bdda33f | 185 | } |
JLS | 0:0e1b2bdda33f | 186 | |
JLS | 0:0e1b2bdda33f | 187 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 188 | 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 |
JLS | 0:0e1b2bdda33f | 189 | |
JLS | 0:0e1b2bdda33f | 190 | char command[1000]= ""; |
JLS | 0:0e1b2bdda33f | 191 | int size = strlen(s); |
JLS | 0:0e1b2bdda33f | 192 | int i = 0, red5, green6, blue5; |
JLS | 0:0e1b2bdda33f | 193 | |
JLS | 0:0e1b2bdda33f | 194 | command[0] = TEXTBUTTON; |
JLS | 0:0e1b2bdda33f | 195 | |
JLS | 0:0e1b2bdda33f | 196 | command[1] = mode; |
JLS | 0:0e1b2bdda33f | 197 | |
JLS | 0:0e1b2bdda33f | 198 | command[2] = (x >> 8) & 0xFF; |
JLS | 0:0e1b2bdda33f | 199 | command[3] = x & 0xFF; |
JLS | 0:0e1b2bdda33f | 200 | |
JLS | 0:0e1b2bdda33f | 201 | command[4] = (y >> 8) & 0xFF; |
JLS | 0:0e1b2bdda33f | 202 | command[5] = y & 0xFF; |
JLS | 0:0e1b2bdda33f | 203 | |
JLS | 0:0e1b2bdda33f | 204 | red5 = (button_color >> (16 + 3)) & 0x1F; // get red on 5 bits |
JLS | 0:0e1b2bdda33f | 205 | green6 = (button_color >> (8 + 2)) & 0x3F; // get green on 6 bits |
JLS | 0:0e1b2bdda33f | 206 | blue5 = (button_color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
JLS | 0:0e1b2bdda33f | 207 | |
JLS | 0:0e1b2bdda33f | 208 | command[6] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
JLS | 0:0e1b2bdda33f | 209 | command[7] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
JLS | 0:0e1b2bdda33f | 210 | |
JLS | 0:0e1b2bdda33f | 211 | command[8] = font; |
JLS | 0:0e1b2bdda33f | 212 | |
JLS | 0:0e1b2bdda33f | 213 | red5 = (text_color >> (16 + 3)) & 0x1F; // get red on 5 bits |
JLS | 0:0e1b2bdda33f | 214 | green6 = (text_color >> (8 + 2)) & 0x3F; // get green on 6 bits |
JLS | 0:0e1b2bdda33f | 215 | blue5 = (text_color >> (0 + 3)) & 0x1F; // get blue on 5 bits |
JLS | 0:0e1b2bdda33f | 216 | |
JLS | 0:0e1b2bdda33f | 217 | command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color |
JLS | 0:0e1b2bdda33f | 218 | command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color |
JLS | 0:0e1b2bdda33f | 219 | |
JLS | 0:0e1b2bdda33f | 220 | command[11] = width; |
JLS | 0:0e1b2bdda33f | 221 | |
JLS | 0:0e1b2bdda33f | 222 | command[12] = height; |
JLS | 0:0e1b2bdda33f | 223 | |
JLS | 0:0e1b2bdda33f | 224 | for (i=0; i<size; i++) command[13+i] = s[i]; |
JLS | 0:0e1b2bdda33f | 225 | |
JLS | 0:0e1b2bdda33f | 226 | command[13+size] = 0; |
JLS | 0:0e1b2bdda33f | 227 | |
JLS | 0:0e1b2bdda33f | 228 | writeCOMMAND(command, 14 + size); |
JLS | 0:0e1b2bdda33f | 229 | } |
JLS | 0:0e1b2bdda33f | 230 | |
JLS | 0:0e1b2bdda33f | 231 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 232 | void TFT_4DGL :: locate(char col, char row) { // place text curssor at col, row |
JLS | 0:0e1b2bdda33f | 233 | current_col = col; |
JLS | 0:0e1b2bdda33f | 234 | current_row = row; |
JLS | 0:0e1b2bdda33f | 235 | } |
JLS | 0:0e1b2bdda33f | 236 | |
JLS | 0:0e1b2bdda33f | 237 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 238 | void TFT_4DGL :: color(int color) { // set text color |
JLS | 0:0e1b2bdda33f | 239 | current_color = color; |
JLS | 0:0e1b2bdda33f | 240 | } |
JLS | 0:0e1b2bdda33f | 241 | |
JLS | 0:0e1b2bdda33f | 242 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 243 | void TFT_4DGL :: putc(char c) { // place char at current cursor position |
JLS | 0:0e1b2bdda33f | 244 | |
JLS | 0:0e1b2bdda33f | 245 | text_char(c, current_col++, current_row, current_color); |
JLS | 0:0e1b2bdda33f | 246 | |
JLS | 0:0e1b2bdda33f | 247 | if (current_col == max_col) { |
JLS | 0:0e1b2bdda33f | 248 | current_col = 0; |
JLS | 0:0e1b2bdda33f | 249 | current_row++; |
JLS | 0:0e1b2bdda33f | 250 | } |
JLS | 0:0e1b2bdda33f | 251 | if (current_row == max_row) { |
JLS | 0:0e1b2bdda33f | 252 | current_row = 0; |
JLS | 0:0e1b2bdda33f | 253 | } |
JLS | 0:0e1b2bdda33f | 254 | } |
JLS | 0:0e1b2bdda33f | 255 | |
JLS | 0:0e1b2bdda33f | 256 | //**************************************************************************************************** |
JLS | 0:0e1b2bdda33f | 257 | void TFT_4DGL :: puts(char *s) { // place string at current cursor position |
JLS | 0:0e1b2bdda33f | 258 | |
JLS | 0:0e1b2bdda33f | 259 | text_string(s, current_col, current_row, current_font, current_color); |
JLS | 0:0e1b2bdda33f | 260 | |
JLS | 0:0e1b2bdda33f | 261 | current_col += strlen(s); |
JLS | 0:0e1b2bdda33f | 262 | |
JLS | 0:0e1b2bdda33f | 263 | if (current_col >= max_col) { |
JLS | 0:0e1b2bdda33f | 264 | current_row += current_col / max_col; |
JLS | 0:0e1b2bdda33f | 265 | current_col %= max_col; |
JLS | 0:0e1b2bdda33f | 266 | } |
JLS | 0:0e1b2bdda33f | 267 | if (current_row >= max_row) { |
JLS | 0:0e1b2bdda33f | 268 | current_row %= max_row; |
JLS | 0:0e1b2bdda33f | 269 | } |
JLS | 0:0e1b2bdda33f | 270 | } |