-
Notifications
You must be signed in to change notification settings - Fork 84
/
DrawPlugin.cpp
65 lines (59 loc) · 1.08 KB
/
DrawPlugin.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
#include "plugins/DrawPlugin.h"
void DrawPlugin::setup()
{
Screen.clear();
if (Screen.isCacheEmpty())
{
Screen.loadFromStorage();
}
else
{
Screen.restoreCache();
}
#ifdef ENABLE_SERVER
sendInfo();
#endif
}
void DrawPlugin::teardown()
{
Screen.cacheCurrent();
}
void DrawPlugin::websocketHook(DynamicJsonDocument &request)
{
const char *event = request["event"];
if (currentStatus == NONE)
{
if (!strcmp(event, "led"))
{
Screen.setPixelAtIndex(request["index"], request["status"]);
}
else if (!strcmp(event, "clear"))
{
Screen.clear();
}
else if (!strcmp(event, "screen"))
{
uint8_t buffer[ROWS * COLS];
for (int i = 0; i < ROWS * COLS; i++)
{
buffer[i] = request["data"][i];
}
Screen.setRenderBuffer(buffer);
}
else if (!strcmp(event, "persist"))
{
Screen.persist();
}
else if (!strcmp(event, "load"))
{
Screen.loadFromStorage();
#ifdef ENABLE_SERVER
sendInfo();
#endif
}
}
}
const char *DrawPlugin::getName() const
{
return "Draw";
}