Skip to content

Commit 595f627

Browse files
committed
window management
1 parent 5e2c6b6 commit 595f627

File tree

6 files changed

+86
-118
lines changed

6 files changed

+86
-118
lines changed

src/controller/Display.cpp

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,24 @@
88
#include <wiringPiSPI.h>
99

1010
namespace udd {
11+
#define swap(t, a, b) {t tmp=a; a=b; b=tmp;}
12+
1113
std::recursive_mutex screenLock;
1214

1315
Display::Display() {
1416
displayId = IdGenerator::next();
1517
}
1618

19+
void Display::init() {
20+
fprintf(stderr, "init failed, base method called instead of child\n");
21+
exit(0);
22+
}
23+
1724

1825

1926
void Display::openDisplay(DisplayConfigruation configuration) {
2027
this->config = configuration;
21-
this->vImage = Image(config.width, config.height, BLACK);
28+
// this->vImage = Image(config.width, config.height, BLACK);
2229

2330
openSPI();
2431

@@ -110,7 +117,7 @@ namespace udd {
110117
}
111118
}
112119

113-
void Display::clearWindow(Color color) {
120+
void Display::clearWindow(Color color, Point p1, Point p2, Rotation rotation) {
114121
screenLock.lock();
115122

116123
openSPI();
@@ -122,14 +129,14 @@ namespace udd {
122129
_byte* rowPointer = (_byte*)(row);
123130
_word cx = color2word(&ct);
124131

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;
127134

128135
for (int x = 0; x < width; x++) {
129136
row[x] = cx;
130137
}
131138

132-
setWindow(windowP1.x, windowP1.y, windowP2.x, windowP2.y, DEGREE_0);
139+
setWindow(p1,p2, DEGREE_0);
133140
digitalWrite(config.DC, 1);
134141
digitalWrite(config.CS, 0);
135142

@@ -153,8 +160,6 @@ namespace udd {
153160
int width = config.width + config.xOffset;
154161
int height = config.height + config.yOffset;
155162

156-
157-
158163
printf("clearScreen: width=%d height=%d\n", width, height); fflush(stdout);
159164

160165
_word row[width];
@@ -168,7 +173,7 @@ namespace udd {
168173
}
169174

170175
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);
172177

173178
digitalWrite(config.DC, 1);
174179
digitalWrite(config.CS, 0);
@@ -189,10 +194,10 @@ namespace udd {
189194

190195

191196
void Display::showImage(Image& image) {
192-
showImage(image, DEGREE_0);
197+
showImage(image, Point(0,0), Point(config.width,config.height), DEGREE_0);
193198
}
194199

195-
void Display::showImage(Image &image, Rotation rotation) {
200+
void Display::showImage(Image &image, Point p1, Point p2, Rotation rotation) {
196201
int width, height;
197202
screenLock.lock();
198203
openSPI();
@@ -201,11 +206,10 @@ namespace udd {
201206
// int width = config.width + config.xOffset;
202207
// int height = config.height + config.yOffset;
203208

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);
208210

211+
width = p2.x - p1.x + 1;
212+
height = p2.y - p1.y + 1;
209213

210214
/*
211215
switch (rotation) {
@@ -259,19 +263,61 @@ namespace udd {
259263

260264

261265

262-
void Display::setWindowFullScreen() {
263-
setWindow(0, 0, config.width-1 + config.xOffset, config.height-1 + config.yOffset, config.screenRotation);
264-
}
265266

266-
void Display::setWindow(int x1, int y1, int x2, int y2) {
267-
setWindow(x1, y1, x2, y2, DEGREE_0);
268-
}
269267

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+
275321
}
276322

277323
void Display::adjustPoint(int &x, int &y, Rotation rotation) {
@@ -351,8 +397,10 @@ namespace udd {
351397
}
352398
*/
353399

400+
/*
354401
void Display::setPixel(Pixel pixel) {
355402
this->vImage.drawPoint(pixel.point.x, pixel.point.y, pixel.color,1);
356403
}
404+
*/
357405

358406
}

src/controller/Display.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,45 +53,39 @@ namespace udd {
5353

5454
class Display {
5555
protected:
56-
5756
int displayId = -1;
57+
int handle = -1;
5858

5959
Display();
6060
virtual ~Display() {}
6161

62-
int handle = -1;
62+
void adjustPoint(int& x, int& y, Rotation rotation);
6363

64-
Image vImage;
64+
virtual void setWindow(Point p1, Point p2, Rotation rotation);
6565

66-
Point windowP1 = Point(0, 0);
67-
Point windowP2 = Point(0, 0);
68-
void adjustPoint(int& x, int& y, Rotation rotation);
69-
7066
public:
7167
DisplayConfigruation config;
7268

73-
virtual void init() {
74-
fprintf(stderr, "init failed, base method called instead of child\n");
75-
exit(0);
76-
}
69+
virtual void init();
70+
7771

7872
void openDisplay(DisplayConfigruation configuratrion);
79-
void setWindowFullScreen();
80-
void setWindow(int x1, int y1, int x2, int y2);
8173

82-
virtual _word color2word(ColorType* xp);
83-
virtual void reset();
74+
8475
virtual void clearScreen(Color color);
85-
virtual void clearWindow(Color color);
86-
virtual void setWindow(int x1, int y1, int x2, int y2, Rotation rotation);
76+
virtual void clearWindow(Color color, Point p1, Point p2, Rotation rotation);
77+
8778
virtual void showImage(Image &image);
88-
virtual void showImage(Image &image, Rotation rotation);
79+
virtual void showImage(Image &image, Point p1, Point p2, Rotation rotation);
8980

9081
virtual void readBusy() {
9182
fprintf(stderr, "readBusy() is not implemented for this method\n");
9283
exit(0);
9384
}
9485

86+
virtual _word color2word(ColorType* xp);
87+
virtual void reset();
88+
9589

9690
void printConfiguration();
9791
void printRotation(Rotation rotation);
@@ -106,7 +100,7 @@ namespace udd {
106100
void resume();
107101
void writeCommand(_byte data);
108102
void writeData(_byte data);
109-
void setPixel(Pixel pixel);
103+
//void setPixel(Pixel pixel);
110104
//void writeWord(_word data);
111105
};
112106

src/displays/DisplayST7735R.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,7 @@ namespace udd {
101101
writeCommand(0x29);
102102

103103
}
104-
void DisplayST7735R::setWindow(int x1, int y1, int x2, int y2, Rotation rotation) {
105-
Display::setWindow(x1, y1, x2, y2);
106104

107-
adjustPoint(x1, y1, rotation);
108-
adjustPoint(x2, y2, rotation);
109-
110-
writeCommand(0x2a);
111-
writeData(x1 >> 8);
112-
writeData(x1 & 0xff);
113-
writeData((x2 - 1) >> 8);
114-
writeData((x2 - 1) & 0xff);
115-
116-
writeCommand(0x2b);
117-
writeData(y1 >> 8);
118-
writeData(y1 & 0xff);
119-
writeData((y2 - 1) >> 8);
120-
writeData((y2 - 1) & 0xff);
121-
122-
writeCommand(0x2C);
123-
}
124105
void DisplayST7735R::initScanDir(LCD_SCAN_DIR Scan_dir) {
125106
//Get the screen scan direction
126107
sLCD_DIS.LCD_Scan_Dir = Scan_dir;

src/displays/DisplayST7735R.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ namespace udd {
5252

5353
void init() override;
5454
void initScanDir(LCD_SCAN_DIR direction);
55-
void setWindow(int x1, int y1, int x2, int y2, Rotation rotation);
5655

5756
_word color2word(ColorType* xp);
5857

src/displays/DisplayST7789.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -98,61 +98,8 @@ namespace udd {
9898
writeCommand(0x29);
9999
}
100100

101-
#define swap(t, a, b) {t tmp=a; a=b; b=tmp;}
102101

103102

104-
void DisplayST7789R::setWindow(int x1, int y1, int x2, int y2, Rotation rotation) {
105-
fprintf(stderr, "----setWindow(rotation=%d)------------------\n", rotation);
106-
fprintf(stderr, "p1(%3d,%3d) p2(%3d,%3d)\n", x1, y1, x2, y2);
107-
108-
Display::setWindow(x1, y1, x2, y2, rotation);
109-
110-
fprintf(stderr, "----adjustPoint(rotation=%d)------------------\n",rotation);
111-
fflush(stderr);
112-
113-
if (rotation == DEGREE_0) {
114-
// do nothing
115-
}
116-
117-
if (rotation == DEGREE_180) {
118-
adjustPoint(x1, y1, rotation);
119-
adjustPoint(x2, y2, rotation);
120-
swap(int, x1, x2);
121-
swap(int, y1, y2);
122-
}
123-
124-
if (rotation == DEGREE_90) {
125-
swap(int, x1, x2);
126-
127-
}
128-
129-
if (rotation == DEGREE_270) {
130-
adjustPoint(x1, y1, rotation);
131-
adjustPoint(x2, y2, rotation);
132-
133-
fprintf(stderr, "p2(%3d,%3d) p2(%3d,%3d)\n", x1, y1, x2, y2);
134-
swap(int, y1, y2);
135-
136-
}
137-
138-
139-
fprintf(stderr, "p4(%3d,%3d) p2(%3d,%3d)\n", x1, y1, x2, y2);
140-
fflush(stderr);
141-
142-
writeCommand(0x2a); // caset x1 <= y2
143-
writeData(x1 >> 8);
144-
writeData(x1 & 0xff);
145-
writeData((x2) >> 8);
146-
writeData((x2) & 0xff);
147-
148-
writeCommand(0x2b); // raset y1 <= y2
149-
writeData(y1 >> 8);
150-
writeData(y1 & 0xff);
151-
writeData((y2) >> 8);
152-
writeData((y2) & 0xff);
153-
154-
writeCommand(0x2C);
155-
}
156103

157104

158105

src/displays/DisplayST7789.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace udd {
99

1010
void init() override;
1111

12-
void setWindow(int x1, int y1, int x2, int y2, Rotation rotation) override;
1312

1413
};
1514
}

0 commit comments

Comments
 (0)