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