forked from firefeather/ArduProj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphicdisplay.cpp
More file actions
348 lines (339 loc) · 14.1 KB
/
Copy pathgraphicdisplay.cpp
File metadata and controls
348 lines (339 loc) · 14.1 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
#ifndef GRAPHICDISPLAY_CPP
#define GRAPHICDISPLAY_CPP
#include "graphicdisplay.h"
#ifdef LCD_DOGM128
GraphicDisplay::GraphicDisplay(){
//U8GLIB_DOGM128(13,11,10,9,255);
}
GraphicDisplay::GraphicDisplay(uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t m) {
U8GLIB_DOGM128(13,11,10,9,255); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
}
void GraphicDisplay::lcd_data( unsigned char Data) {
_symbuffer[_row*21+_column] = Data;
if( _column < 20) _column++;
}
void GraphicDisplay::lcd_clear( void ) {
for( int i = 0; i < 168; i++ ) {
_symbuffer[i] = ' ';
}
_column = 0;
_row = 0;
}
void GraphicDisplay::lcd_line(unsigned char Line) {
_column = 0;
_row = Line;
}
//Clear single line of display
void GraphicDisplay::lcd_clear_line(unsigned char Line)
{
_row = Line;
_column = 0;
for( int i = _row*21; i < _row*21+21; i++) {
_symbuffer[i] = ' ';
}
}
//Write probe pin number to the LCD
void GraphicDisplay::lcd_testpin(unsigned char Probe)
{
//Since TP1 is 0 we simply add the value to '1'
this->lcd_data('1' + Probe); //Send data
}
//Display a space
void GraphicDisplay::lcd_space(void)
{
this->lcd_data(' ');
}
//Display a string
void GraphicDisplay::lcd_string(char *String)
{
while (*String) //Loop until trailing 0 is reached
{
this->lcd_data(*String); //Send character
String++; //Next one
}
}
//Display a fixed string stored in PROGMEM
void GraphicDisplay::lcd_fixed_string(const unsigned char *String)
{
while (pgm_read_byte(String) != 0x00)
this->lcd_data(pgm_read_byte(String++)); //Send character
}
void GraphicDisplay::print(const char *Str)
{
for( int i = _row*21+_column; i < _row*21+21; i++ ) {
_symbuffer[i] = (byte)*Str++;
_column++;
}
}
void GraphicDisplay::begin(uint8_t cols, uint8_t rows)
{
// flip screen, if required
this->setRot180();
// set SPI backup if required
//setHardwareBackup(u8g_backup_avr_spi);
// assign default color value
if ( this->getMode() == U8G_MODE_R3G3B2 ) {
this->setColorIndex(255); // white
}
else if ( this->getMode() == U8G_MODE_GRAY2BIT ) {
this->setColorIndex(3); // max intensity
}
else if ( this->getMode() == U8G_MODE_BW ) {
this->setColorIndex(1); // pixel on
}
else if ( this->getMode() == U8G_MODE_HICOLOR ) {
this->setHiColorByRGB(255,255,255);
}
//u8g_font_unifont
this->setFont(u8g_font_6x12);
for( int i=0; i < 168; i++) {
_symbuffer[i] = ' ';
}
_comp = COMPONENT_NONE;
this->home();
}
void GraphicDisplay::setCursor(uint8_t col, uint8_t row)
{
_column = col;
_row = row;
}
void GraphicDisplay::backlight(void)
{
}
void GraphicDisplay::createChar(uint8_t location, uint8_t charmap[])
{
}
#ifdef __AVR__
void GraphicDisplay::createChar(uint8_t location, const unsigned char *charmap)
{
}
#endif // __AVR__
void GraphicDisplay::home(void)
{
_column = 0;
_row = 0;
}
void GraphicDisplay::component(uint8_t c){
_comp = c;
}
#define X_OFFSET 87
#define Y_OFFSET 32
#define Y_CENTRAL 48
#define X_CENTRAL 106
#define ICON_WIDTH 32
#define ICON_HEIGHT 32
void GraphicDisplay::update(void)
{
this->setColorIndex(1);
this->firstPage();
do {
// symbol buffer
char buf[22];
for( int k=0; k <8; k++) {
for( int i=0; i <21; i++) {
buf[i] = _symbuffer[k*21+i];
}
buf[21] = 0;
this->drawStr((u8g_uint_t)0,(u8g_uint_t)(k*8+8),(const char*)buf);
//Serial.println(buf);
}
// Component icon
if(_comp != COMPONENT_NEVER) {
this->setColorIndex(0);
this->drawBox(X_OFFSET,Y_OFFSET,ICON_WIDTH,ICON_HEIGHT);
}
this->setColorIndex(1);
switch (_comp) {
case COMPONENT_NONE:
case COMPONENT_ERROR:
case COMPONENT_NEVER:
case COMPONENT_MENU:
break;
case COMPONENT_RESISTOR:
this->drawFrame(X_OFFSET + 8,Y_OFFSET + 12, 16, 8);
this->drawHLine(X_OFFSET, Y_CENTRAL, 8);
this->drawHLine(X_OFFSET + 24, Y_CENTRAL, 8);
break;
case COMPONENT_CAPACITOR:
this->drawBox(X_OFFSET + 10, Y_OFFSET + 10, 4, 16);
this->drawBox(X_OFFSET + 16, Y_OFFSET + 10, 4, 16);
this->drawHLine(X_OFFSET, Y_CENTRAL + 1, 10);
this->drawHLine(X_OFFSET + 20, Y_CENTRAL + 1, 10);
break;
case COMPONENT_INDUCTOR:
this->drawHLine(X_OFFSET + 3, Y_CENTRAL, 4);
this->drawVLine(X_OFFSET + 6, Y_CENTRAL - 2, 3);
this->drawHLine(X_OFFSET + 7, Y_CENTRAL - 3, 3);
this->drawVLine(X_OFFSET + 10, Y_CENTRAL - 2, 5);
this->drawHLine(X_OFFSET + 11, Y_CENTRAL + 3, 3);
this->drawVLine(X_OFFSET + 14, Y_CENTRAL - 2, 5);
this->drawHLine(X_OFFSET + 15, Y_CENTRAL - 3, 3);
this->drawVLine(X_OFFSET + 18, Y_CENTRAL - 2, 5);
this->drawHLine(X_OFFSET + 19, Y_CENTRAL + 3, 3);
this->drawVLine(X_OFFSET + 22, Y_CENTRAL - 2, 5);
this->drawHLine(X_OFFSET + 23, Y_CENTRAL - 3, 3);
this->drawVLine(X_OFFSET + 26, Y_CENTRAL - 2, 3);
this->drawHLine(X_OFFSET + 27, Y_CENTRAL, 3);
break;
case COMPONENT_DIODE:
this->drawTriangle(X_OFFSET + 12, Y_CENTRAL - 8, X_OFFSET + 12, Y_CENTRAL + 8, X_OFFSET + 20, Y_CENTRAL);
this->drawBox(X_OFFSET + 21, Y_CENTRAL - 8, 2, 17);
this->drawHLine(X_OFFSET + 3,Y_CENTRAL, 26);
break;
case COMPONENT_ZENER:
this->drawHLine( X_OFFSET + 3, Y_CENTRAL, 4);
this->drawVLine( X_OFFSET + 7, Y_CENTRAL - 8, 17);
this->drawHLine( X_OFFSET + 8, Y_CENTRAL - 8, 23);
this->drawHLine( X_OFFSET + 8, Y_CENTRAL + 8, 23);
this->drawTriangle(X_OFFSET + 15, Y_CENTRAL - 8, X_OFFSET + 24, Y_CENTRAL - 13, X_OFFSET + 24, Y_CENTRAL - 3);
this->drawTriangle(X_OFFSET + 13, Y_CENTRAL + 3, X_OFFSET + 13, Y_CENTRAL + 13, X_OFFSET + 22, Y_CENTRAL + 8);
this->drawBox(X_OFFSET + 13, Y_CENTRAL - 13, 2, 11);
this->drawBox(X_OFFSET + 22, Y_CENTRAL + 3, 2, 11);
break;
case COMPONENT_BJTN:
this->drawHLine(X_OFFSET + 20, Y_OFFSET + 6, 5);
this->drawVLine(X_OFFSET + 24, Y_OFFSET + 7, 17);
this->drawHLine(X_OFFSET + 20, Y_OFFSET + 24, 5);
this->drawBox(X_OFFSET + 21, Y_OFFSET + 11, 7, 2);
this->drawTriangle(X_OFFSET + 24, Y_OFFSET + 13, X_OFFSET + 20, Y_OFFSET + 17, X_OFFSET + 28, Y_OFFSET + 17);
case COMPONENT_NPN:
this->drawHLine(X_OFFSET + 2, Y_OFFSET + 15, 6);
this->drawBox(X_OFFSET + 8, Y_OFFSET + 6, 2, 19);
this->drawLine(X_OFFSET + 10, Y_OFFSET + 15, X_OFFSET + 19, Y_OFFSET + 6);
this->drawVLine(X_OFFSET + 19, Y_OFFSET + 2, 4);
this->drawLine(X_OFFSET + 10, Y_OFFSET + 15, X_OFFSET + 19, Y_OFFSET + 24);
this->drawVLine(X_OFFSET + 19, Y_OFFSET + 25, 4);
this->drawTriangle(X_OFFSET + 14, Y_OFFSET + 23, X_OFFSET + 18, Y_OFFSET + 19, X_OFFSET + 18, Y_OFFSET + 23);
break;
case COMPONENT_BJTP:
this->drawHLine(X_OFFSET + 20, Y_OFFSET + 6, 5);
this->drawVLine(X_OFFSET + 24, Y_OFFSET + 7, 17);
this->drawHLine(X_OFFSET + 20, Y_OFFSET + 24, 5);
this->drawTriangle(X_OFFSET + 20, Y_OFFSET + 11, X_OFFSET + 28, Y_OFFSET + 11, X_OFFSET + 24, Y_OFFSET + 15);
this->drawBox(X_OFFSET + 21, Y_OFFSET + 16, 7, 2);
case COMPONENT_PNP:
this->drawHLine(X_OFFSET + 2, Y_OFFSET + 15, 6);
this->drawBox(X_OFFSET + 8, Y_OFFSET + 6, 2, 19);
this->drawLine(X_OFFSET + 10, Y_OFFSET + 15, X_OFFSET + 19, Y_OFFSET + 6);
this->drawLine(X_OFFSET + 10, Y_OFFSET + 15, X_OFFSET + 19, Y_OFFSET + 24);
this->drawVLine(X_OFFSET + 19, Y_OFFSET + 2, 4);
this->drawVLine(X_OFFSET + 19, Y_OFFSET + 25, 4);
this->drawTriangle(X_OFFSET + 14, Y_OFFSET + 19, X_OFFSET + 14, Y_OFFSET + 23, X_OFFSET + 18, Y_OFFSET + 19);
break;
case COMPONENT_NFET:
this->drawHLine(X_OFFSET + 3, Y_OFFSET + 22, 23);
this->drawVLine(X_OFFSET + 25, Y_OFFSET + 23, 6);
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 5, 21);
this->drawHLine(X_OFFSET + 13, Y_OFFSET + 8, 13);
this->drawVLine(X_OFFSET + 25, Y_OFFSET + 2, 6);
this->drawTriangle(X_OFFSET + 8, Y_OFFSET + 19, X_OFFSET + 8, Y_OFFSET + 25, X_OFFSET + 11, Y_OFFSET + 22);
break;
case COMPONENT_PFET:
this->drawHLine(X_OFFSET + 3, Y_OFFSET + 22, 23);
this->drawVLine(X_OFFSET + 25, Y_OFFSET + 23, 6);
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 5, 21);
this->drawHLine(X_OFFSET + 13, Y_OFFSET + 8, 13);
this->drawVLine(X_OFFSET + 25, Y_OFFSET + 2, 6);
this->drawTriangle(X_OFFSET + 6, Y_OFFSET + 22, X_OFFSET + 9, Y_OFFSET + 19, X_OFFSET + 9, Y_OFFSET + 25);
break;
case COMPONENT_NIGBT:
this->drawHLine(X_OFFSET + 3, Y_OFFSET + 15, 6);
this->drawVLine(X_OFFSET + 9, Y_OFFSET + 7, 17);
this->drawBox(X_OFFSET + 11, Y_OFFSET + 6, 2, 19);
this->drawLine(X_OFFSET + 13, Y_OFFSET + 15, X_OFFSET + 22, Y_OFFSET + 6);
this->drawVLine(X_OFFSET + 22, Y_OFFSET + 2, 4);
this->drawLine(X_OFFSET + 13, Y_OFFSET + 15, X_OFFSET + 22, Y_OFFSET + 24);
this->drawVLine(X_OFFSET + 22, Y_OFFSET + 25, 4);
this->drawTriangle(X_OFFSET + 17, Y_OFFSET + 23, X_OFFSET + 21, Y_OFFSET + 19, X_OFFSET + 21, Y_OFFSET + 23);
break;
case COMPONENT_PIGBT:
this->drawHLine(X_OFFSET + 3, Y_OFFSET + 15, 6);
this->drawVLine(X_OFFSET + 9, Y_OFFSET + 7, 17);
this->drawBox(X_OFFSET + 11, Y_OFFSET + 6, 2, 19);
this->drawLine(X_OFFSET + 13, Y_OFFSET + 15, X_OFFSET + 22, Y_OFFSET + 6);
this->drawVLine(X_OFFSET + 22, Y_OFFSET + 2, 4);
this->drawLine(X_OFFSET + 13, Y_OFFSET + 15, X_OFFSET + 22, Y_OFFSET + 24);
this->drawVLine(X_OFFSET + 22, Y_OFFSET + 25, 4);
this->drawTriangle(X_OFFSET + 16, Y_OFFSET + 19, X_OFFSET + 16, Y_OFFSET + 23, X_OFFSET + 20, Y_OFFSET + 19);
break;
case COMPONENT_TRIAC:
this->drawHLine(X_OFFSET, Y_OFFSET + 28, 6);
this->drawLine(X_OFFSET + 6, Y_OFFSET + 27, X_OFFSET + 12, Y_OFFSET + 21);
this->drawVLine(X_OFFSET + 14, Y_OFFSET + 21, 8);
this->drawHLine(X_OFFSET + 14, Y_OFFSET + 29, 16);
this->drawVLine(X_OFFSET + 14, Y_OFFSET + 2, 8);
this->drawHLine(X_OFFSET + 15, Y_OFFSET + 2, 15);
this->drawHLine(X_OFFSET + 20, Y_OFFSET + 10, 10);
this->drawHLine(X_OFFSET + 2, Y_OFFSET + 20, 10);
this->drawTriangle(X_OFFSET + 2, Y_OFFSET + 10, X_OFFSET + 19, Y_OFFSET + 10, X_OFFSET + 10, Y_OFFSET + 19);
this->drawTriangle(X_OFFSET + 12, Y_OFFSET + 20, X_OFFSET + 30, Y_OFFSET + 20, X_OFFSET + 21, Y_OFFSET + 11);
break;
case COMPONENT_THYRISTOR:
this->drawHLine(X_OFFSET + 2, Y_OFFSET + 26, 6);
this->drawLine(X_OFFSET + 8, Y_OFFSET + 25, X_OFFSET + 13, Y_OFFSET + 20);
this->drawVLine(X_OFFSET + 15, Y_OFFSET + 4, 25);
this->drawHLine(X_OFFSET + 16, Y_OFFSET + 4, 14);
this->drawHLine(X_OFFSET + 16, Y_OFFSET + 28, 14);
this->drawBox(X_OFFSET + 9, Y_OFFSET + 18, 13, 2);
this->drawTriangle(X_OFFSET + 9, Y_OFFSET + 11, X_OFFSET + 21, Y_OFFSET + 11, X_OFFSET + 15, Y_OFFSET + 17);
break;
case COMPONENT_NMOSD:
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 5, 22);
case COMPONENT_NMOS:
this->drawHLine(X_OFFSET + 3, Y_OFFSET + 22, 7);
this->drawVLine(X_OFFSET + 9, Y_OFFSET + 8, 14);
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 11, 9);
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 5, 4);
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 22, 4);
this->drawHLine(X_OFFSET + 13, Y_OFFSET + 8, 12);
this->drawHLine(X_OFFSET + 13, Y_OFFSET + 22, 12);
this->drawHLine(X_OFFSET + 13, Y_OFFSET + 15, 6);
this->drawVLine(X_OFFSET + 19, Y_OFFSET + 15, 7);
this->drawVLine(X_OFFSET + 25, Y_OFFSET + 2, 27);
this->drawTriangle(X_OFFSET + 14, Y_OFFSET + 15, X_OFFSET + 17, Y_OFFSET + 12, X_OFFSET + 17, Y_OFFSET + 18);
this->drawHLine(X_OFFSET + 22, Y_OFFSET + 13, 7);
this->drawTriangle(X_OFFSET + 22, Y_OFFSET + 17, X_OFFSET + 29, Y_OFFSET + 17, X_OFFSET + 25, Y_OFFSET + 14);
break;
case COMPONENT_PMOSD:
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 5, 22);
case COMPONENT_PMOS:
this->drawHLine(X_OFFSET + 3, Y_OFFSET + 22, 7);
this->drawVLine(X_OFFSET + 9, Y_OFFSET + 8, 14);
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 11, 9);
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 5, 4);
this->drawVLine(X_OFFSET + 12, Y_OFFSET + 22, 4);
this->drawHLine(X_OFFSET + 13, Y_OFFSET + 8, 12);
this->drawHLine(X_OFFSET + 13, Y_OFFSET + 22, 12);
this->drawHLine(X_OFFSET + 13, Y_OFFSET + 15, 6);
this->drawVLine(X_OFFSET + 19, Y_OFFSET + 15, 7);
this->drawVLine(X_OFFSET + 25, Y_OFFSET + 2, 27);
this->drawTriangle(X_OFFSET + 14, Y_OFFSET + 12, X_OFFSET + 14, Y_OFFSET + 18, X_OFFSET + 17, Y_OFFSET + 15);
this->drawHLine(X_OFFSET + 22, Y_OFFSET + 17, 7);
this->drawTriangle(X_OFFSET + 22, Y_OFFSET + 13, X_OFFSET + 29, Y_OFFSET + 13, X_OFFSET + 25, Y_OFFSET + 16);
break;
default:
break;
}
} while(this->nextPage());
}
void GraphicDisplay::pins(uint8_t a, uint8_t b, uint8_t c)
{
uint8_t r, co;
co = _column;
r = _row;
this->setCursor( 13, 5);
this->lcd_data('1'+a);
if(c==' ')
this->setCursor( 20, 5);
else
this->setCursor(20,4);
this->lcd_data('1'+b);
this->setCursor( 20, 7);
if( c!=' ')
this->lcd_data('1'+c);
else
this->lcd_data(' ');
this->setCursor( co, r);
}
#endif // LCD_DOGM128
#endif // GRAPHICDISPLAY_CPP