Skip to content

Commit

Permalink
Refactoring to PolledTimeout or optimistic_yield on the grounds that …
Browse files Browse the repository at this point in the history
…these are not wait loops on slow input.
  • Loading branch information
dok-net committed May 18, 2021
1 parent 117f163 commit f382fc9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
1 change: 0 additions & 1 deletion cores/esp8266/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ unsigned long HardwareSerial::detectBaudrate(time_t timeoutMillis)
if ((detectedBaudrate = testBaudrate())) {
break;
}
yield();
delay(100);
}
return detectedBaudrate;
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void hexdump(const void *mem, uint32_t len, uint8_t cols)
}
src += linesize;
len -= linesize;
yield();
optimistic_yield(10000);
}
os_printf("\n");
}
2 changes: 1 addition & 1 deletion libraries/ESP8266AVRISP/src/ESP8266AVRISP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ uint8_t ESP8266AVRISP::write_flash_pages(int length) {
int x = 0;
int page = addr_page(here);
while (x < length) {
yield();
optimistic_yield(10000);
if (page != addr_page(here)) {
commit(page);
page = addr_page(here);
Expand Down
5 changes: 2 additions & 3 deletions libraries/ESP8266WiFi/src/ESP8266WiFiSTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,9 @@ int8_t ESP8266WiFiSTAClass::waitForConnectResult(unsigned long timeoutLength) {
if((wifi_get_opmode() & 1) == 0) {
return WL_DISCONNECTED;
}
using esp8266::polledTimeout::oneShot;
oneShot timeout(timeoutLength); // number of milliseconds to wait before returning timeout error
using oneShotYieldMs = esp8266::polledTimeout::timeoutTemplate<false, esp8266::polledTimeout::YieldPolicy::YieldOrSkip>;
oneShotYieldMs timeout(timeoutLength); // number of milliseconds to wait before returning timeout error
while(!timeout) {
yield();
if(status() != WL_DISCONNECTED) {
return status();
}
Expand Down
30 changes: 15 additions & 15 deletions libraries/ESP8266WiFiMesh/src/ESP8266WiFiMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ IPAddress ESP8266WiFiMesh::getStaticIP()
void ESP8266WiFiMesh::disableStaticIP()
{
WiFi.config(0u,0u,0u);
yield();
optimistic_yield(10000);
staticIPActivated = false;
}

Expand Down Expand Up @@ -185,9 +185,9 @@ void ESP8266WiFiMesh::deactivateAP()
void ESP8266WiFiMesh::restartAP()
{
deactivateAP();
yield();
optimistic_yield(10000);
activateAP();
yield();
optimistic_yield(10000);
}

ESP8266WiFiMesh * ESP8266WiFiMesh::getAPController()
Expand Down Expand Up @@ -331,9 +331,9 @@ bool ESP8266WiFiMesh::latestTransmissionSuccessful()
void ESP8266WiFiMesh::fullStop(WiFiClient &currClient)
{
currClient.stop();
yield();
optimistic_yield(10000);
WiFi.disconnect();
yield();
optimistic_yield(10000);
}

/**
Expand Down Expand Up @@ -375,7 +375,7 @@ transmission_status_t ESP8266WiFiMesh::exchangeInfo(WiFiClient &currClient)
verboseModePrint("Transmitting"); // Not storing strings in flash (via F()) to avoid performance impacts when using the string.

currClient.print(getMessage() + '\r');
yield();
optimistic_yield(10000);

if (!waitForClientTransmission(currClient, _stationModeTimeoutMs))
{
Expand All @@ -390,7 +390,7 @@ transmission_status_t ESP8266WiFiMesh::exchangeInfo(WiFiClient &currClient)
}

String response = currClient.readStringUntil('\r');
yield();
optimistic_yield(10000);
currClient.flush();

/* Pass data to user callback */
Expand Down Expand Up @@ -443,7 +443,7 @@ transmission_status_t ESP8266WiFiMesh::attemptDataTransferKernel()
}

currClient.stop();
yield();
optimistic_yield(10000);

return transmissionOutcome;
}
Expand Down Expand Up @@ -476,7 +476,7 @@ transmission_status_t ESP8266WiFiMesh::connectToNode(const String &targetSSID, i
WiFiMode_t storedWiFiMode = WiFi.getMode();
WiFi.mode(WIFI_OFF);
WiFi.mode(storedWiFiMode);
yield();
optimistic_yield(10000);

#else
// Disable static IP so that we can connect to other servers via DHCP (DHCP is slower but required for connecting to more than one server, it seems (possible bug?)).
Expand All @@ -500,7 +500,7 @@ transmission_status_t ESP8266WiFiMesh::connectToNode(const String &targetSSID, i
{
verboseModePrint(F("... "), false);
WiFi.disconnect();
yield();
optimistic_yield(10000);
initiateConnectionToAP(targetSSID, targetChannel, targetBSSID);
attemptNumber++;
}
Expand All @@ -527,7 +527,7 @@ void ESP8266WiFiMesh::attemptTransmission(const String &message, bool concluding
if(initialDisconnect)
{
WiFi.disconnect();
yield();
optimistic_yield(10000);
}

latestTransmissionOutcomes.clear();
Expand Down Expand Up @@ -565,7 +565,7 @@ void ESP8266WiFiMesh::attemptTransmission(const String &message, bool concluding
for(NetworkInfo &currentNetwork : connectionQueue)
{
WiFi.disconnect();
yield();
optimistic_yield(10000);

String currentSSID;
int currentWiFiChannel = NETWORK_INFO_DEFAULT_INT;
Expand Down Expand Up @@ -614,7 +614,7 @@ void ESP8266WiFiMesh::attemptTransmission(const String &message, bool concluding
if(concludingDisconnect)
{
WiFi.disconnect();
yield();
optimistic_yield(10000);
}
}

Expand Down Expand Up @@ -658,7 +658,7 @@ void ESP8266WiFiMesh::acceptRequest()

/* Read in request and pass it to the supplied requestHandler */
String request = _client.readStringUntil('\r');
yield();
optimistic_yield(10000);
_client.flush();

String response = _requestHandler(request, *this);
Expand All @@ -669,7 +669,7 @@ void ESP8266WiFiMesh::acceptRequest()
verboseModePrint("Responding"); // Not storing strings in flash (via F()) to avoid performance impacts when using the string.
_client.print(response + '\r');
_client.flush();
yield();
optimistic_yield(10000);
}
}
}
Expand Down

0 comments on commit f382fc9

Please sign in to comment.