8
8
#include < wiringPiSPI.h>
9
9
10
10
namespace udd {
11
+ #define swap (t, a, b ) {t tmp=a; a=b; b=tmp;}
12
+
11
13
std::recursive_mutex screenLock;
12
14
13
15
Display::Display () {
14
16
displayId = IdGenerator::next ();
15
17
}
16
18
19
+ void Display::init () {
20
+ fprintf (stderr, " init failed, base method called instead of child\n " );
21
+ exit (0 );
22
+ }
23
+
17
24
18
25
19
26
void Display::openDisplay (DisplayConfigruation configuration) {
20
27
this ->config = configuration;
21
- this ->vImage = Image (config.width , config.height , BLACK);
28
+ // this->vImage = Image(config.width, config.height, BLACK);
22
29
23
30
openSPI ();
24
31
@@ -110,7 +117,7 @@ namespace udd {
110
117
}
111
118
}
112
119
113
- void Display::clearWindow (Color color) {
120
+ void Display::clearWindow (Color color, Point p1, Point p2, Rotation rotation ) {
114
121
screenLock.lock ();
115
122
116
123
openSPI ();
@@ -122,14 +129,14 @@ namespace udd {
122
129
_byte* rowPointer = (_byte*)(row);
123
130
_word cx = color2word (&ct);
124
131
125
- int width = windowP2 .x - windowP1 .x + 1 ;
126
- int height = windowP2 .y - windowP1 .y + 1 ;
132
+ int width = p2 .x - p1 .x + 1 ;
133
+ int height = p2 .y - p1 .y + 1 ;
127
134
128
135
for (int x = 0 ; x < width; x++) {
129
136
row[x] = cx;
130
137
}
131
138
132
- setWindow (windowP1. x , windowP1. y , windowP2. x , windowP2. y , DEGREE_0);
139
+ setWindow (p1,p2 , DEGREE_0);
133
140
digitalWrite (config.DC , 1 );
134
141
digitalWrite (config.CS , 0 );
135
142
@@ -153,8 +160,6 @@ namespace udd {
153
160
int width = config.width + config.xOffset ;
154
161
int height = config.height + config.yOffset ;
155
162
156
-
157
-
158
163
printf (" clearScreen: width=%d height=%d\n " , width, height); fflush (stdout);
159
164
160
165
_word row[width];
@@ -168,7 +173,7 @@ namespace udd {
168
173
}
169
174
170
175
printf (" clearScreen: tag01\n " ); fflush (stdout);
171
- setWindow (0 , 0 , width-1 , height-1 , DEGREE_0);
176
+ setWindow (Point ( 0 , 0 ), Point ( width-1 , height-1 ) , DEGREE_0);
172
177
173
178
digitalWrite (config.DC , 1 );
174
179
digitalWrite (config.CS , 0 );
@@ -189,10 +194,10 @@ namespace udd {
189
194
190
195
191
196
void Display::showImage (Image& image) {
192
- showImage (image, DEGREE_0);
197
+ showImage (image, Point ( 0 , 0 ), Point (config. width ,config. height ), DEGREE_0);
193
198
}
194
199
195
- void Display::showImage (Image &image, Rotation rotation) {
200
+ void Display::showImage (Image &image, Point p1, Point p2, Rotation rotation) {
196
201
int width, height;
197
202
screenLock.lock ();
198
203
openSPI ();
@@ -201,11 +206,10 @@ namespace udd {
201
206
// int width = config.width + config.xOffset;
202
207
// int height = config.height + config.yOffset;
203
208
204
- setWindow (windowP1.x , windowP1.y , windowP2.x , windowP2.y , rotation);
205
-
206
- width = windowP2.x - windowP1.x + 1 ;
207
- height = windowP2.y - windowP1.y + 1 ;
209
+ setWindow (p1, p2, rotation);
208
210
211
+ width = p2.x - p1.x + 1 ;
212
+ height = p2.y - p1.y + 1 ;
209
213
210
214
/*
211
215
switch (rotation) {
@@ -259,19 +263,61 @@ namespace udd {
259
263
260
264
261
265
262
- void Display::setWindowFullScreen () {
263
- setWindow (0 , 0 , config.width -1 + config.xOffset , config.height -1 + config.yOffset , config.screenRotation );
264
- }
265
266
266
- void Display::setWindow (int x1, int y1, int x2, int y2) {
267
- setWindow (x1, y1, x2, y2, DEGREE_0);
268
- }
269
267
270
- void Display::setWindow (int x1, int y1, int x2, int y2, Rotation rotation) {
271
- windowP1.x = x1;
272
- windowP1.y = y1;
273
- windowP2.x = x2;
274
- windowP2.y = y2;
268
+ void Display::setWindow (Point p1, Point p2, Rotation rotation) {
269
+
270
+ int x1 = p1.x ;
271
+ int y1 = p1.y ;
272
+
273
+ int x2 = p2.x ;
274
+ int y2 = p2.y ;
275
+
276
+ fprintf (stderr, " p1(%3d,%3d) p2(%3d,%3d)\n " , x1, y1, x2, y2);
277
+
278
+ adjustPoint (x1, y1, rotation);
279
+ adjustPoint (x2, y2, rotation);
280
+
281
+ fprintf (stderr, " p2(%3d,%3d) p2(%3d,%3d)\n " , x1, y1, x2, y2);
282
+
283
+
284
+ switch (rotation) {
285
+ case DEGREE_0: {
286
+ break ;
287
+ }
288
+ case DEGREE_90: {
289
+ swap (int , x1, x2);
290
+ break ;
291
+ }
292
+ case DEGREE_180: {
293
+ swap (int , x1, x2);
294
+ swap (int , y1, y2);
295
+ break ;
296
+ }
297
+ case DEGREE_270: {
298
+ swap (int , y1, y2);
299
+ break ;
300
+ }
301
+ }
302
+
303
+
304
+ fprintf (stderr, " p4(%3d,%3d) p2(%3d,%3d)\n " , x1, y1, x2, y2);
305
+ fflush (stderr);
306
+
307
+ writeCommand (0x2a ); // caset x1 <= y2
308
+ writeData (x1 >> 8 );
309
+ writeData (x1 & 0xff );
310
+ writeData ((x2) >> 8 );
311
+ writeData ((x2) & 0xff );
312
+
313
+ writeCommand (0x2b ); // raset y1 <= y2
314
+ writeData (y1 >> 8 );
315
+ writeData (y1 & 0xff );
316
+ writeData ((y2) >> 8 );
317
+ writeData ((y2) & 0xff );
318
+
319
+ writeCommand (0x2C );
320
+
275
321
}
276
322
277
323
void Display::adjustPoint (int &x, int &y, Rotation rotation) {
@@ -351,8 +397,10 @@ namespace udd {
351
397
}
352
398
*/
353
399
400
+ /*
354
401
void Display::setPixel(Pixel pixel) {
355
402
this->vImage.drawPoint(pixel.point.x, pixel.point.y, pixel.color,1);
356
403
}
404
+ */
357
405
358
406
}
0 commit comments