1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-15 11:04:16 +02:00

Regularized millisecond delay code.

This commit is contained in:
Mitch Bradley
2021-07-28 11:11:44 -10:00
parent 2c3982d520
commit 4260eb8446
6 changed files with 15 additions and 19 deletions

View File

@@ -115,7 +115,7 @@ namespace Pins {
// This method basically ensures we don't flood users:
auto time = millis();
if (uint32_t(_lastEvent + 1000) < time) {
if ((time - _lastEvent) > 1000) {
_lastEvent = time;
_eventCount = 1;
return true;

View File

@@ -24,9 +24,9 @@ namespace Pins {
class DebugPinDetail : public PinDetail {
PinDetail* _implementation;
int _lastEvent;
int _eventCount;
bool _isHigh;
uint32_t _lastEvent;
int _eventCount;
bool _isHigh;
struct CallbackHandler {
void (*callback)(void* arg);

View File

@@ -41,10 +41,10 @@ namespace WebUI {
* delay is to avoid with asyncwebserver and may need to wait sometimes
*/
void COMMANDS::wait(uint32_t milliseconds) {
uint32_t timeout = millis();
uint32_t start_time = millis();
esp_task_wdt_reset(); //for a wait 0;
//wait feeding WDT
while ((millis() - timeout) < milliseconds) {
while ((millis() - start_time) < milliseconds) {
esp_task_wdt_reset();
}
}

View File

@@ -66,8 +66,8 @@ namespace WebUI {
bool Wait4Answer(WiFiClientSecure& client, const char* linetrigger, const char* expected_answer, uint32_t timeout) {
if (client.connected()) {
String answer;
uint32_t starttimeout = millis();
while (client.connected() && ((millis() - starttimeout) < timeout)) {
uint32_t start_time = millis();
while (client.connected() && ((millis() - start_time) < timeout)) {
answer = client.readStringUntil('\n');
log_d("Answer: %s", answer.c_str());
if ((answer.indexOf(linetrigger) != -1) || (strlen(linetrigger) == 0)) {

View File

@@ -887,8 +887,8 @@ namespace WebUI {
_webserver->send(web_error, "text/xml", st);
}
uint32_t t = millis();
while (millis() - t < timeout) {
uint32_t start_time = millis();
while ((millis() - start_time) < timeout) {
_socket_server->loop();
delay(10);
}
@@ -1530,7 +1530,7 @@ namespace WebUI {
}
void Web_Server::handle() {
static uint32_t timeout = millis();
static uint32_t start_time = millis();
COMMANDS::wait(0);
if (WiFi.getMode() == WIFI_AP) {
dnsServer.processNextRequest();
@@ -1541,11 +1541,11 @@ namespace WebUI {
if (_socket_server && _setupdone) {
_socket_server->loop();
}
if ((millis() - timeout) > 10000 && _socket_server) {
if ((millis() - start_time) > 10000 && _socket_server) {
String s = "PING:";
s += String(_id_connection);
_socket_server->broadcastTXT(s);
timeout = millis();
start_time = millis();
}
}
@@ -1728,8 +1728,6 @@ namespace WebUI {
AuthenticationIP* Web_Server::GetAuth(IPAddress ip, const char* sessionID) {
AuthenticationIP* current = _head;
//AuthenticationIP * previous = NULL;
//get time
//uint32_t now = millis();
while (current) {
if (ip == current->ip) {
if (strcmp(sessionID, current->sessionID) == 0) {
@@ -1747,8 +1745,6 @@ namespace WebUI {
AuthenticationLevel Web_Server::ResetAuthIP(IPAddress ip, const char* sessionID) {
AuthenticationIP* current = _head;
AuthenticationIP* previous = NULL;
//get time
//uint32_t now = millis();
while (current) {
if ((millis() - current->last_time) > 360000) {
//remove

View File

@@ -36,7 +36,7 @@ int Stream::timedRead() {
if (c >= 0) {
return c;
}
} while (millis() - _startMillis < _timeout);
} while ((millis() - _startMillis) < _timeout);
return -1; // -1 indicates timeout
}
@@ -49,7 +49,7 @@ int Stream::timedPeek() {
if (c >= 0) {
return c;
}
} while (millis() - _startMillis < _timeout);
} while ((millis() - _startMillis) < _timeout);
return -1; // -1 indicates timeout
}
*/