smartgpu version 1
Dependents: 4dofRoboticArmAX12
SMARTGPU.cpp@0:d2c9ddbc2cda, 2012-08-31 (annotated)
- Committer:
- aimen
- Date:
- Fri Aug 31 06:32:17 2012 +0000
- Revision:
- 0:d2c9ddbc2cda
initial set up
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aimen | 0:d2c9ddbc2cda | 1 | |
aimen | 0:d2c9ddbc2cda | 2 | #include "mbed.h" |
aimen | 0:d2c9ddbc2cda | 3 | #include "SMARTGPU.h" |
aimen | 0:d2c9ddbc2cda | 4 | |
aimen | 0:d2c9ddbc2cda | 5 | // SMART GPU DEFAULT BAUD RATE: 9600bps |
aimen | 0:d2c9ddbc2cda | 6 | //It shoud be used like this : SMARTGPU lcd(p13,p14,p15); for serial communication with SMARTGPU |
aimen | 0:d2c9ddbc2cda | 7 | SMARTGPU::SMARTGPU(PinName TXPin, PinName RXPin, PinName resetPin): _serialSMARTGPU(TXPin,RXPin), _resetPin(resetPin){ |
aimen | 0:d2c9ddbc2cda | 8 | init(); |
aimen | 0:d2c9ddbc2cda | 9 | } |
aimen | 0:d2c9ddbc2cda | 10 | |
aimen | 0:d2c9ddbc2cda | 11 | /********** high level commands, for the user! */ |
aimen | 0:d2c9ddbc2cda | 12 | void SMARTGPU::init(){ //configure the mbed for SMARTGPU board |
aimen | 0:d2c9ddbc2cda | 13 | _serialSMARTGPU.baud(9600); |
aimen | 0:d2c9ddbc2cda | 14 | _resetPin=1; //set the pin to 3.3v to avoid reset |
aimen | 0:d2c9ddbc2cda | 15 | } |
aimen | 0:d2c9ddbc2cda | 16 | |
aimen | 0:d2c9ddbc2cda | 17 | void SMARTGPU::reset(){ //Reset the SMARTGPU board |
aimen | 0:d2c9ddbc2cda | 18 | _resetPin=0; //set the pin to GND to reset |
aimen | 0:d2c9ddbc2cda | 19 | wait_ms(500); |
aimen | 0:d2c9ddbc2cda | 20 | _resetPin=1; //set the pin to 3.3v to end reset |
aimen | 0:d2c9ddbc2cda | 21 | wait_ms(500); |
aimen | 0:d2c9ddbc2cda | 22 | } |
aimen | 0:d2c9ddbc2cda | 23 | |
aimen | 0:d2c9ddbc2cda | 24 | unsigned char SMARTGPU::start(){ //Init the SMARTGPU |
aimen | 0:d2c9ddbc2cda | 25 | wait_ms(500); |
aimen | 0:d2c9ddbc2cda | 26 | _serialSMARTGPU.putc('U'); |
aimen | 0:d2c9ddbc2cda | 27 | wait_ms(1000); |
aimen | 0:d2c9ddbc2cda | 28 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 29 | } |
aimen | 0:d2c9ddbc2cda | 30 | |
aimen | 0:d2c9ddbc2cda | 31 | unsigned char SMARTGPU::erase(){ //Erase the SMARTGPU screen |
aimen | 0:d2c9ddbc2cda | 32 | _serialSMARTGPU.putc('E'); |
aimen | 0:d2c9ddbc2cda | 33 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 34 | } |
aimen | 0:d2c9ddbc2cda | 35 | |
aimen | 0:d2c9ddbc2cda | 36 | unsigned char SMARTGPU::sleep(unsigned char mode){ //Send SMARTGPU to sleep mode |
aimen | 0:d2c9ddbc2cda | 37 | _serialSMARTGPU.putc('Z'); |
aimen | 0:d2c9ddbc2cda | 38 | _serialSMARTGPU.putc(mode); |
aimen | 0:d2c9ddbc2cda | 39 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 40 | } |
aimen | 0:d2c9ddbc2cda | 41 | |
aimen | 0:d2c9ddbc2cda | 42 | unsigned char SMARTGPU::orientation(unsigned char side){ //Change display orientation |
aimen | 0:d2c9ddbc2cda | 43 | _serialSMARTGPU.putc('O'); |
aimen | 0:d2c9ddbc2cda | 44 | _serialSMARTGPU.putc(side); |
aimen | 0:d2c9ddbc2cda | 45 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 46 | } |
aimen | 0:d2c9ddbc2cda | 47 | |
aimen | 0:d2c9ddbc2cda | 48 | unsigned char SMARTGPU::bright(unsigned char val){ //Change display brightness |
aimen | 0:d2c9ddbc2cda | 49 | _serialSMARTGPU.putc('V'); |
aimen | 0:d2c9ddbc2cda | 50 | _serialSMARTGPU.putc(val); |
aimen | 0:d2c9ddbc2cda | 51 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 52 | } |
aimen | 0:d2c9ddbc2cda | 53 | |
aimen | 0:d2c9ddbc2cda | 54 | unsigned char SMARTGPU::baudChange(unsigned long val){ //Change baud rate of arduino and SMARTGPU board |
aimen | 0:d2c9ddbc2cda | 55 | unsigned char aux; |
aimen | 0:d2c9ddbc2cda | 56 | |
aimen | 0:d2c9ddbc2cda | 57 | switch(val){ |
aimen | 0:d2c9ddbc2cda | 58 | case 9600: |
aimen | 0:d2c9ddbc2cda | 59 | aux=0; |
aimen | 0:d2c9ddbc2cda | 60 | break; |
aimen | 0:d2c9ddbc2cda | 61 | case 19200: |
aimen | 0:d2c9ddbc2cda | 62 | aux=1; |
aimen | 0:d2c9ddbc2cda | 63 | break; |
aimen | 0:d2c9ddbc2cda | 64 | case 57600: |
aimen | 0:d2c9ddbc2cda | 65 | aux=2; |
aimen | 0:d2c9ddbc2cda | 66 | break; |
aimen | 0:d2c9ddbc2cda | 67 | case 115200: |
aimen | 0:d2c9ddbc2cda | 68 | aux=3; |
aimen | 0:d2c9ddbc2cda | 69 | break; |
aimen | 0:d2c9ddbc2cda | 70 | case 256000: |
aimen | 0:d2c9ddbc2cda | 71 | aux=4; |
aimen | 0:d2c9ddbc2cda | 72 | break; |
aimen | 0:d2c9ddbc2cda | 73 | case 500000: |
aimen | 0:d2c9ddbc2cda | 74 | aux=5; |
aimen | 0:d2c9ddbc2cda | 75 | break; |
aimen | 0:d2c9ddbc2cda | 76 | case 1000000: |
aimen | 0:d2c9ddbc2cda | 77 | aux=6; |
aimen | 0:d2c9ddbc2cda | 78 | break; |
aimen | 0:d2c9ddbc2cda | 79 | case 2000000: |
aimen | 0:d2c9ddbc2cda | 80 | aux=7; |
aimen | 0:d2c9ddbc2cda | 81 | break; |
aimen | 0:d2c9ddbc2cda | 82 | default: |
aimen | 0:d2c9ddbc2cda | 83 | return 'F'; |
aimen | 0:d2c9ddbc2cda | 84 | } |
aimen | 0:d2c9ddbc2cda | 85 | _serialSMARTGPU.putc('X'); |
aimen | 0:d2c9ddbc2cda | 86 | _serialSMARTGPU.putc(aux); |
aimen | 0:d2c9ddbc2cda | 87 | aux=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 88 | if(aux=='O'){ |
aimen | 0:d2c9ddbc2cda | 89 | wait_ms(150); |
aimen | 0:d2c9ddbc2cda | 90 | _serialSMARTGPU.baud(val); |
aimen | 0:d2c9ddbc2cda | 91 | wait_ms(200); |
aimen | 0:d2c9ddbc2cda | 92 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 93 | }else{ |
aimen | 0:d2c9ddbc2cda | 94 | return aux; |
aimen | 0:d2c9ddbc2cda | 95 | } |
aimen | 0:d2c9ddbc2cda | 96 | } |
aimen | 0:d2c9ddbc2cda | 97 | |
aimen | 0:d2c9ddbc2cda | 98 | unsigned char SMARTGPU::digitalOut(unsigned char number, unsigned char val ){ //Set Digital out pins to a logic value |
aimen | 0:d2c9ddbc2cda | 99 | _serialSMARTGPU.putc('D'); |
aimen | 0:d2c9ddbc2cda | 100 | _serialSMARTGPU.putc(number); |
aimen | 0:d2c9ddbc2cda | 101 | _serialSMARTGPU.putc(val); |
aimen | 0:d2c9ddbc2cda | 102 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 103 | } |
aimen | 0:d2c9ddbc2cda | 104 | |
aimen | 0:d2c9ddbc2cda | 105 | unsigned char SMARTGPU::setScreenBackground(int colour){ //Change the default screen background colour for erase function |
aimen | 0:d2c9ddbc2cda | 106 | _serialSMARTGPU.putc('B'); |
aimen | 0:d2c9ddbc2cda | 107 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 108 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 109 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 110 | } |
aimen | 0:d2c9ddbc2cda | 111 | |
aimen | 0:d2c9ddbc2cda | 112 | unsigned char SMARTGPU::setTextBackground(int colour){ //Set the default text background colour for letters and strings |
aimen | 0:d2c9ddbc2cda | 113 | _serialSMARTGPU.putc('A'); |
aimen | 0:d2c9ddbc2cda | 114 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 115 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 116 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 117 | } |
aimen | 0:d2c9ddbc2cda | 118 | |
aimen | 0:d2c9ddbc2cda | 119 | unsigned char SMARTGPU::memoryRead(int x1, int y1, int x2, int y2, char buffer[]){ //Read the internal memory of the SMARTGPU, This command returns 24bit pixels (3 bytes) |
aimen | 0:d2c9ddbc2cda | 120 | unsigned int i,j,k=0; |
aimen | 0:d2c9ddbc2cda | 121 | |
aimen | 0:d2c9ddbc2cda | 122 | _serialSMARTGPU.putc('M'); |
aimen | 0:d2c9ddbc2cda | 123 | _serialSMARTGPU.putc(x1>>8); |
aimen | 0:d2c9ddbc2cda | 124 | _serialSMARTGPU.putc(x1); |
aimen | 0:d2c9ddbc2cda | 125 | _serialSMARTGPU.putc(y1>>8); |
aimen | 0:d2c9ddbc2cda | 126 | _serialSMARTGPU.putc(y1); |
aimen | 0:d2c9ddbc2cda | 127 | _serialSMARTGPU.putc(x2>>8); |
aimen | 0:d2c9ddbc2cda | 128 | _serialSMARTGPU.putc(x2); |
aimen | 0:d2c9ddbc2cda | 129 | _serialSMARTGPU.putc(y2>>8); |
aimen | 0:d2c9ddbc2cda | 130 | _serialSMARTGPU.putc(y2); |
aimen | 0:d2c9ddbc2cda | 131 | |
aimen | 0:d2c9ddbc2cda | 132 | //receive all the pixels |
aimen | 0:d2c9ddbc2cda | 133 | for(j=0;j<=(y2-y1);j++){ |
aimen | 0:d2c9ddbc2cda | 134 | for(i=0;i<=(x2-x1);i++){ |
aimen | 0:d2c9ddbc2cda | 135 | buffer[k]=_serialSMARTGPU.getc(); //Red |
aimen | 0:d2c9ddbc2cda | 136 | k++; |
aimen | 0:d2c9ddbc2cda | 137 | buffer[k]=_serialSMARTGPU.getc(); //Green |
aimen | 0:d2c9ddbc2cda | 138 | k++; |
aimen | 0:d2c9ddbc2cda | 139 | buffer[k]=_serialSMARTGPU.getc(); //Blue |
aimen | 0:d2c9ddbc2cda | 140 | k++; |
aimen | 0:d2c9ddbc2cda | 141 | } |
aimen | 0:d2c9ddbc2cda | 142 | } |
aimen | 0:d2c9ddbc2cda | 143 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 144 | } |
aimen | 0:d2c9ddbc2cda | 145 | |
aimen | 0:d2c9ddbc2cda | 146 | unsigned char SMARTGPU::putPixel(int x, int y, int colour){ //Draw a pixel on the screen |
aimen | 0:d2c9ddbc2cda | 147 | _serialSMARTGPU.putc('P'); |
aimen | 0:d2c9ddbc2cda | 148 | _serialSMARTGPU.putc(x>>8); |
aimen | 0:d2c9ddbc2cda | 149 | _serialSMARTGPU.putc(x); |
aimen | 0:d2c9ddbc2cda | 150 | _serialSMARTGPU.putc(y>>8); |
aimen | 0:d2c9ddbc2cda | 151 | _serialSMARTGPU.putc(y); |
aimen | 0:d2c9ddbc2cda | 152 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 153 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 154 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 155 | } |
aimen | 0:d2c9ddbc2cda | 156 | |
aimen | 0:d2c9ddbc2cda | 157 | unsigned char SMARTGPU::drawLine(int x1, int y1, int x2, int y2, int colour){ //Draw a line on the screen |
aimen | 0:d2c9ddbc2cda | 158 | _serialSMARTGPU.putc('L'); |
aimen | 0:d2c9ddbc2cda | 159 | _serialSMARTGPU.putc(x1>>8); |
aimen | 0:d2c9ddbc2cda | 160 | _serialSMARTGPU.putc(x1); |
aimen | 0:d2c9ddbc2cda | 161 | _serialSMARTGPU.putc(y1>>8); |
aimen | 0:d2c9ddbc2cda | 162 | _serialSMARTGPU.putc(y1); |
aimen | 0:d2c9ddbc2cda | 163 | _serialSMARTGPU.putc(x2>>8); |
aimen | 0:d2c9ddbc2cda | 164 | _serialSMARTGPU.putc(x2); |
aimen | 0:d2c9ddbc2cda | 165 | _serialSMARTGPU.putc(y2>>8); |
aimen | 0:d2c9ddbc2cda | 166 | _serialSMARTGPU.putc(y2); |
aimen | 0:d2c9ddbc2cda | 167 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 168 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 169 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 170 | } |
aimen | 0:d2c9ddbc2cda | 171 | |
aimen | 0:d2c9ddbc2cda | 172 | unsigned char SMARTGPU::drawRectangle(int x1, int y1, int x2, int y2, int colour, unsigned char fill){ //Draw a rectangle on the screen |
aimen | 0:d2c9ddbc2cda | 173 | _serialSMARTGPU.putc('R'); |
aimen | 0:d2c9ddbc2cda | 174 | _serialSMARTGPU.putc(x1>>8); |
aimen | 0:d2c9ddbc2cda | 175 | _serialSMARTGPU.putc(x1); |
aimen | 0:d2c9ddbc2cda | 176 | _serialSMARTGPU.putc(y1>>8); |
aimen | 0:d2c9ddbc2cda | 177 | _serialSMARTGPU.putc(y1); |
aimen | 0:d2c9ddbc2cda | 178 | _serialSMARTGPU.putc(x2>>8); |
aimen | 0:d2c9ddbc2cda | 179 | _serialSMARTGPU.putc(x2); |
aimen | 0:d2c9ddbc2cda | 180 | _serialSMARTGPU.putc(y2>>8); |
aimen | 0:d2c9ddbc2cda | 181 | _serialSMARTGPU.putc(y2); |
aimen | 0:d2c9ddbc2cda | 182 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 183 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 184 | _serialSMARTGPU.putc(fill); |
aimen | 0:d2c9ddbc2cda | 185 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 186 | } |
aimen | 0:d2c9ddbc2cda | 187 | |
aimen | 0:d2c9ddbc2cda | 188 | unsigned char SMARTGPU::drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int colour, unsigned char fill){ //Draw a triangle on the screen |
aimen | 0:d2c9ddbc2cda | 189 | _serialSMARTGPU.putc('T'); |
aimen | 0:d2c9ddbc2cda | 190 | _serialSMARTGPU.putc(x1>>8); |
aimen | 0:d2c9ddbc2cda | 191 | _serialSMARTGPU.putc(x1); |
aimen | 0:d2c9ddbc2cda | 192 | _serialSMARTGPU.putc(y1>>8); |
aimen | 0:d2c9ddbc2cda | 193 | _serialSMARTGPU.putc(y1); |
aimen | 0:d2c9ddbc2cda | 194 | _serialSMARTGPU.putc(x2>>8); |
aimen | 0:d2c9ddbc2cda | 195 | _serialSMARTGPU.putc(x2); |
aimen | 0:d2c9ddbc2cda | 196 | _serialSMARTGPU.putc(y2>>8); |
aimen | 0:d2c9ddbc2cda | 197 | _serialSMARTGPU.putc(y2); |
aimen | 0:d2c9ddbc2cda | 198 | _serialSMARTGPU.putc(x3>>8); |
aimen | 0:d2c9ddbc2cda | 199 | _serialSMARTGPU.putc(x3); |
aimen | 0:d2c9ddbc2cda | 200 | _serialSMARTGPU.putc(y3>>8); |
aimen | 0:d2c9ddbc2cda | 201 | _serialSMARTGPU.putc(y3); |
aimen | 0:d2c9ddbc2cda | 202 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 203 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 204 | _serialSMARTGPU.putc(fill); |
aimen | 0:d2c9ddbc2cda | 205 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 206 | } |
aimen | 0:d2c9ddbc2cda | 207 | |
aimen | 0:d2c9ddbc2cda | 208 | unsigned char SMARTGPU::drawCircle(int x, int y, int radius, int colour, unsigned char fill){ //Draw a circle on the screen |
aimen | 0:d2c9ddbc2cda | 209 | _serialSMARTGPU.putc('C'); |
aimen | 0:d2c9ddbc2cda | 210 | _serialSMARTGPU.putc(x>>8); |
aimen | 0:d2c9ddbc2cda | 211 | _serialSMARTGPU.putc(x); |
aimen | 0:d2c9ddbc2cda | 212 | _serialSMARTGPU.putc(y>>8); |
aimen | 0:d2c9ddbc2cda | 213 | _serialSMARTGPU.putc(y); |
aimen | 0:d2c9ddbc2cda | 214 | _serialSMARTGPU.putc(radius>>8); |
aimen | 0:d2c9ddbc2cda | 215 | _serialSMARTGPU.putc(radius); |
aimen | 0:d2c9ddbc2cda | 216 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 217 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 218 | _serialSMARTGPU.putc(fill); |
aimen | 0:d2c9ddbc2cda | 219 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 220 | } |
aimen | 0:d2c9ddbc2cda | 221 | |
aimen | 0:d2c9ddbc2cda | 222 | unsigned char SMARTGPU::putLetter(int x, int y, int colour, unsigned char font, unsigned char fill, unsigned char letter){ //Draw a letter on the screen |
aimen | 0:d2c9ddbc2cda | 223 | |
aimen | 0:d2c9ddbc2cda | 224 | _serialSMARTGPU.putc('W'); |
aimen | 0:d2c9ddbc2cda | 225 | _serialSMARTGPU.putc(x>>8); |
aimen | 0:d2c9ddbc2cda | 226 | _serialSMARTGPU.putc(x); |
aimen | 0:d2c9ddbc2cda | 227 | _serialSMARTGPU.putc(y>>8); |
aimen | 0:d2c9ddbc2cda | 228 | _serialSMARTGPU.putc(y); |
aimen | 0:d2c9ddbc2cda | 229 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 230 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 231 | _serialSMARTGPU.putc(font); |
aimen | 0:d2c9ddbc2cda | 232 | _serialSMARTGPU.putc(fill); |
aimen | 0:d2c9ddbc2cda | 233 | _serialSMARTGPU.putc(letter); |
aimen | 0:d2c9ddbc2cda | 234 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 235 | } |
aimen | 0:d2c9ddbc2cda | 236 | |
aimen | 0:d2c9ddbc2cda | 237 | unsigned char SMARTGPU::string(int x1, int y1, int x2, int y2, int colour, unsigned char font, unsigned char fill, char text[]){ //Draw a string on the screen |
aimen | 0:d2c9ddbc2cda | 238 | int counter=0; |
aimen | 0:d2c9ddbc2cda | 239 | |
aimen | 0:d2c9ddbc2cda | 240 | _serialSMARTGPU.putc('S'); |
aimen | 0:d2c9ddbc2cda | 241 | _serialSMARTGPU.putc('N'); //not SD |
aimen | 0:d2c9ddbc2cda | 242 | _serialSMARTGPU.putc(x1>>8); |
aimen | 0:d2c9ddbc2cda | 243 | _serialSMARTGPU.putc(x1); |
aimen | 0:d2c9ddbc2cda | 244 | _serialSMARTGPU.putc(y1>>8); |
aimen | 0:d2c9ddbc2cda | 245 | _serialSMARTGPU.putc(y1); |
aimen | 0:d2c9ddbc2cda | 246 | _serialSMARTGPU.putc(x2>>8); |
aimen | 0:d2c9ddbc2cda | 247 | _serialSMARTGPU.putc(x2); |
aimen | 0:d2c9ddbc2cda | 248 | _serialSMARTGPU.putc(y2>>8); |
aimen | 0:d2c9ddbc2cda | 249 | _serialSMARTGPU.putc(y2); |
aimen | 0:d2c9ddbc2cda | 250 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 251 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 252 | _serialSMARTGPU.putc(font); |
aimen | 0:d2c9ddbc2cda | 253 | _serialSMARTGPU.putc(fill); |
aimen | 0:d2c9ddbc2cda | 254 | while(1){ |
aimen | 0:d2c9ddbc2cda | 255 | _serialSMARTGPU.putc(text[counter]); |
aimen | 0:d2c9ddbc2cda | 256 | if(text[counter]==0x00){ |
aimen | 0:d2c9ddbc2cda | 257 | break; |
aimen | 0:d2c9ddbc2cda | 258 | } |
aimen | 0:d2c9ddbc2cda | 259 | counter++; |
aimen | 0:d2c9ddbc2cda | 260 | } |
aimen | 0:d2c9ddbc2cda | 261 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 262 | } |
aimen | 0:d2c9ddbc2cda | 263 | |
aimen | 0:d2c9ddbc2cda | 264 | unsigned char SMARTGPU::stringSD(int x1, int y1, int x2, int y2, int colour, unsigned char font, unsigned char fill, int BS, int BR, char name[]){ //Draw a String from a text file contained on the micro SD card on the screen |
aimen | 0:d2c9ddbc2cda | 265 | unsigned char counter=0; |
aimen | 0:d2c9ddbc2cda | 266 | |
aimen | 0:d2c9ddbc2cda | 267 | _serialSMARTGPU.putc('S'); |
aimen | 0:d2c9ddbc2cda | 268 | _serialSMARTGPU.putc('S'); //from SD |
aimen | 0:d2c9ddbc2cda | 269 | _serialSMARTGPU.putc(x1>>8); |
aimen | 0:d2c9ddbc2cda | 270 | _serialSMARTGPU.putc(x1); |
aimen | 0:d2c9ddbc2cda | 271 | _serialSMARTGPU.putc(y1>>8); |
aimen | 0:d2c9ddbc2cda | 272 | _serialSMARTGPU.putc(y1); |
aimen | 0:d2c9ddbc2cda | 273 | _serialSMARTGPU.putc(x2>>8); |
aimen | 0:d2c9ddbc2cda | 274 | _serialSMARTGPU.putc(x2); |
aimen | 0:d2c9ddbc2cda | 275 | _serialSMARTGPU.putc(y2>>8); |
aimen | 0:d2c9ddbc2cda | 276 | _serialSMARTGPU.putc(y2); |
aimen | 0:d2c9ddbc2cda | 277 | _serialSMARTGPU.putc(colour>>8); |
aimen | 0:d2c9ddbc2cda | 278 | _serialSMARTGPU.putc(colour); |
aimen | 0:d2c9ddbc2cda | 279 | _serialSMARTGPU.putc(font); |
aimen | 0:d2c9ddbc2cda | 280 | _serialSMARTGPU.putc(fill); |
aimen | 0:d2c9ddbc2cda | 281 | _serialSMARTGPU.putc(BS>>8); |
aimen | 0:d2c9ddbc2cda | 282 | _serialSMARTGPU.putc(BS); |
aimen | 0:d2c9ddbc2cda | 283 | _serialSMARTGPU.putc(BR>>8); |
aimen | 0:d2c9ddbc2cda | 284 | _serialSMARTGPU.putc(BR); |
aimen | 0:d2c9ddbc2cda | 285 | while(1){ |
aimen | 0:d2c9ddbc2cda | 286 | _serialSMARTGPU.putc(name[counter]); |
aimen | 0:d2c9ddbc2cda | 287 | if(name[counter]==0x00){ |
aimen | 0:d2c9ddbc2cda | 288 | break; |
aimen | 0:d2c9ddbc2cda | 289 | } |
aimen | 0:d2c9ddbc2cda | 290 | counter++; |
aimen | 0:d2c9ddbc2cda | 291 | } |
aimen | 0:d2c9ddbc2cda | 292 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 293 | } |
aimen | 0:d2c9ddbc2cda | 294 | |
aimen | 0:d2c9ddbc2cda | 295 | unsigned char SMARTGPU::icon(int x1, int y1, int x2, int y2, char icon[]){ //Send and image or icon pixel by pixel to SMARTGPU, 16bit(2 bytes) each pixel RGB565 |
aimen | 0:d2c9ddbc2cda | 296 | unsigned int i,j,k=0; |
aimen | 0:d2c9ddbc2cda | 297 | |
aimen | 0:d2c9ddbc2cda | 298 | _serialSMARTGPU.putc('I'); |
aimen | 0:d2c9ddbc2cda | 299 | _serialSMARTGPU.putc('N'); //not SD |
aimen | 0:d2c9ddbc2cda | 300 | _serialSMARTGPU.putc(x1>>8); |
aimen | 0:d2c9ddbc2cda | 301 | _serialSMARTGPU.putc(x1); |
aimen | 0:d2c9ddbc2cda | 302 | _serialSMARTGPU.putc(y1>>8); |
aimen | 0:d2c9ddbc2cda | 303 | _serialSMARTGPU.putc(y1); |
aimen | 0:d2c9ddbc2cda | 304 | _serialSMARTGPU.putc(x2>>8); |
aimen | 0:d2c9ddbc2cda | 305 | _serialSMARTGPU.putc(x2); |
aimen | 0:d2c9ddbc2cda | 306 | _serialSMARTGPU.putc(y2>>8); |
aimen | 0:d2c9ddbc2cda | 307 | _serialSMARTGPU.putc(y2); |
aimen | 0:d2c9ddbc2cda | 308 | |
aimen | 0:d2c9ddbc2cda | 309 | //Send icon buffer pixel by pixel |
aimen | 0:d2c9ddbc2cda | 310 | for(j=0;j<=(y2-y1);j++){ |
aimen | 0:d2c9ddbc2cda | 311 | for(i=0;i<=(x2-x1);i++){ |
aimen | 0:d2c9ddbc2cda | 312 | _serialSMARTGPU.putc(icon[k]); |
aimen | 0:d2c9ddbc2cda | 313 | k++; |
aimen | 0:d2c9ddbc2cda | 314 | } |
aimen | 0:d2c9ddbc2cda | 315 | } |
aimen | 0:d2c9ddbc2cda | 316 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 317 | } |
aimen | 0:d2c9ddbc2cda | 318 | |
aimen | 0:d2c9ddbc2cda | 319 | unsigned char SMARTGPU::imageSD(int x, int y, char name[]){ //Draw an Image contained on the micro SD card on the screen, top left corner coordinates |
aimen | 0:d2c9ddbc2cda | 320 | unsigned char counter=0; |
aimen | 0:d2c9ddbc2cda | 321 | |
aimen | 0:d2c9ddbc2cda | 322 | _serialSMARTGPU.putc('I'); |
aimen | 0:d2c9ddbc2cda | 323 | _serialSMARTGPU.putc('S'); //from SD |
aimen | 0:d2c9ddbc2cda | 324 | _serialSMARTGPU.putc(x>>8); |
aimen | 0:d2c9ddbc2cda | 325 | _serialSMARTGPU.putc(x); |
aimen | 0:d2c9ddbc2cda | 326 | _serialSMARTGPU.putc(y>>8); |
aimen | 0:d2c9ddbc2cda | 327 | _serialSMARTGPU.putc(y); |
aimen | 0:d2c9ddbc2cda | 328 | while(1){ |
aimen | 0:d2c9ddbc2cda | 329 | _serialSMARTGPU.putc(name[counter]); |
aimen | 0:d2c9ddbc2cda | 330 | if(name[counter]==0x00){ |
aimen | 0:d2c9ddbc2cda | 331 | break; |
aimen | 0:d2c9ddbc2cda | 332 | } |
aimen | 0:d2c9ddbc2cda | 333 | counter++; |
aimen | 0:d2c9ddbc2cda | 334 | } |
aimen | 0:d2c9ddbc2cda | 335 | return _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 336 | } |
aimen | 0:d2c9ddbc2cda | 337 | |
aimen | 0:d2c9ddbc2cda | 338 | unsigned char SMARTGPU::touchScreen(int buffer[]){ //Ask for a touch on the screen, if return=1, touch coordinates are stored on the buffer[] |
aimen | 0:d2c9ddbc2cda | 339 | |
aimen | 0:d2c9ddbc2cda | 340 | _serialSMARTGPU.putc('G'); |
aimen | 0:d2c9ddbc2cda | 341 | buffer[0]=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 342 | buffer[0]=buffer[0]<<8; |
aimen | 0:d2c9ddbc2cda | 343 | buffer[0]|=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 344 | buffer[1]=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 345 | buffer[1]=buffer[1]<<8; |
aimen | 0:d2c9ddbc2cda | 346 | buffer[1]|=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 347 | _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 348 | if(buffer[0]<0x0200){ |
aimen | 0:d2c9ddbc2cda | 349 | return 1; |
aimen | 0:d2c9ddbc2cda | 350 | }else{ |
aimen | 0:d2c9ddbc2cda | 351 | return 0; |
aimen | 0:d2c9ddbc2cda | 352 | } |
aimen | 0:d2c9ddbc2cda | 353 | } |
aimen | 0:d2c9ddbc2cda | 354 | |
aimen | 0:d2c9ddbc2cda | 355 | unsigned char SMARTGPU::touchIcon(char buffer[]){ //Ask for a touch on the icons of the screen, if return=1, icon name is stored on the buffer[] |
aimen | 0:d2c9ddbc2cda | 356 | |
aimen | 0:d2c9ddbc2cda | 357 | _serialSMARTGPU.putc('G'); |
aimen | 0:d2c9ddbc2cda | 358 | buffer[0]=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 359 | buffer[1]=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 360 | buffer[2]=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 361 | buffer[3]=_serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 362 | _serialSMARTGPU.getc(); |
aimen | 0:d2c9ddbc2cda | 363 | if(!(buffer[0]<0x02) & (buffer[0]!=0x4E)){ |
aimen | 0:d2c9ddbc2cda | 364 | return 1; |
aimen | 0:d2c9ddbc2cda | 365 | }else{ |
aimen | 0:d2c9ddbc2cda | 366 | return 0; |
aimen | 0:d2c9ddbc2cda | 367 | } |
aimen | 0:d2c9ddbc2cda | 368 | } |