-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRS485TestClient.cpp
More file actions
74 lines (66 loc) · 1.74 KB
/
Copy pathRS485TestClient.cpp
File metadata and controls
74 lines (66 loc) · 1.74 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
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Constants.h"
byte buffer_index = 0;
char buffer[bufferSize];
bool msg_start = false;
bool msg_end = false;
uint64_t data=0;
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void RecieveChar(){
char rc;
while(Serial.available() >0 ){
rc = Serial.read();
if(!msg_start){
if(rc==start_marker){
// Serial.println("start");
// Point to beginning of array, and allow future reads of Serial to be processed
buffer_index = 0;
msg_start = true;
}
}
else{
if(rc!=end_marker){
// read in characters, then advance index
// Serial.println("mid");
buffer[buffer_index] = rc;
buffer_index++;
// If the index exceeds the buffer size, set buffer_index to end of buffer
if(buffer_index>=bufferSize){
buffer_index = bufferSize-1;
}
}
else{
// We are at the nd of the message. Need to null terminate string
// Serial.println("end");
buffer[buffer_index] = '\0';
msg_end = true;
}
}
}
}
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextSize(1);
display.setTextColor(WHITE);
display.clearDisplay();
display.println("Start");
display.display();
Serial.begin(115200);
pinMode(ENABLE_PIN,OUTPUT);
digitalWrite(ENABLE_PIN,LOW);
}
void loop() {
RecieveChar();
if(msg_end&&msg_start){
msg_start = false;
msg_end = false;
data = strtoull(buffer,NULL,10);
display.clearDisplay();
display.setCursor(0,0);
display.printf("Count:%llu",data);
display.display();
}
}