forked from davidbouchard/arduino-osc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOscSerial.cpp
executable file
·70 lines (50 loc) · 1.14 KB
/
OscSerial.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
#include <OscSerial.h>
void oscEvent(OscMessage &);
//=============================================================================
// OSC_Serial Wrapper
//=============================================================================
/*
// old wrapper constructor
OscSerial::OscSerial(HardwareSerial &s) {
slip = new SLIPEncodedSerial(s);
}
*/
OscSerial::OscSerial() {
;
}
void OscSerial::begin(HardwareSerial &s) {
slip = new SLIPEncodedSerial(s);
}
// Non-blocking version
void OscSerial::listen() {
int size;
if( (size = slip->available()) > 0) {
while(size--) msgIN.fill(slip->read());
}
if (!slip->endofPacket()) return;
if (!msgIN.hasError()) {
oscEvent(msgIN);
}
msgIN.reset();
}
/*
// Blocking Version -- do not use, left there for reference
void OscSerial::listen() {
int size;
while(!slip->endofPacket()) {
if( (size = slip->available()) > 0) {
while(size--) msgIN.fill(slip->read());
}
}
if(!msgIN.hasError()) {
oscEvent(msgIN);
}
// get the OSC message ready for the next one
msgIN.reset();
}
*/
void OscSerial::send(OscMessage &msg) {
msg.send(*slip);
slip->endPacket();
msg.empty();
}