-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLedMatrix.cpp
More file actions
69 lines (47 loc) · 1.54 KB
/
LedMatrix.cpp
File metadata and controls
69 lines (47 loc) · 1.54 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
#include <iostream>
#include "LedMatrix.h"
#include "candy.h"
void LedMatrix::load_lua(const char* filename, AbstractDriver *driver) {
lua_State *L = luaL_newstate();
luaL_requiref(L, "base", luaopen_base, 1);
luaL_requiref(L, "io", luaopen_io, 1);
luaL_requiref(L, "math", luaopen_math, 1);
Luna<Candy>::Register(L);
Candy::driver = driver;
int s = luaL_loadfile(L, filename);
if ( s==0 ) {
printf("- Loading file: %s\n", filename);
// execute Lua program
s = lua_pcall(L, 0, LUA_MULTRET, 0);
}
if ( s!=0 ) {
std::cerr << "-- " << lua_tostring(L, -1) << std::endl;
lua_pop(L, 1); // remove error message
}
std::cerr << std::endl;
lua_close(L);
for(std::vector<LedMatrix*>::iterator mx = LedMatrix::matrices.begin(); mx != LedMatrix::matrices.end();++mx) {
LedMatrix *matrix = *mx;
matrix->finalize();
}
}
LedMatrix::LedMatrix(const char * hostname) {
opc_client.resolve(hostname);
}
void LedMatrix::add_strip(Point start, Point end, unsigned int length)
{
float width = end.x - start.x;
float height = end.y - start.y;
float deltaX = width / length;
float deltaY = height / length;
for (unsigned int i = 0; i < length; i++)
{
leds.push_back(Point(start.x + i*deltaX,start.y + i*deltaY));
}
}
void LedMatrix::finalize() {
int frameBytes = leds.size() * 3;
frameBuffer.resize(sizeof(OPCClient::Header) + frameBytes);
OPCClient::Header::view(frameBuffer).init(0, opc_client.SET_PIXEL_COLORS, frameBytes);
}
std::vector<LedMatrix*> LedMatrix::matrices;