-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRTx.cpp
More file actions
65 lines (54 loc) · 1.23 KB
/
RTx.cpp
File metadata and controls
65 lines (54 loc) · 1.23 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
#include "RTx.h"
RTx::RTx() {
this->inputCount = 0;
this->outputCount = 0;
}
void RTx::reset() {
this->inputCount = 0;
this->outputCount = 0;
}
int RTx::sendData(int pixels[], int pixelCount){
String cmd;
while (true) {
cmd = listen();
if (cmd == "RDY" || cmd == "DONE"){break;}
}
//sending data
for (int i = 0; i < pixelCount; ++i) {
Serial.print(((pixels[i])));
if (i == pixelCount - 1){
Serial.print(';'); // Send ';' when all numbers are sent
} else
Serial.print(','); // Send ',' when a number is sent
}
Serial.flush();
if (cmd=="DONE") return 0;
else return 1;
}
//only send message if other side is ready for it
void RTx::sendString(String message){
String cmd;
while (true){
cmd=listen();
if (cmd=="RDY"){break;}
else if (cmd=="DONE"){break;}
}
Serial.print(message);
Serial.println(';'); // Send ';' when all numbers are sent
}
String RTx::listen() {
String retVal = "";
while (true){
if (Serial.available()) {
delay(40); //wait for entire serial to arrive
retVal = Serial.readStringUntil(';'); //stop at ;
//return input value
Serial.print(retVal);
Serial.print(';');
Serial.flush();
break;
}
delay(1);
}
return retVal;
}