-
Notifications
You must be signed in to change notification settings - Fork 0
/
CrossFunc.cpp
74 lines (57 loc) · 1.59 KB
/
CrossFunc.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
/*
* Definition of cross functional services
*/
#include "CrossFunc.h"
#include "Symbols.h"
#ifdef HL_DISP
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// I2C OLED display
Adafruit_SSD1306 display(OLED_WIDTH, OLED_HEIGHT, &Wire, OLED_RESET);
#endif
// WiFi
// WiFi settings
wiFiConfig wiFiSettings {
(char*)"SSID",
(char*)"Passphrase",
4
};
WiFiClient client; // This throttle's WiFi client
// WiThrottle server communication
// WiThrottle server settings
hostConfig hostSettings {
(char*)"0.0.0.0",
12090,
2,
(char*)"",
0
};
unsigned long lastHeartbeat; // Timestamp of last heartbeat sent to WiThrottle server
// Send command to WiThrottle server
void sendCmd(String command, bool waitAfterCommand) {
client.println(command);
lastHeartbeat = millis();
#ifdef DEBUG
Serial.println("-->: " + command);
#endif
if (waitAfterCommand) {
delay(JMRI_DELAY);
}
}
// Read command from WiThrottle server
String readCmd() {
String command; // Command string sent by WiThrottle server
String tmpCommand; // Modified command string used for debugging
if (client.available() > 0) {
command = client.readString();
client.flush();
#ifdef DEBUG
if (command != "\r\n\r\n" && command != "") {
tmpCommand = command.substring(0, command.length() - 4);
tmpCommand.replace("\r\n\r\n", "\r\n<--: ");
Serial.println("<--: " + tmpCommand);
}
#endif
}
return command;
}