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
|
#include "sharp.hpp"
#include "rtc.hpp"
constexpr unsigned int SHARP_SCK = 12;
constexpr unsigned int SHARP_MOSI = 13;
constexpr unsigned int SHARP_SS = 14;
Adafruit_SharpMem Sharp::display(SHARP_SCK, SHARP_MOSI, SHARP_SS, SHARP_WIDTH,
SHARP_HEIGHT);
TaskHandle_t Sharp::taskHandle;
std::vector<Widget *> Sharp::widgets;
int Sharp::topY = 0;
int Sharp::scrollVelocity = 0;
void Sharp::begin(void)
{
widgets.reserve(10);
display.begin();
display.clearDisplay();
display.setTextSize(3);
display.setTextColor(BLACK, WHITE);
xTaskCreate(updateTask, "sharp", 512, nullptr, TASK_PRIO_LOW,
&taskHandle);
}
void Sharp::sendInput(int ypos)
{
if (ypos < 0 || ypos > SHARP_HEIGHT)
return;
int y = topY;
for (unsigned int i = 0; i < widgets.size(); i++) {
y += widgets[i]->getHeight();
if (ypos < y) {
if (widgets[i]->onPress()) {
delete widgets[i];
widgets.erase(widgets.begin() + i);
display.clearDisplay();
}
break;
}
y += 3;
if (y >= SHARP_HEIGHT)
break;
}
}
void Sharp::updateTask([[maybe_unused]] void *arg)
{
static unsigned int counter = 0;
while (1) {
if (counter++ == 3) {
counter = 0;
auto y = topY;
for (auto& w : widgets) {
w->render(display, y);
y += w->getHeight();
display.drawFastHLine(0, y + 1, SHARP_WIDTH, BLACK);
y += 3;
if (y >= SHARP_HEIGHT)
break;
}
display.refresh();
} else {
topY += scrollVelocity * 20;
if (scrollVelocity != 0)
display.clearDisplay();
if (topY > 0)
topY = 0;
}
delay(50);
}
}
|