-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverload.cpp
83 lines (59 loc) · 1.86 KB
/
serverload.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "serverload.h"
static ofEvent < vector <bool> > buttonChange;
ofEvent < vector <bool> > serverload::buttonChange = ofEvent < vector <bool> >();
static ofEvent < vector <bool> > hillsPress;
ofEvent < vector <bool> > serverload::hillsPress = ofEvent < vector <bool> >();
serverload::serverload() {
udpConnection.Create();
udpConnection.Bind(9000);
udpConnection.SetNonBlocking(true);
udpConnectionTwo.Create();
udpConnectionTwo.Bind(8000);
udpConnectionTwo.SetNonBlocking(true);
preMes = "start";
}
//--------------------------
//--------------------------
void serverload::update() {
string message;
char udpMessage[50];
udpConnection.Receive(udpMessage,50);
message=udpMessage;
if(message!=""){
if(message != preMes){
vector<string> dataFromArdunio = ofSplitString(message,",");
vector<bool> send;
for(int x = 0;x < dataFromArdunio.size()-1;x++){
send.push_back(ofToBool(dataFromArdunio[x]));
}
ofNotifyEvent(buttonChange, send);
}
preMes = message;
}
}
void serverload::updateTwo(){
string message;
char udpMessage[50];
udpConnectionTwo.Receive(udpMessage,50);
message=udpMessage;
if(message!=""){
if(message != preMesTwo){
vector<string> dataFromArdunio = ofSplitString(message,",");
vector<bool> send;
for(int x = 0;x < dataFromArdunio.size()-1;x++){
send.push_back(ofToBool(dataFromArdunio[x]));
}
ofNotifyEvent(hillsPress, send);
}
preMesTwo = message;
}
}
//--------------------------
serverload::~serverload() {
udpConnection.Close();
udpConnection.~ofxUDPManager();
udpConnectionTwo.Close();
udpConnectionTwo.~ofxUDPManager();
preMes.empty();
preMesTwo.empty();
}