Repository navigation
Expand file tree
/
Copy pathOpcLayoutServerApp.cpp
More file actions
77 lines (61 loc) · 1.97 KB
/
Copy pathOpcLayoutServerApp.cpp
File metadata and controls
77 lines (61 loc) · 1.97 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
70
71
72
73
74
75
76
77
#include "cinder/Json.h"
#include "cinder/Log.h"
#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "OpcServer.h"
using namespace ci;
using namespace ci::app;
using namespace std;
class OpcLayoutServerApp : public App {
public:
static void prepareSettings(Settings *settings);
void setup() override;
void update() override;
void draw() override;
private:
kp::opc::ServerRef mOpcServer;
vector<vec2> mLayoutPositions;
};
void OpcLayoutServerApp::prepareSettings(Settings *settings) {
settings->setWindowSize(800, 800);
settings->setPowerManagementEnabled(true); // Prevent App Nap
settings->setTitle("OPC Layout Server Sample App");
}
void OpcLayoutServerApp::setup() {
// Load layout JSON and store positions by LED index. Ignore the Z axis.
JsonTree layoutData = JsonTree(loadAsset("layout.json"));
for (auto &led : layoutData) {
const vec2 position = vec2(led["point"].getValueAtIndex<float>(0), led["point"].getValueAtIndex<float>(1));
mLayoutPositions.push_back(position);
}
mOpcServer = kp::opc::Server::create(mLayoutPositions.size(), 7890);
}
void OpcLayoutServerApp::update() {
}
void OpcLayoutServerApp::draw() {
gl::clear(Color(0, 0, 0));
// Draw the LEDs per the layout, setting color from received messages.
int i = 0;
for (const Color8u &color : mOpcServer->getLeds()) {
const ivec2 center = mLayoutPositions[i];
// LED outline
if (color == Color("black")) {
// Fill with placeholder color
gl::color(Color(0.1, 0.1, 0.1));
} else {
// Fill with received color
gl::color(color);
}
gl::drawSolidCircle(center, 3.0);
i++;
}
// Draw stats
TextBox textBox = TextBox().size(ivec2(200, 15)).text("Messages received: " + toString(mOpcServer->getNumMessagesReceived()));
gl::pushMatrices();
gl::translate(10.0, 10.0);
gl::color(Color("white"));
gl::draw(gl::Texture2d::create(textBox.render()));
gl::popMatrices();
}
CINDER_APP(OpcLayoutServerApp, RendererGl, OpcLayoutServerApp::prepareSettings)