-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGraph.cpp
51 lines (40 loc) · 994 Bytes
/
Graph.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
#include "Graph.h"
void Graph::init(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, TFT_HX8357 tft)
{
x = x0;
y = y0;
maxX = x1;
maxY = y1;
display = tft;
curX = 1;
values = (uint16_t *)malloc((maxX - x) * sizeof(uint16_t));
clear();
}
void Graph::clear()
{
display.fillRect(x, y, maxX, maxY, TFT_BLACK);
display.drawFastVLine(x, y, (maxY - y) - 1, TFT_WHITE);
display.drawFastHLine(x, maxY - 1, (maxX - x) - 1, TFT_WHITE);
}
void Graph::plot(uint16_t value)
{
uint16_t val = (value * 100) / (maxY - y);
values[curX] = val;
display.drawPixel(x + curX, maxY - val, TFT_WHITE);
if (curX >= maxX) {
scroll();
} else {
curX++;
}
}
void Graph::scroll()
{
for (uint16_t i = 0; i < (maxX - x); i++) {
if ((maxY - values[i]) < (maxY - 1) && i > 0) {
display.drawPixel(x + i, maxY - values[i], TFT_BLACK);
}
values[i] = values[i + 1];
display.drawPixel(x + i, maxY - values[i], TFT_WHITE);
}
values[maxX - x] = 0;
}