This repository was archived by the owner on Apr 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScreen.cpp
More file actions
222 lines (167 loc) · 4.73 KB
/
Screen.cpp
File metadata and controls
222 lines (167 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//---headers
#include "Screen.h"
//---constructor
Screen::Screen(bool s):
simulator_{s},
numbers_{0b00111111,
0b00110000,
0b01101101,
0b01111001,
0b01110010,
0b01011011,
0b01011111,
0b00110001,
0b01111111,
0b01111011 },
table_{ {20-THICKNESS,20-THICKNESS,80+2*THICKNESS,2*THICKNESS},
{20-THICKNESS,20-THICKNESS,2*THICKNESS,80+THICKNESS},
{20-THICKNESS,100,2*THICKNESS,80+THICKNESS},
{20-THICKNESS,180-THICKNESS,80+2*THICKNESS,2*THICKNESS},
{100-THICKNESS,100,2*THICKNESS,80+THICKNESS},
{100-THICKNESS,20-THICKNESS,2*THICKNESS,80+THICKNESS},
{20-THICKNESS,100-THICKNESS,80+2*THICKNESS,2*THICKNESS} }
{
if(simulator_){
Serial.println("LOG Inited_Screen");
}
else {
epd_ = new Epd;
if (epd_->Init() != 0) {
// Serial.print("e-Paper init failed");
}
// Serial.println("post");
}
unsigned char internalNumberBuffer[4000]; // > 120*200/8
numberBuffer_ = new Paint(internalNumberBuffer,120,200);
}
void
Screen::drawNumber(const int number) {
// Serial.println("before clear");
numberBuffer_->Clear(UNCOLORED);
// Serial.println("after clear");
for(volatile int j=0; j<7; j++) { //volatile otherwise it shit itself
if(numbers_[number] & 1<<j) {
const int tx = table_[j][0];
const int ty = table_[j][1];
const int dtx = table_[j][2];
const int dty = table_[j][3];
// Serial.println("random serial");
if(j%2 == 0) { //vertical lines
// Serial.println(j);
for(volatile int k = 0; k < dtx; k++) { //same thing as earlyer
numberBuffer_->DrawVerticalLine(tx+k,ty,dty,COLORED);
// Serial.println("DrawVerticalLine");
}
}
else { //horizontal lines
// Serial.println(j);
for(volatile int k = 0; k < dty; k++) { //same thing as earlyer
numberBuffer_->DrawHorizontalLine(tx,ty+k,dtx,COLORED);
// Serial.print("DrawHorizontalLine");
}
}
}
}
// Serial.println("end");
}
void
Screen::setScore(const int score, const bool refreshEnabled) {
if(simulator_) {
Serial.println("LOG screen_score_"+String(score));
}
else {
if(score > 999) { return; } //score is too high
const char hundreeds = int(score/100);
const char decades = int((score-hundreeds*100)/10);
const char units = int(score%10);
// Serial.println("drawHundreeds");
drawNumber(hundreeds);
epd_->SetPartialWindow(numberBuffer_->GetImage(), 16, 40,
numberBuffer_->GetWidth(), numberBuffer_->GetHeight());
// Serial.println("drawDecades");
drawNumber(decades);
epd_->SetPartialWindow(numberBuffer_->GetImage(), 144, 40,
numberBuffer_->GetWidth(), numberBuffer_->GetHeight());
// Serial.println("drawUnits");
drawNumber(units);
epd_->SetPartialWindow(numberBuffer_->GetImage(), 272, 40,
numberBuffer_->GetWidth(), numberBuffer_->GetHeight());
}
if(refreshEnabled) {
refresh();
}
// Serial.println("after drawNumbers");
}
void
Screen::drawIcon(const int iconId, const bool refreshEnabled) {
if(simulator_) {
Serial.println("LOG screen_drawn_icon_"+String(iconId));
}
else {
if(iconId < 0 || iconId > 8) { //id does not correspond to any icon
return;
}
epd_->SetPartialWindow(iconsTable[iconId],(3+iconId*5)*8,264,32,32);
}
if(refreshEnabled) {
refresh();
}
}
void
Screen::clearIcon(const int iconId, const bool refreshEnabled) {
if(simulator_) {
Serial.println("LOG screen_cleared_icon_"+String(iconId));
}
else {
if(iconId < 0 || iconId > 8) { //id does not correspond to any icon
return;
}
epd_->fillPartialWindow((3+iconId*5)*8,264,32,32,UNCOLORED);
}
if(refreshEnabled) {
refresh();
}
}
void
Screen::showInitFrame(const int score) {
if(simulator_) {
Serial.println("LOG screen_show_init_frame");
}
else {
/*unsigned char internalTmpBuffer[2000]; // > 400*20/8
Paint *tmpBuffer = new Paint(internalTmpBuffer,400,20);
Serial.println(tmpBuffer->GetWidth());
Serial.println(tmpBuffer->GetHeight());
Serial.println(tmpBuffer->GetWidth()*tmpBuffer->GetHeight()/8);
tmpBuffer->Clear(COLORED);
tmpBuffer->DrawStringAt(0,0,"Enigma",&Font16,UNCOLORED);
epd_->SetPartialWindow(tmpBuffer->GetImage(), 0, 0,
tmpBuffer->GetWidth(), tmpBuffer->GetHeight());*/
epd_->ClearFrame();
// Serial.println("back in showInitFrame");
epd_->fillPartialWindow(0,0,400,20,COLORED); //top of the screen
epd_->fillPartialWindow(0,260,400,1,COLORED); //bottom of the screen
}
setScore(score);
// sSerial.println("end");
}
void
Screen::refresh() {
if(isBusy()) { return; } //screen is not ready
if(simulator_) {
Serial.println("LOG screen_refresh");
}
else {
epd_->DisplayFrame();
}
}
void
Screen::clearScreen() {
if(simulator_) {
Serial.println("LOG screen_clear_frame");
}
else {
epd_->ClearFrame();
epd_->DisplayFrame();
}
}