-
Notifications
You must be signed in to change notification settings - Fork 0
/
btReciever.ino
59 lines (52 loc) · 1.69 KB
/
btReciever.ino
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
const byte ascii2hex[103] = { 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,1,
2,3,4,5,6,7,8,9,0,0,
0,0,0,0,0,10,11,12,13,14,
15,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,10,11,12,
13,14,15};
byte readByte(){
Serial.print("Serial.available = ");
Serial.println(BTserial.available());
byte result;
if(BTserial.available() >= 2){
result = ascii2hex[BTserial.read()];
result *= 16;
result += ascii2hex[BTserial.read()];
return result;
}else return 0;
}
String readString(){
const uint16_t bufferLen = 64;
char buffer[bufferLen] = {0};
if(!BTserial.available()) return String();
for(uint16_t i=0; i<bufferLen; i++){
buffer[i] = BTserial.read();
if(!BTserial.available()){
buffer[i+1] = '\0';
Serial.print("len = ");
Serial.println(i+1);
break;
}
}
Serial.println(buffer);
return String(buffer);
}
void readMessage(String message, uint8_t cursor){
int current=0, next;
int i=cursor;
while((next = message.indexOf(',', current))!=-1){
showingTable[i++] = message.substring(current, next).toInt();
Serial.println(message.substring(current, next).toInt());
current = next+1;
if(i >= NUM_OF_ROWS) break;
}
if(i < NUM_OF_ROWS){
showingTable[i++] = message.substring(current, next).toInt();
Serial.println(message.substring(current, next).toInt());
}
}