4D systems Picaso uLCD 32PTU touch display library

Committer:
CaptainR
Date:
Mon Sep 12 12:12:09 2016 +0000
Revision:
8:b634ac9c92f8
Parent:
7:f064ae670553
Child:
9:32eb75c01e9d
lineTo() not setting origin point after drawing a line

Who changed what in which revision?

UserRevisionLine numberNew contents of line
CaptainR 1:e2337e2653e1 1 //
CaptainR 2:81eaaa491a02 2 // Picaso_4DGL-32PTU is a class to drive 4D Systems TFT touch screens with PICASO processor
CaptainR 2:81eaaa491a02 3 // Tested with NUCLEO L152RE development board
CaptainR 2:81eaaa491a02 4 // Copyright (C) <2016> Rihards Balass <rihards.balass@gmail.com>
CaptainR 1:e2337e2653e1 5 //
CaptainR 2:81eaaa491a02 6 // Picaso_4DGL-32PTU is free software: you can redistribute it and/or modify
CaptainR 2:81eaaa491a02 7 // it under the terms of the GNU General Public License as published by
CaptainR 2:81eaaa491a02 8 // the Free Software Foundation, either version 3 of the License, or
CaptainR 2:81eaaa491a02 9 // (at your option) any later version.
CaptainR 2:81eaaa491a02 10 //
CaptainR 2:81eaaa491a02 11 // Picaso_4DGL-32PTU is distributed in the hope that it will be useful,
CaptainR 2:81eaaa491a02 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
CaptainR 2:81eaaa491a02 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
CaptainR 2:81eaaa491a02 14 // GNU General Public License for more details.
CaptainR 2:81eaaa491a02 15 //
CaptainR 2:81eaaa491a02 16 // You can see GNU General Public License at <http://www.gnu.org/licenses/>.
CaptainR 1:e2337e2653e1 17 //
CaptainR 0:a5ef6bc3c2e8 18
CaptainR 0:a5ef6bc3c2e8 19 #include "mbed.h"
CaptainR 0:a5ef6bc3c2e8 20 #include "Picaso_4DGL-32PTU.h"
CaptainR 0:a5ef6bc3c2e8 21
CaptainR 0:a5ef6bc3c2e8 22 //**************************************************************************
CaptainR 3:dcfbceb81fef 23 // The Clear Screen command clears the screen using the current background color.
CaptainR 0:a5ef6bc3c2e8 24 // This command brings some of the settings back to default; such as,
CaptainR 0:a5ef6bc3c2e8 25 //  Transparency turned OFF
CaptainR 3:dcfbceb81fef 26 //  Outline color set to BLACK
CaptainR 0:a5ef6bc3c2e8 27 //  Opacity set to OPAQUE
CaptainR 0:a5ef6bc3c2e8 28 //  Pen set to OUTLINE
CaptainR 0:a5ef6bc3c2e8 29 //  Line patterns set to OFF
CaptainR 0:a5ef6bc3c2e8 30 //  Right text margin set to full width
CaptainR 0:a5ef6bc3c2e8 31 //  Text magnifications set to 1
CaptainR 0:a5ef6bc3c2e8 32 //  All origins set to 0:0
CaptainR 0:a5ef6bc3c2e8 33 // The alternative to maintain settings and clear screen is
CaptainR 3:dcfbceb81fef 34 // to draw a filled rectangle with the required background color.
CaptainR 0:a5ef6bc3c2e8 35 //**************************************************************************
CaptainR 3:dcfbceb81fef 36 void PICASO_4DGL :: cls() { // clear screen
CaptainR 0:a5ef6bc3c2e8 37
CaptainR 0:a5ef6bc3c2e8 38 char command[2] = "";
CaptainR 0:a5ef6bc3c2e8 39
CaptainR 2:81eaaa491a02 40 command[0] = (CLS >> (8*1)) & 0xff;
CaptainR 2:81eaaa491a02 41 command[1] = (CLS >> (8*0)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 42
CaptainR 0:a5ef6bc3c2e8 43 writeCOMMAND(command, 2);
CaptainR 5:890ddd974624 44 getResponse(1);
CaptainR 0:a5ef6bc3c2e8 45 }
CaptainR 0:a5ef6bc3c2e8 46
CaptainR 0:a5ef6bc3c2e8 47 //**************************************************************************
CaptainR 3:dcfbceb81fef 48 // The Change Color command changes all oldColor pixels to newColor
CaptainR 0:a5ef6bc3c2e8 49 // within the clipping window area.
CaptainR 0:a5ef6bc3c2e8 50 //**************************************************************************
CaptainR 3:dcfbceb81fef 51 void PICASO_4DGL :: changeColor(short oldColor, short newColor) {
CaptainR 0:a5ef6bc3c2e8 52
CaptainR 0:a5ef6bc3c2e8 53 char command[6] = "";
CaptainR 0:a5ef6bc3c2e8 54
CaptainR 2:81eaaa491a02 55 command[0] = (CHANGE_COLOR >> (8*1)) & 0xff;
CaptainR 2:81eaaa491a02 56 command[1] = (CHANGE_COLOR >> (8*0)) & 0xff;
CaptainR 2:81eaaa491a02 57 command[2] = (oldColor >> (8*1)) & 0xff;
CaptainR 2:81eaaa491a02 58 command[3] = (oldColor >> (8*0)) & 0xff;
CaptainR 2:81eaaa491a02 59 command[4] = (newColor >> (8*1)) & 0xff;
CaptainR 2:81eaaa491a02 60 command[5] = (newColor >> (8*0)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 61
CaptainR 0:a5ef6bc3c2e8 62 writeCOMMAND(command, 6);
CaptainR 5:890ddd974624 63 getResponse(1);
CaptainR 0:a5ef6bc3c2e8 64 }
CaptainR 0:a5ef6bc3c2e8 65
CaptainR 0:a5ef6bc3c2e8 66 //**************************************************************************
CaptainR 0:a5ef6bc3c2e8 67 // The Draw Circle command draws a circle with centre point x, y
CaptainR 3:dcfbceb81fef 68 // with radius r using the specified color.
CaptainR 0:a5ef6bc3c2e8 69 //**************************************************************************
CaptainR 3:dcfbceb81fef 70 void PICASO_4DGL :: drawCircle(short x, short y, short r, short color) {
CaptainR 0:a5ef6bc3c2e8 71
CaptainR 0:a5ef6bc3c2e8 72 char command[10] = "";
CaptainR 0:a5ef6bc3c2e8 73
CaptainR 2:81eaaa491a02 74 command[0] = (DRAW_CIRCLE >> (8*1)) & 0xff;
CaptainR 2:81eaaa491a02 75 command[1] = (DRAW_CIRCLE >> (8*0)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 76 command[2] = (x >> (8*1)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 77 command[3] = (x >> (8*0)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 78 command[4] = (y >> (8*1)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 79 command[5] = (y >> (8*0)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 80 command[6] = (r >> (8*1)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 81 command[7] = (r >> (8*0)) & 0xff;
CaptainR 2:81eaaa491a02 82 command[8] = (color >> (8*1)) & 0xff;
CaptainR 2:81eaaa491a02 83 command[9] = (color >> (8*0)) & 0xff;
CaptainR 0:a5ef6bc3c2e8 84
CaptainR 0:a5ef6bc3c2e8 85 writeCOMMAND(command, 10);
CaptainR 5:890ddd974624 86 getResponse(1);
CaptainR 0:a5ef6bc3c2e8 87 }
CaptainR 0:a5ef6bc3c2e8 88
CaptainR 3:dcfbceb81fef 89 //**************************************************************************
CaptainR 3:dcfbceb81fef 90 // The Draw Circle command draws a solid circle with centre point x1, y1
CaptainR 3:dcfbceb81fef 91 // with radius r using the specified color.
CaptainR 3:dcfbceb81fef 92 // The outline color can be specified with the “Outline Color” command.
CaptainR 3:dcfbceb81fef 93 // If “Outline Color” is set to 0, no outline is drawn.
CaptainR 3:dcfbceb81fef 94 //**************************************************************************
CaptainR 3:dcfbceb81fef 95 void PICASO_4DGL :: drawFilledCircle(short x, short y, short r, short color) {
CaptainR 3:dcfbceb81fef 96
CaptainR 3:dcfbceb81fef 97 char command[10] = "";
CaptainR 3:dcfbceb81fef 98
CaptainR 3:dcfbceb81fef 99 command[0] = (CIRCLE_FILLED >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 100 command[1] = (CIRCLE_FILLED >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 101 command[2] = (x >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 102 command[3] = (x >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 103 command[4] = (y >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 104 command[5] = (y >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 105 command[6] = (r >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 106 command[7] = (r >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 107 command[8] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 108 command[9] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 109
CaptainR 3:dcfbceb81fef 110 writeCOMMAND(command, 10);
CaptainR 5:890ddd974624 111 getResponse(1);
CaptainR 3:dcfbceb81fef 112 }
CaptainR 0:a5ef6bc3c2e8 113
CaptainR 3:dcfbceb81fef 114 //**************************************************************************
CaptainR 3:dcfbceb81fef 115 // The Draw Line command draws a line from x1, y1 to x2, y2
CaptainR 3:dcfbceb81fef 116 // using the specified color.
CaptainR 3:dcfbceb81fef 117 //**************************************************************************
CaptainR 3:dcfbceb81fef 118 void PICASO_4DGL :: drawLine(short x1, short y1, short x2, short y2, short color) {
CaptainR 3:dcfbceb81fef 119
CaptainR 3:dcfbceb81fef 120 char command[12] = "";
CaptainR 3:dcfbceb81fef 121
CaptainR 3:dcfbceb81fef 122 command[0] = (DRAW_LINE >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 123 command[1] = (DRAW_LINE >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 124 command[2] = (x1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 125 command[3] = (x1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 126 command[4] = (y1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 127 command[5] = (y1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 128 command[6] = (x2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 129 command[7] = (x2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 130 command[8] = (y2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 131 command[9] = (y2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 132 command[10] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 133 command[11] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 134
CaptainR 3:dcfbceb81fef 135 writeCOMMAND(command, 12);
CaptainR 5:890ddd974624 136 getResponse(1);
CaptainR 3:dcfbceb81fef 137 }
CaptainR 0:a5ef6bc3c2e8 138
CaptainR 3:dcfbceb81fef 139 //**************************************************************************
CaptainR 3:dcfbceb81fef 140 // The Draw Rectangle command draws a rectangle from x1, y1 to x2, y2
CaptainR 3:dcfbceb81fef 141 // using the specified color.
CaptainR 3:dcfbceb81fef 142 // The line may be tessellated with the “Line Pattern” command.
CaptainR 3:dcfbceb81fef 143 //**************************************************************************
CaptainR 3:dcfbceb81fef 144 void PICASO_4DGL :: drawRectangle(short x1, short y1, short x2, short y2, short color) {
CaptainR 3:dcfbceb81fef 145
CaptainR 3:dcfbceb81fef 146 char command[12] = "";
CaptainR 3:dcfbceb81fef 147
CaptainR 3:dcfbceb81fef 148 command[0] = (DRAW_RECTANGLE >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 149 command[1] = (DRAW_RECTANGLE >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 150 command[2] = (x1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 151 command[3] = (x1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 152 command[4] = (y1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 153 command[5] = (y1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 154 command[6] = (x2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 155 command[7] = (x2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 156 command[8] = (y2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 157 command[9] = (y2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 158 command[10] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 159 command[11] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 160
CaptainR 3:dcfbceb81fef 161 writeCOMMAND(command, 12);
CaptainR 5:890ddd974624 162 getResponse(1);
CaptainR 3:dcfbceb81fef 163 }
CaptainR 0:a5ef6bc3c2e8 164
CaptainR 3:dcfbceb81fef 165 //**************************************************************************
CaptainR 3:dcfbceb81fef 166 // The Draw Filled Rectangle command draws a solid rectangle from x1, y1 to x2, y2
CaptainR 3:dcfbceb81fef 167 // using the specified color.
CaptainR 3:dcfbceb81fef 168 // The line may be tessellated with the “Line Pattern” command.
CaptainR 3:dcfbceb81fef 169 // The outline color can be specified with the “Outline Color” command.
CaptainR 3:dcfbceb81fef 170 // If “Outline Color” is set to 0, no outline is drawn.
CaptainR 3:dcfbceb81fef 171 //**************************************************************************
CaptainR 3:dcfbceb81fef 172 void PICASO_4DGL :: drawFilledRectangle(short x1, short y1, short x2, short y2, short color) {
CaptainR 3:dcfbceb81fef 173
CaptainR 3:dcfbceb81fef 174 char command[12] = "";
CaptainR 3:dcfbceb81fef 175
CaptainR 3:dcfbceb81fef 176 command[0] = (RECTANGLE_FILLED >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 177 command[1] = (RECTANGLE_FILLED >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 178 command[2] = (x1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 179 command[3] = (x1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 180 command[4] = (y1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 181 command[5] = (y1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 182 command[6] = (x2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 183 command[7] = (x2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 184 command[8] = (y2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 185 command[9] = (y2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 186 command[10] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 187 command[11] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 188
CaptainR 3:dcfbceb81fef 189 writeCOMMAND(command, 12);
CaptainR 5:890ddd974624 190 getResponse(1);
CaptainR 3:dcfbceb81fef 191 }
CaptainR 0:a5ef6bc3c2e8 192
CaptainR 0:a5ef6bc3c2e8 193
CaptainR 3:dcfbceb81fef 194 //**************************************************************************
CaptainR 3:dcfbceb81fef 195 // The Draw Polyline command plots lines between points specified by a pair of arrays
CaptainR 3:dcfbceb81fef 196 // using the specified color.
CaptainR 3:dcfbceb81fef 197 // The lines may be tessellated with the “Line Pattern” command.
CaptainR 3:dcfbceb81fef 198 // The “Draw Polyline” command can be used to create complex raster graphics
CaptainR 3:dcfbceb81fef 199 // by loading the arrays from serial input or from MEDIA with very little code requirement.
CaptainR 3:dcfbceb81fef 200 //
CaptainR 3:dcfbceb81fef 201 // n - Specifies the number of elements in the x and y arrays specifying the vertices for the polyline.
CaptainR 3:dcfbceb81fef 202 // vx, vy - Specifies the array of elements for the x/y coordinates of the vertices.
CaptainR 3:dcfbceb81fef 203 // Vx1, vx2, …, vxN, vy1, vy2, …, vyN
CaptainR 3:dcfbceb81fef 204 //**************************************************************************
CaptainR 3:dcfbceb81fef 205 void PICASO_4DGL :: drawPolyline(short n, short *vx, short *vy, short color) {
CaptainR 3:dcfbceb81fef 206
CaptainR 3:dcfbceb81fef 207 int size = 6 + (n*4);
CaptainR 3:dcfbceb81fef 208 int i, j = 4;
CaptainR 3:dcfbceb81fef 209 char command[size];
CaptainR 3:dcfbceb81fef 210 for(i = 0; i < size; i++) command[i] = 0;
CaptainR 3:dcfbceb81fef 211
CaptainR 3:dcfbceb81fef 212 command[0] = (DRAW_POLYLINE >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 213 command[1] = (DRAW_POLYLINE >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 214 command[2] = (n >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 215 command[3] = (n >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 216 for (i = 0; i < n; i++) {
CaptainR 3:dcfbceb81fef 217 command[j] = (vx[i] >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 218 j++;
CaptainR 3:dcfbceb81fef 219 command[j] = (vx[i] >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 220 j++;
CaptainR 3:dcfbceb81fef 221 }
CaptainR 3:dcfbceb81fef 222 for (i = 0; i < n; i++) {
CaptainR 3:dcfbceb81fef 223 command[j] = (vy[i] >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 224 j++;
CaptainR 3:dcfbceb81fef 225 command[j] = (vy[i] >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 226 j++;
CaptainR 3:dcfbceb81fef 227 }
CaptainR 3:dcfbceb81fef 228 command[j] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 229 command[j+1] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 230
CaptainR 3:dcfbceb81fef 231 writeCOMMAND(command, size);
CaptainR 5:890ddd974624 232 getResponse(1);
CaptainR 3:dcfbceb81fef 233 }
CaptainR 0:a5ef6bc3c2e8 234
CaptainR 3:dcfbceb81fef 235 //**************************************************************************
CaptainR 3:dcfbceb81fef 236 // The Draw Polygon command plots lines between points specified by a pair of arrays
CaptainR 3:dcfbceb81fef 237 // using the specified color.
CaptainR 3:dcfbceb81fef 238 // The last point is drawn back to the first point, completing the polygon.
CaptainR 3:dcfbceb81fef 239 // The lines may be tessellated with the “Line Pattern” command.
CaptainR 3:dcfbceb81fef 240 // The Draw Polygon command can be used to create complex raster graphics
CaptainR 3:dcfbceb81fef 241 // by loading the arrays from serial input or from MEDIA with very little code requirement.
CaptainR 3:dcfbceb81fef 242 //
CaptainR 3:dcfbceb81fef 243 // n - Specifies the number of elements in the x and y arrays specifying the vertices for the polygon.
CaptainR 3:dcfbceb81fef 244 // vx, vy - Specifies the array of elements for the x/y coordinates of the vertices.
CaptainR 3:dcfbceb81fef 245 // Vx1, vx2, …, vxN, vy1, vy2, …, vyN
CaptainR 3:dcfbceb81fef 246 //**************************************************************************
CaptainR 3:dcfbceb81fef 247 void PICASO_4DGL :: drawPolygon(short n, short *vx, short *vy, short color) {
CaptainR 3:dcfbceb81fef 248
CaptainR 3:dcfbceb81fef 249 int size = 6 + (n*4);
CaptainR 3:dcfbceb81fef 250 int i, j = 4;
CaptainR 3:dcfbceb81fef 251 char command[size];
CaptainR 3:dcfbceb81fef 252 for(i = 0; i < size; i++) command[i] = 0;
CaptainR 3:dcfbceb81fef 253
CaptainR 3:dcfbceb81fef 254 command[0] = (DRAW_POLYGON >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 255 command[1] = (DRAW_POLYGON >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 256 command[2] = (n >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 257 command[3] = (n >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 258 for (i = 0; i < n; i++) {
CaptainR 3:dcfbceb81fef 259 command[j] = (vx[i] >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 260 j++;
CaptainR 3:dcfbceb81fef 261 command[j] = (vx[i] >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 262 j++;
CaptainR 3:dcfbceb81fef 263 }
CaptainR 3:dcfbceb81fef 264 for (i = 0; i < n; i++) {
CaptainR 3:dcfbceb81fef 265 command[j] = (vy[i] >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 266 j++;
CaptainR 3:dcfbceb81fef 267 command[j] = (vy[i] >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 268 j++;
CaptainR 3:dcfbceb81fef 269 }
CaptainR 3:dcfbceb81fef 270 command[j] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 271 command[j+1] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 272
CaptainR 3:dcfbceb81fef 273 writeCOMMAND(command, size);
CaptainR 5:890ddd974624 274 getResponse(1);
CaptainR 3:dcfbceb81fef 275 }
CaptainR 0:a5ef6bc3c2e8 276
CaptainR 3:dcfbceb81fef 277 //**************************************************************************
CaptainR 3:dcfbceb81fef 278 // The Draw Filled Polygon command draws a solid Polygon between specified vertices:
CaptainR 3:dcfbceb81fef 279 // x1, y1 x2, y2, .... , xn, yn using the specified color.
CaptainR 3:dcfbceb81fef 280 // The last point is drawn back to the first point, completing the polygon.
CaptainR 3:dcfbceb81fef 281 // Vertices must be a minimum of 3 and can be specified in any fashion.
CaptainR 3:dcfbceb81fef 282 //
CaptainR 3:dcfbceb81fef 283 // n - Specifies the number of elements in the x and y arrays specifying the vertices for the polygon.
CaptainR 3:dcfbceb81fef 284 // vx, vy - Specifies the array of elements for the x/y coordinates of the vertices.
CaptainR 3:dcfbceb81fef 285 // Vx1, vx2, …, vxN, vy1, vy2, …, vyN
CaptainR 3:dcfbceb81fef 286 //**************************************************************************
CaptainR 3:dcfbceb81fef 287 void PICASO_4DGL :: drawFilledPolygon(short n, short *vx, short *vy, short color) {
CaptainR 3:dcfbceb81fef 288
CaptainR 3:dcfbceb81fef 289 if (n >= 3) {
CaptainR 3:dcfbceb81fef 290 int size = 6 + (n*4);
CaptainR 3:dcfbceb81fef 291 int i, j = 4;
CaptainR 3:dcfbceb81fef 292 char command[size];
CaptainR 3:dcfbceb81fef 293 for(i = 0; i < size; i++) command[i] = 0;
CaptainR 3:dcfbceb81fef 294
CaptainR 3:dcfbceb81fef 295 command[0] = (POLYGON_FILLED >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 296 command[1] = (POLYGON_FILLED >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 297 command[2] = (n >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 298 command[3] = (n >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 299 for (i = 0; i < n; i++) {
CaptainR 3:dcfbceb81fef 300 command[j] = (vx[i] >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 301 j++;
CaptainR 3:dcfbceb81fef 302 command[j] = (vx[i] >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 303 j++;
CaptainR 3:dcfbceb81fef 304 }
CaptainR 3:dcfbceb81fef 305 for (i = 0; i < n; i++) {
CaptainR 3:dcfbceb81fef 306 command[j] = (vy[i] >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 307 j++;
CaptainR 3:dcfbceb81fef 308 command[j] = (vy[i] >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 309 j++;
CaptainR 3:dcfbceb81fef 310 }
CaptainR 3:dcfbceb81fef 311 command[j] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 312 command[j+1] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 313
CaptainR 3:dcfbceb81fef 314 writeCOMMAND(command, size);
CaptainR 5:890ddd974624 315 getResponse(1);
CaptainR 3:dcfbceb81fef 316 }
CaptainR 3:dcfbceb81fef 317 }
CaptainR 3:dcfbceb81fef 318
CaptainR 3:dcfbceb81fef 319 //**************************************************************************
CaptainR 3:dcfbceb81fef 320 // The Draw Triangle command draws a triangle outline between vertices
CaptainR 3:dcfbceb81fef 321 // x1,y1 , x2,y2 and x3,y3 using the specified color.
CaptainR 3:dcfbceb81fef 322 // The line may be tessellated with the “Line Pattern” command.
CaptainR 3:dcfbceb81fef 323 //**************************************************************************
CaptainR 3:dcfbceb81fef 324 void PICASO_4DGL :: drawTriangle(short x1, short y1, short x2, short y2, short x3, short y3, short color) {
CaptainR 3:dcfbceb81fef 325
CaptainR 3:dcfbceb81fef 326 char command[16] = "";
CaptainR 3:dcfbceb81fef 327
CaptainR 3:dcfbceb81fef 328 command[0] = (DRAW_TRIANGLE >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 329 command[1] = (DRAW_TRIANGLE >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 330 command[2] = (x1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 331 command[3] = (x1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 332 command[4] = (y1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 333 command[5] = (y1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 334 command[6] = (x2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 335 command[7] = (x2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 336 command[8] = (y2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 337 command[9] = (y2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 338 command[10] = (x3 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 339 command[11] = (x3 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 340 command[12] = (y3 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 341 command[13] = (y3 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 342 command[14] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 343 command[15] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 344
CaptainR 3:dcfbceb81fef 345 writeCOMMAND(command, 16);
CaptainR 5:890ddd974624 346 getResponse(1);
CaptainR 3:dcfbceb81fef 347 }
CaptainR 3:dcfbceb81fef 348
CaptainR 3:dcfbceb81fef 349 //**************************************************************************
CaptainR 3:dcfbceb81fef 350 // The Draw Filled Triangle command draws a solid triangle between vertices
CaptainR 3:dcfbceb81fef 351 // x1, y1, x2, y2 and x3, y3 using the specified color.
CaptainR 3:dcfbceb81fef 352 //**************************************************************************
CaptainR 3:dcfbceb81fef 353 void PICASO_4DGL :: drawFilledTriangle(short x1, short y1, short x2, short y2, short x3, short y3, short color) {
CaptainR 3:dcfbceb81fef 354
CaptainR 3:dcfbceb81fef 355 char command[16] = "";
CaptainR 3:dcfbceb81fef 356
CaptainR 3:dcfbceb81fef 357 command[0] = (TRIANGLE_FILLED >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 358 command[1] = (TRIANGLE_FILLED >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 359 command[2] = (x1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 360 command[3] = (x1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 361 command[4] = (y1 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 362 command[5] = (y1 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 363 command[6] = (x2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 364 command[7] = (x2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 365 command[8] = (y2 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 366 command[9] = (y2 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 367 command[10] = (x3 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 368 command[11] = (x3 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 369 command[12] = (y3 >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 370 command[13] = (y3 >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 371 command[14] = (color >> (8*1)) & 0xff;
CaptainR 3:dcfbceb81fef 372 command[15] = (color >> (8*0)) & 0xff;
CaptainR 3:dcfbceb81fef 373
CaptainR 3:dcfbceb81fef 374 writeCOMMAND(command, 16);
CaptainR 5:890ddd974624 375 getResponse(1);
CaptainR 3:dcfbceb81fef 376 }
CaptainR 0:a5ef6bc3c2e8 377
CaptainR 4:50511ed54ab4 378 //**************************************************************************
CaptainR 4:50511ed54ab4 379 // The Calculate Orbit command calculates the x, y coordinates of a distant point relative
CaptainR 4:50511ed54ab4 380 // to the current origin, where the only known parameters are the angle and the distance
CaptainR 4:50511ed54ab4 381 // from the current origin. The new coordinates are calculated and then placed in the
CaptainR 4:50511ed54ab4 382 // destination variables Xdest and Ydest.
CaptainR 4:50511ed54ab4 383 //**************************************************************************
CaptainR 4:50511ed54ab4 384 void PICASO_4DGL :: calculateOrbit(short angle, short distance) {
CaptainR 4:50511ed54ab4 385
CaptainR 4:50511ed54ab4 386 char command[6] = "";
CaptainR 4:50511ed54ab4 387
CaptainR 4:50511ed54ab4 388 command[0] = (CALCULATE_ORBIT >> (8*1)) & 0xff;
CaptainR 4:50511ed54ab4 389 command[1] = (CALCULATE_ORBIT >> (8*0)) & 0xff;
CaptainR 4:50511ed54ab4 390 command[2] = (angle >> (8*1)) & 0xff;
CaptainR 4:50511ed54ab4 391 command[3] = (angle >> (8*0)) & 0xff;
CaptainR 4:50511ed54ab4 392 command[4] = (distance >> (8*1)) & 0xff;
CaptainR 4:50511ed54ab4 393 command[5] = (distance >> (8*0)) & 0xff;
CaptainR 4:50511ed54ab4 394
CaptainR 4:50511ed54ab4 395 writeCOMMAND(command, 6);
CaptainR 6:a1a85f2bc04b 396 calculateOrbitResponse();
CaptainR 6:a1a85f2bc04b 397 }
CaptainR 6:a1a85f2bc04b 398
CaptainR 6:a1a85f2bc04b 399 //**************************************************************************
CaptainR 6:a1a85f2bc04b 400 // The Put Pixel command draws a pixel at position x, y using the specified color.
CaptainR 6:a1a85f2bc04b 401 //**************************************************************************
CaptainR 6:a1a85f2bc04b 402 void PICASO_4DGL :: putPixel(short x, short y, short color) {
CaptainR 6:a1a85f2bc04b 403
CaptainR 6:a1a85f2bc04b 404 char command[8] = "";
CaptainR 6:a1a85f2bc04b 405
CaptainR 6:a1a85f2bc04b 406 command[0] = (PUT_PIXEL >> (8*1)) & 0xff;
CaptainR 6:a1a85f2bc04b 407 command[1] = (PUT_PIXEL >> (8*0)) & 0xff;
CaptainR 6:a1a85f2bc04b 408 command[2] = (x >> (8*1)) & 0xff;
CaptainR 6:a1a85f2bc04b 409 command[3] = (x >> (8*0)) & 0xff;
CaptainR 6:a1a85f2bc04b 410 command[4] = (y >> (8*1)) & 0xff;
CaptainR 6:a1a85f2bc04b 411 command[5] = (y >> (8*0)) & 0xff;
CaptainR 6:a1a85f2bc04b 412 command[6] = (color >> (8*1)) & 0xff;
CaptainR 6:a1a85f2bc04b 413 command[7] = (color >> (8*0)) & 0xff;
CaptainR 6:a1a85f2bc04b 414
CaptainR 6:a1a85f2bc04b 415 writeCOMMAND(command, 8);
CaptainR 6:a1a85f2bc04b 416 getResponse(1);
CaptainR 6:a1a85f2bc04b 417 }
CaptainR 6:a1a85f2bc04b 418
CaptainR 6:a1a85f2bc04b 419 //**************************************************************************
CaptainR 6:a1a85f2bc04b 420 // The Move Origin command moves the origin to a new position, which is suitable for
CaptainR 6:a1a85f2bc04b 421 // specifying the location for both graphics and text.
CaptainR 6:a1a85f2bc04b 422 //**************************************************************************
CaptainR 6:a1a85f2bc04b 423 void PICASO_4DGL :: moveOrigin(short x, short y) {
CaptainR 6:a1a85f2bc04b 424
CaptainR 6:a1a85f2bc04b 425 char command[6] = "";
CaptainR 6:a1a85f2bc04b 426
CaptainR 7:f064ae670553 427 command[0] = (MOVE_ORIGIN >> (8*1)) & 0xff;
CaptainR 7:f064ae670553 428 command[1] = (MOVE_ORIGIN >> (8*0)) & 0xff;
CaptainR 6:a1a85f2bc04b 429 command[2] = (x >> (8*1)) & 0xff;
CaptainR 6:a1a85f2bc04b 430 command[3] = (x >> (8*0)) & 0xff;
CaptainR 6:a1a85f2bc04b 431 command[4] = (y >> (8*1)) & 0xff;
CaptainR 6:a1a85f2bc04b 432 command[5] = (y >> (8*0)) & 0xff;
CaptainR 6:a1a85f2bc04b 433
CaptainR 8:b634ac9c92f8 434 writeCOMMAND(command, 6);
CaptainR 8:b634ac9c92f8 435 getResponse(1);
CaptainR 8:b634ac9c92f8 436 }
CaptainR 8:b634ac9c92f8 437
CaptainR 8:b634ac9c92f8 438 //**************************************************************************
CaptainR 8:b634ac9c92f8 439 // The Draw Line & Move Origin command draws a line from the current origin
CaptainR 8:b634ac9c92f8 440 // to a new position. The Origin is then set to the new position.
CaptainR 8:b634ac9c92f8 441 // The line is drawn using the current object colour, using the
CaptainR 8:b634ac9c92f8 442 // “Set Graphics Parameters” – “Object Colour” command. The line may be
CaptainR 8:b634ac9c92f8 443 // tessellated with the “Line Pattern” command.
CaptainR 8:b634ac9c92f8 444 //
CaptainR 8:b634ac9c92f8 445 // Note: this command is mostly useful with the “Calculate Orbit” command,
CaptainR 8:b634ac9c92f8 446 // and usually the “Draw Line” command would be used
CaptainR 8:b634ac9c92f8 447 //**************************************************************************
CaptainR 8:b634ac9c92f8 448 void PICASO_4DGL :: lineTo(short x, short y) {
CaptainR 8:b634ac9c92f8 449
CaptainR 8:b634ac9c92f8 450 char command[6] = "";
CaptainR 8:b634ac9c92f8 451
CaptainR 8:b634ac9c92f8 452 command[0] = (LINE_TO >> (8*1)) & 0xff;
CaptainR 8:b634ac9c92f8 453 command[1] = (LINE_TO >> (8*0)) & 0xff;
CaptainR 8:b634ac9c92f8 454 command[2] = (x >> (8*1)) & 0xff;
CaptainR 8:b634ac9c92f8 455 command[3] = (x >> (8*0)) & 0xff;
CaptainR 8:b634ac9c92f8 456 command[4] = (y >> (8*1)) & 0xff;
CaptainR 8:b634ac9c92f8 457 command[5] = (y >> (8*0)) & 0xff;
CaptainR 8:b634ac9c92f8 458
CaptainR 8:b634ac9c92f8 459 writeCOMMAND(command, 6);
CaptainR 6:a1a85f2bc04b 460 getResponse(1);
CaptainR 4:50511ed54ab4 461 }
CaptainR 4:50511ed54ab4 462
CaptainR 4:50511ed54ab4 463
CaptainR 4:50511ed54ab4 464