Finished Lab 4 Pt 1

Dependencies:   mbed Sounds PinDetect

Committer:
trmontgomery
Date:
Fri Apr 05 19:46:26 2019 +0000
Revision:
0:daf9e2f8e1a1
Finished Lab 4 pt 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trmontgomery 0:daf9e2f8e1a1 1 //
trmontgomery 0:daf9e2f8e1a1 2 // uLCD_4DGL is a class to drive 4D Systems LCD screens
trmontgomery 0:daf9e2f8e1a1 3 //
trmontgomery 0:daf9e2f8e1a1 4 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
trmontgomery 0:daf9e2f8e1a1 5 // Modifed for Goldelox processor <2013> Jim Hamblen
trmontgomery 0:daf9e2f8e1a1 6 //
trmontgomery 0:daf9e2f8e1a1 7 // uLCD_4DGL is free software: you can redistribute it and/or modify
trmontgomery 0:daf9e2f8e1a1 8 // it under the terms of the GNU General Public License as published by
trmontgomery 0:daf9e2f8e1a1 9 // the Free Software Foundation, either version 3 of the License, or
trmontgomery 0:daf9e2f8e1a1 10 // (at your option) any later version.
trmontgomery 0:daf9e2f8e1a1 11 //
trmontgomery 0:daf9e2f8e1a1 12 // uLCD_4DGL is distributed in the hope that it will be useful,
trmontgomery 0:daf9e2f8e1a1 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
trmontgomery 0:daf9e2f8e1a1 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
trmontgomery 0:daf9e2f8e1a1 15 // GNU General Public License for more details.
trmontgomery 0:daf9e2f8e1a1 16 //
trmontgomery 0:daf9e2f8e1a1 17 // You should have received a copy of the GNU General Public License
trmontgomery 0:daf9e2f8e1a1 18 // along with uLCD_4DGL. If not, see <http://www.gnu.org/licenses/>.
trmontgomery 0:daf9e2f8e1a1 19
trmontgomery 0:daf9e2f8e1a1 20 #include "mbed.h"
trmontgomery 0:daf9e2f8e1a1 21 #include "uLCD_4DGL.h"
trmontgomery 0:daf9e2f8e1a1 22
trmontgomery 0:daf9e2f8e1a1 23 #define ARRAY_SIZE(X) sizeof(X)/sizeof(X[0])
trmontgomery 0:daf9e2f8e1a1 24
trmontgomery 0:daf9e2f8e1a1 25 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 26 void uLCD_4DGL :: circle(int x, int y , int radius, int color) // draw a circle in (x,y)
trmontgomery 0:daf9e2f8e1a1 27 {
trmontgomery 0:daf9e2f8e1a1 28 char command[9]= "";
trmontgomery 0:daf9e2f8e1a1 29
trmontgomery 0:daf9e2f8e1a1 30 command[0] = CIRCLE;
trmontgomery 0:daf9e2f8e1a1 31
trmontgomery 0:daf9e2f8e1a1 32 command[1] = (x >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 33 command[2] = x & 0xFF;
trmontgomery 0:daf9e2f8e1a1 34
trmontgomery 0:daf9e2f8e1a1 35 command[3] = (y >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 36 command[4] = y & 0xFF;
trmontgomery 0:daf9e2f8e1a1 37
trmontgomery 0:daf9e2f8e1a1 38 command[5] = (radius >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 39 command[6] = radius & 0xFF;
trmontgomery 0:daf9e2f8e1a1 40
trmontgomery 0:daf9e2f8e1a1 41 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
trmontgomery 0:daf9e2f8e1a1 42 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
trmontgomery 0:daf9e2f8e1a1 43 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
trmontgomery 0:daf9e2f8e1a1 44
trmontgomery 0:daf9e2f8e1a1 45 command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 46 command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 47
trmontgomery 0:daf9e2f8e1a1 48 writeCOMMAND(command, 9);
trmontgomery 0:daf9e2f8e1a1 49 }
trmontgomery 0:daf9e2f8e1a1 50 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 51 void uLCD_4DGL :: filled_circle(int x, int y , int radius, int color) // draw a circle in (x,y)
trmontgomery 0:daf9e2f8e1a1 52 {
trmontgomery 0:daf9e2f8e1a1 53 char command[9]= "";
trmontgomery 0:daf9e2f8e1a1 54
trmontgomery 0:daf9e2f8e1a1 55 command[0] = FCIRCLE;
trmontgomery 0:daf9e2f8e1a1 56
trmontgomery 0:daf9e2f8e1a1 57 command[1] = (x >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 58 command[2] = x & 0xFF;
trmontgomery 0:daf9e2f8e1a1 59
trmontgomery 0:daf9e2f8e1a1 60 command[3] = (y >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 61 command[4] = y & 0xFF;
trmontgomery 0:daf9e2f8e1a1 62
trmontgomery 0:daf9e2f8e1a1 63 command[5] = (radius >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 64 command[6] = radius & 0xFF;
trmontgomery 0:daf9e2f8e1a1 65
trmontgomery 0:daf9e2f8e1a1 66 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
trmontgomery 0:daf9e2f8e1a1 67 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
trmontgomery 0:daf9e2f8e1a1 68 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
trmontgomery 0:daf9e2f8e1a1 69
trmontgomery 0:daf9e2f8e1a1 70 command[7] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 71 command[8] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 72
trmontgomery 0:daf9e2f8e1a1 73 writeCOMMAND(command, 9);
trmontgomery 0:daf9e2f8e1a1 74 }
trmontgomery 0:daf9e2f8e1a1 75
trmontgomery 0:daf9e2f8e1a1 76 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 77 void uLCD_4DGL :: triangle(int x1, int y1 , int x2, int y2, int x3, int y3, int color) // draw a traingle
trmontgomery 0:daf9e2f8e1a1 78 {
trmontgomery 0:daf9e2f8e1a1 79 char command[15]= "";
trmontgomery 0:daf9e2f8e1a1 80
trmontgomery 0:daf9e2f8e1a1 81 command[0] = TRIANGLE;
trmontgomery 0:daf9e2f8e1a1 82
trmontgomery 0:daf9e2f8e1a1 83 command[1] = (x1 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 84 command[2] = x1 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 85
trmontgomery 0:daf9e2f8e1a1 86 command[3] = (y1 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 87 command[4] = y1 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 88
trmontgomery 0:daf9e2f8e1a1 89 command[5] = (x2 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 90 command[6] = x2 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 91
trmontgomery 0:daf9e2f8e1a1 92 command[7] = (y2 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 93 command[8] = y2 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 94
trmontgomery 0:daf9e2f8e1a1 95 command[9] = (x3 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 96 command[10] = x3 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 97
trmontgomery 0:daf9e2f8e1a1 98 command[11] = (y3 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 99 command[12] = y3 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 100
trmontgomery 0:daf9e2f8e1a1 101 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
trmontgomery 0:daf9e2f8e1a1 102 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
trmontgomery 0:daf9e2f8e1a1 103 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
trmontgomery 0:daf9e2f8e1a1 104
trmontgomery 0:daf9e2f8e1a1 105 command[13] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 106 command[14] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 107
trmontgomery 0:daf9e2f8e1a1 108 writeCOMMAND(command, 15);
trmontgomery 0:daf9e2f8e1a1 109 }
trmontgomery 0:daf9e2f8e1a1 110
trmontgomery 0:daf9e2f8e1a1 111 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 112 void uLCD_4DGL :: line(int x1, int y1 , int x2, int y2, int color) // draw a line
trmontgomery 0:daf9e2f8e1a1 113 {
trmontgomery 0:daf9e2f8e1a1 114 char command[11]= "";
trmontgomery 0:daf9e2f8e1a1 115
trmontgomery 0:daf9e2f8e1a1 116 command[0] = LINE;
trmontgomery 0:daf9e2f8e1a1 117
trmontgomery 0:daf9e2f8e1a1 118 command[1] = (x1 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 119 command[2] = x1 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 120
trmontgomery 0:daf9e2f8e1a1 121 command[3] = (y1 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 122 command[4] = y1 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 123
trmontgomery 0:daf9e2f8e1a1 124 command[5] = (x2 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 125 command[6] = x2 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 126
trmontgomery 0:daf9e2f8e1a1 127 command[7] = (y2 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 128 command[8] = y2 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 129
trmontgomery 0:daf9e2f8e1a1 130 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
trmontgomery 0:daf9e2f8e1a1 131 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
trmontgomery 0:daf9e2f8e1a1 132 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
trmontgomery 0:daf9e2f8e1a1 133
trmontgomery 0:daf9e2f8e1a1 134 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 135 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 136
trmontgomery 0:daf9e2f8e1a1 137 writeCOMMAND(command, 11);
trmontgomery 0:daf9e2f8e1a1 138 }
trmontgomery 0:daf9e2f8e1a1 139
trmontgomery 0:daf9e2f8e1a1 140 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 141 void uLCD_4DGL :: rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle
trmontgomery 0:daf9e2f8e1a1 142 {
trmontgomery 0:daf9e2f8e1a1 143 char command[11]= "";
trmontgomery 0:daf9e2f8e1a1 144
trmontgomery 0:daf9e2f8e1a1 145 command[0] = RECTANGLE;
trmontgomery 0:daf9e2f8e1a1 146
trmontgomery 0:daf9e2f8e1a1 147 command[1] = (x1 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 148 command[2] = x1 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 149
trmontgomery 0:daf9e2f8e1a1 150 command[3] = (y1 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 151 command[4] = y1 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 152
trmontgomery 0:daf9e2f8e1a1 153 command[5] = (x2 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 154 command[6] = x2 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 155
trmontgomery 0:daf9e2f8e1a1 156 command[7] = (y2 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 157 command[8] = y2 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 158
trmontgomery 0:daf9e2f8e1a1 159 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
trmontgomery 0:daf9e2f8e1a1 160 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
trmontgomery 0:daf9e2f8e1a1 161 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
trmontgomery 0:daf9e2f8e1a1 162
trmontgomery 0:daf9e2f8e1a1 163 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 164 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 165
trmontgomery 0:daf9e2f8e1a1 166 writeCOMMAND(command, 11);
trmontgomery 0:daf9e2f8e1a1 167 }
trmontgomery 0:daf9e2f8e1a1 168
trmontgomery 0:daf9e2f8e1a1 169 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 170 void uLCD_4DGL :: filled_rectangle(int x1, int y1 , int x2, int y2, int color) // draw a rectangle
trmontgomery 0:daf9e2f8e1a1 171 {
trmontgomery 0:daf9e2f8e1a1 172 char command[11]= "";
trmontgomery 0:daf9e2f8e1a1 173
trmontgomery 0:daf9e2f8e1a1 174 command[0] = FRECTANGLE;
trmontgomery 0:daf9e2f8e1a1 175
trmontgomery 0:daf9e2f8e1a1 176 command[1] = (x1 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 177 command[2] = x1 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 178
trmontgomery 0:daf9e2f8e1a1 179 command[3] = (y1 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 180 command[4] = y1 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 181
trmontgomery 0:daf9e2f8e1a1 182 command[5] = (x2 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 183 command[6] = x2 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 184
trmontgomery 0:daf9e2f8e1a1 185 command[7] = (y2 >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 186 command[8] = y2 & 0xFF;
trmontgomery 0:daf9e2f8e1a1 187
trmontgomery 0:daf9e2f8e1a1 188 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
trmontgomery 0:daf9e2f8e1a1 189 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
trmontgomery 0:daf9e2f8e1a1 190 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
trmontgomery 0:daf9e2f8e1a1 191
trmontgomery 0:daf9e2f8e1a1 192 command[9] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 193 command[10] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 194
trmontgomery 0:daf9e2f8e1a1 195 writeCOMMAND(command, 11);
trmontgomery 0:daf9e2f8e1a1 196 }
trmontgomery 0:daf9e2f8e1a1 197
trmontgomery 0:daf9e2f8e1a1 198
trmontgomery 0:daf9e2f8e1a1 199
trmontgomery 0:daf9e2f8e1a1 200 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 201 void uLCD_4DGL :: pixel(int x, int y, int color) // draw a pixel
trmontgomery 0:daf9e2f8e1a1 202 {
trmontgomery 0:daf9e2f8e1a1 203 char command[7]= "";
trmontgomery 0:daf9e2f8e1a1 204
trmontgomery 0:daf9e2f8e1a1 205 command[0] = PIXEL;
trmontgomery 0:daf9e2f8e1a1 206
trmontgomery 0:daf9e2f8e1a1 207 command[1] = (x >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 208 command[2] = x & 0xFF;
trmontgomery 0:daf9e2f8e1a1 209
trmontgomery 0:daf9e2f8e1a1 210 command[3] = (y >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 211 command[4] = y & 0xFF;
trmontgomery 0:daf9e2f8e1a1 212
trmontgomery 0:daf9e2f8e1a1 213 int red5 = (color >> (16 + 3)) & 0x1F; // get red on 5 bits
trmontgomery 0:daf9e2f8e1a1 214 int green6 = (color >> (8 + 2)) & 0x3F; // get green on 6 bits
trmontgomery 0:daf9e2f8e1a1 215 int blue5 = (color >> (0 + 3)) & 0x1F; // get blue on 5 bits
trmontgomery 0:daf9e2f8e1a1 216
trmontgomery 0:daf9e2f8e1a1 217 command[5] = ((red5 << 3) + (green6 >> 3)) & 0xFF; // first part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 218 command[6] = ((green6 << 5) + (blue5 >> 0)) & 0xFF; // second part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 219
trmontgomery 0:daf9e2f8e1a1 220 writeCOMMAND(command, 7);
trmontgomery 0:daf9e2f8e1a1 221 }
trmontgomery 0:daf9e2f8e1a1 222 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 223 void uLCD_4DGL :: BLIT(int x, int y, int w, int h, const int *colors) // draw a block of pixels
trmontgomery 0:daf9e2f8e1a1 224 {
trmontgomery 0:daf9e2f8e1a1 225 int red5, green6, blue5;
trmontgomery 0:daf9e2f8e1a1 226 writeBYTEfast('\x00');
trmontgomery 0:daf9e2f8e1a1 227 writeBYTEfast(BLITCOM);
trmontgomery 0:daf9e2f8e1a1 228 writeBYTEfast((x >> 8) & 0xFF);
trmontgomery 0:daf9e2f8e1a1 229 writeBYTEfast(x & 0xFF);
trmontgomery 0:daf9e2f8e1a1 230 writeBYTEfast((y >> 8) & 0xFF);
trmontgomery 0:daf9e2f8e1a1 231 writeBYTEfast(y & 0xFF);
trmontgomery 0:daf9e2f8e1a1 232 writeBYTEfast((w >> 8) & 0xFF);
trmontgomery 0:daf9e2f8e1a1 233 writeBYTE(w & 0xFF);
trmontgomery 0:daf9e2f8e1a1 234 writeBYTE((h >> 8) & 0xFF);
trmontgomery 0:daf9e2f8e1a1 235 writeBYTE(h & 0xFF);
trmontgomery 0:daf9e2f8e1a1 236 wait_ms(1);
trmontgomery 0:daf9e2f8e1a1 237 for (int i=0; i<w*h; i++) {
trmontgomery 0:daf9e2f8e1a1 238 red5 = (colors[i] >> (16 + 3)) & 0x1F; // get red on 5 bits
trmontgomery 0:daf9e2f8e1a1 239 green6 = (colors[i] >> (8 + 2)) & 0x3F; // get green on 6 bits
trmontgomery 0:daf9e2f8e1a1 240 blue5 = (colors[i] >> (0 + 3)) & 0x1F; // get blue on 5 bits
trmontgomery 0:daf9e2f8e1a1 241 writeBYTEfast(((red5 << 3) + (green6 >> 3)) & 0xFF); // first part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 242 writeBYTEfast(((green6 << 5) + (blue5 >> 0)) & 0xFF); // second part of 16 bits color
trmontgomery 0:daf9e2f8e1a1 243 }
trmontgomery 0:daf9e2f8e1a1 244 int resp=0;
trmontgomery 0:daf9e2f8e1a1 245 while (!_cmd.readable()) wait_ms(TEMPO); // wait for screen answer
trmontgomery 0:daf9e2f8e1a1 246 if (_cmd.readable()) resp = _cmd.getc(); // read response if any
trmontgomery 0:daf9e2f8e1a1 247 switch (resp) {
trmontgomery 0:daf9e2f8e1a1 248 case ACK : // if OK return 1
trmontgomery 0:daf9e2f8e1a1 249 resp = 1;
trmontgomery 0:daf9e2f8e1a1 250 break;
trmontgomery 0:daf9e2f8e1a1 251 case NAK : // if NOK return -1
trmontgomery 0:daf9e2f8e1a1 252 resp = -1;
trmontgomery 0:daf9e2f8e1a1 253 break;
trmontgomery 0:daf9e2f8e1a1 254 default :
trmontgomery 0:daf9e2f8e1a1 255 resp = 0; // else return 0
trmontgomery 0:daf9e2f8e1a1 256 break;
trmontgomery 0:daf9e2f8e1a1 257 }
trmontgomery 0:daf9e2f8e1a1 258 #if DEBUGMODE
trmontgomery 0:daf9e2f8e1a1 259 pc.printf(" Answer received : %d\n",resp);
trmontgomery 0:daf9e2f8e1a1 260 #endif
trmontgomery 0:daf9e2f8e1a1 261
trmontgomery 0:daf9e2f8e1a1 262 }
trmontgomery 0:daf9e2f8e1a1 263 //******************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 264 int uLCD_4DGL :: read_pixel(int x, int y) // read screen info and populate data
trmontgomery 0:daf9e2f8e1a1 265 {
trmontgomery 0:daf9e2f8e1a1 266
trmontgomery 0:daf9e2f8e1a1 267 char command[6]= "";
trmontgomery 0:daf9e2f8e1a1 268 command[0] = 0xFF;
trmontgomery 0:daf9e2f8e1a1 269 command[1] = READPIXEL;
trmontgomery 0:daf9e2f8e1a1 270
trmontgomery 0:daf9e2f8e1a1 271 command[2] = (x >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 272 command[3] = x & 0xFF;
trmontgomery 0:daf9e2f8e1a1 273
trmontgomery 0:daf9e2f8e1a1 274 command[4] = (y >> 8) & 0xFF;
trmontgomery 0:daf9e2f8e1a1 275 command[5] = y & 0xFF;
trmontgomery 0:daf9e2f8e1a1 276
trmontgomery 0:daf9e2f8e1a1 277 int i, temp = 0, color = 0, resp = 0;
trmontgomery 0:daf9e2f8e1a1 278 char response[3] = "";
trmontgomery 0:daf9e2f8e1a1 279
trmontgomery 0:daf9e2f8e1a1 280 freeBUFFER();
trmontgomery 0:daf9e2f8e1a1 281
trmontgomery 0:daf9e2f8e1a1 282 for (i = 0; i < 6; i++) { // send all chars to serial port
trmontgomery 0:daf9e2f8e1a1 283 writeBYTE(command[i]);
trmontgomery 0:daf9e2f8e1a1 284 }
trmontgomery 0:daf9e2f8e1a1 285
trmontgomery 0:daf9e2f8e1a1 286 while (!_cmd.readable()) wait_ms(TEMPO); // wait a bit for screen answer
trmontgomery 0:daf9e2f8e1a1 287
trmontgomery 0:daf9e2f8e1a1 288 while ( resp < ARRAY_SIZE(response)) { //read ack and 16-bit color response
trmontgomery 0:daf9e2f8e1a1 289 temp = _cmd.getc();
trmontgomery 0:daf9e2f8e1a1 290 response[resp++] = (char)temp;
trmontgomery 0:daf9e2f8e1a1 291 }
trmontgomery 0:daf9e2f8e1a1 292
trmontgomery 0:daf9e2f8e1a1 293 color = ((response[1] << 8) + response[2]);
trmontgomery 0:daf9e2f8e1a1 294
trmontgomery 0:daf9e2f8e1a1 295 return color;
trmontgomery 0:daf9e2f8e1a1 296 }
trmontgomery 0:daf9e2f8e1a1 297
trmontgomery 0:daf9e2f8e1a1 298
trmontgomery 0:daf9e2f8e1a1 299 //****************************************************************************************************
trmontgomery 0:daf9e2f8e1a1 300 void uLCD_4DGL :: pen_size(char mode) // set pen to SOLID or WIREFRAME
trmontgomery 0:daf9e2f8e1a1 301 {
trmontgomery 0:daf9e2f8e1a1 302 char command[2]= "";
trmontgomery 0:daf9e2f8e1a1 303
trmontgomery 0:daf9e2f8e1a1 304 command[0] = PENSIZE;
trmontgomery 0:daf9e2f8e1a1 305 command[1] = mode;
trmontgomery 0:daf9e2f8e1a1 306 writeCOMMAND(command, 2);
trmontgomery 0:daf9e2f8e1a1 307 }
trmontgomery 0:daf9e2f8e1a1 308
trmontgomery 0:daf9e2f8e1a1 309
trmontgomery 0:daf9e2f8e1a1 310
trmontgomery 0:daf9e2f8e1a1 311