-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscopedisplay.cpp
182 lines (144 loc) · 3.06 KB
/
scopedisplay.cpp
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
#include "scopedisplay.h"
#include "arduino.h"
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
//memory mapped by columns
//byte are shown vertically. from 0 to 83 map the first 8 rows
//bit 0 is at the bottom
//X0 X1 .... 83 <--bit 7
//X X
//X X <--bit 0
//
//X84 X85
//X X
//X X
//...
extern uint8_t pcd8544_buffer[];
//terminal display position and size
int displayX = 0;
int displayY = 0;
const int displayMaxX = 13; //0..13
const int displayMaxY = 5; //0..5
byte cDisplayContrast = 50;
void displayConstrastSet(byte cDC)
{
cDisplayContrast = cDC;
display.setContrast(cDisplayContrast);
}
byte displayContrastGet()
{
return cDisplayContrast;
}
//0..64 pixle for 0..1V (more or less). 10% error
//display is only 48 pixel
//1/64=0,0156v per pixel
//every 16 pixel=0,25volt
//every 8 pixel=0,125volt
//#.#.#.#.
//#.......
//........
//........
//#.#.#.#.
//#.......
//........
//........
//
void displayDrawGrid()
{
char*addr;
int grid[] = {
0b0000000000110011,
0b0000000000000001,
0b0000000000000001,
0b0000000000000001
};
for (int row = 0; row < 6; row++)
{
addr = pcd8544_buffer + (row * 84) ;
for (int column = 0; column < 10; column ++)
{
memcpy(addr, (char*)grid, 8);
addr += 8;
}
memcpy(addr, (char*)grid, 4);
}
displayLineX1Y1X2Y2(0, 24, 83, 24);
displayLineX1Y1X2Y2(40, 0, 40, 47);
}
void displaySetup() {
display.begin();
displayConstrastSet(cDisplayContrast);
display.setTextSize(1);
display.setTextColor(BLACK);
display.clearDisplay();
display.display();
}
void displayScrollUp8()
{
int addr;
for (int row = 0; row < 6; row++)
{
addr = row * 84 ;
for (int column = 0; column < 84; column++)
{
pcd8544_buffer[addr] = pcd8544_buffer[addr + 84];
addr++;
}
}
addr = 84 * 5;
for (int column = 0; column < 84; column++)
{
pcd8544_buffer[addr] = 0;
addr++;
}
}
//display a string with \n support and automatic scroll
void displayPrint(char*str)
{
char c;
for (int i = 0;; i++)
{
c = str[i];
if (c == 0) break;
if (c == '\n' || displayX > displayMaxX)
{
displayX = 0;
if (displayY < displayMaxY) {
displayY++;
}
else
{
displayScrollUp8();
}
if (c == '\n') continue;
}
display.drawChar(displayX * 6, displayY * 8, c, BLACK, WHITE, 1);
displayX++;
}
}
void displayPrintXY(char*str, int x, int y)
{
char c;
for (int i = 0;; i++)
{
c = str[i];
if (c == 0) break;
display.drawChar(x * 6, y * 8, c, BLACK, WHITE, 1);
x++;
}
}
void displayPixelXY(int x, int y)
{
display.drawPixel(x, y, BLACK);
}
void displayLineX1Y1X2Y2(int16_t x0, int16_t y0, int16_t x1, int16_t y1)
{
display.drawLine( x0, y0, x1, y1, BLACK);
}