-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyellow-msx-esp8266-wifi-module.ino
145 lines (110 loc) · 3.3 KB
/
yellow-msx-esp8266-wifi-module.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*********
Yellow MSX for RC2014
RC2014 Wifi Module
Serial to (telnet) TCP bridge
*********/
#include "at-command-msx-rc2014.h"
#include "at-command-parser.h"
#include "at-command-time.h"
#include "at-command-web-get.h"
#include "gpio.h"
#include "parse-string.h"
#include "passthrough-escaping.h"
#include "system-operation-mode.h"
#include "flash_store.h"
#include <ArduinoOTA.h>
#include <ESP8266WiFi.h>
#include <ezTime.h>
WiFiClient client;
int updateProgressFilter = 0;
void setup() {
#ifdef WIFI_IS_OFF_AT_BOOT
enableWiFiAtBootTime(); // can be called from anywhere with the same effect
#endif
eeprom_setup();
Serial.begin(eeprom_get_baud());
setRXOpenDrain();
setCTSFlowControlOff(); // Dont wont to have setup blocked, if serial not able to send
initLeds();
Serial.println(F("\r\n"));
if (!(WiFi.SSID() == F("")) || (WiFi.SSID() == NULL))
WiFi.begin();
Serial.print(F("\033[2J"));
firmwareInit(true);
if (WiFi.status() != WL_CONNECTED)
return;
ArduinoOTA.onStart([]() {
eeprom_ota_reset();
Serial.print(F("Updating ESP8266 Firmware\r\n"));
});
ArduinoOTA.onEnd([]() { Serial.print(F("\r\nCompleted Download.\r\n")); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
if ((updateProgressFilter & 7) == 0 || progress == total) {
setCTSFlowControlOff(); // Dont wont to blocked, if serial not able to send
Serial.printf(PSTR("\r\033[2KProgress: %u%%"), (progress / (total / 100)));
}
updateProgressFilter++;
});
ArduinoOTA.onError([](ota_error_t error) {
EEPROMr.rotate(true);
Serial.printf(PSTR("Error[%u]: "), error);
if (error == OTA_AUTH_ERROR) {
Serial.print(F("Auth Failed\r\n"));
} else if (error == OTA_BEGIN_ERROR) {
Serial.print(F("Begin Failed\r\n"));
} else if (error == OTA_CONNECT_ERROR) {
Serial.print(F("Connect Failed\r\n"));
} else if (error == OTA_RECEIVE_ERROR) {
Serial.print(F("Receive Failed\r\n"));
} else if (error == OTA_END_ERROR) {
Serial.print(F("End Failed\r\n"));
}
});
ArduinoOTA.begin();
Serial.flush();
setCTSFlowControlOn();
}
int incomingByte = 0;
int timeOfLastIncomingByte = 0;
bool wasPassthroughMode = false;
void loop() {
const int timeSinceLastByte = millis() - timeOfLastIncomingByte;
ledLoop();
ArduinoOTA.handle();
testForEscapeSequence(timeSinceLastByte);
if (isPassthroughMode() && !client.connected()) {
Serial.print(F("\r\nREADY\r\n"));
operationMode = CommandMode;
if (WiFi.status() != WL_CONNECTED)
wifiLedOff();
else
wifiLedOn();
}
wasPassthroughMode = isPassthroughMode();
if (Serial.available() > 0) {
rxLedFlash();
incomingByte = Serial.read();
if (isXModemSendingMode()) {
txLedFlash();
xmodemReceiveChar(incomingByte);
}
else if (isCommandMode()) {
txLedFlash();
processCommandByte(incomingByte);
}
else if (incomingByte == '+') {
processPotentialEscape(timeSinceLastByte);
} else {
abortEscapeSquence();
client.write((char)incomingByte);
}
timeOfLastIncomingByte = millis();
} else if (isXModemSendingMode())
xmodemLoop();
if (isPassthroughMode())
if (client.available() > 0) {
txLedFlash();
const char c = client.read();
Serial.print(c);
}
}