Claes Ekengren / Mbed 2 deprecated Measurement_system

Dependencies:   mbed

Committer:
CE
Date:
Thu Jan 06 19:01:44 2011 +0000
Revision:
0:0732b16d9a92
R1A

Who changed what in which revision?

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