mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-15 19:14:06 +02:00
Regularized millisecond delay code.
This commit is contained in:
@@ -115,7 +115,7 @@ namespace Pins {
|
|||||||
// This method basically ensures we don't flood users:
|
// This method basically ensures we don't flood users:
|
||||||
auto time = millis();
|
auto time = millis();
|
||||||
|
|
||||||
if (uint32_t(_lastEvent + 1000) < time) {
|
if ((time - _lastEvent) > 1000) {
|
||||||
_lastEvent = time;
|
_lastEvent = time;
|
||||||
_eventCount = 1;
|
_eventCount = 1;
|
||||||
return true;
|
return true;
|
||||||
|
@@ -24,9 +24,9 @@ namespace Pins {
|
|||||||
class DebugPinDetail : public PinDetail {
|
class DebugPinDetail : public PinDetail {
|
||||||
PinDetail* _implementation;
|
PinDetail* _implementation;
|
||||||
|
|
||||||
int _lastEvent;
|
uint32_t _lastEvent;
|
||||||
int _eventCount;
|
int _eventCount;
|
||||||
bool _isHigh;
|
bool _isHigh;
|
||||||
|
|
||||||
struct CallbackHandler {
|
struct CallbackHandler {
|
||||||
void (*callback)(void* arg);
|
void (*callback)(void* arg);
|
||||||
|
@@ -41,10 +41,10 @@ namespace WebUI {
|
|||||||
* delay is to avoid with asyncwebserver and may need to wait sometimes
|
* delay is to avoid with asyncwebserver and may need to wait sometimes
|
||||||
*/
|
*/
|
||||||
void COMMANDS::wait(uint32_t milliseconds) {
|
void COMMANDS::wait(uint32_t milliseconds) {
|
||||||
uint32_t timeout = millis();
|
uint32_t start_time = millis();
|
||||||
esp_task_wdt_reset(); //for a wait 0;
|
esp_task_wdt_reset(); //for a wait 0;
|
||||||
//wait feeding WDT
|
//wait feeding WDT
|
||||||
while ((millis() - timeout) < milliseconds) {
|
while ((millis() - start_time) < milliseconds) {
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -66,8 +66,8 @@ namespace WebUI {
|
|||||||
bool Wait4Answer(WiFiClientSecure& client, const char* linetrigger, const char* expected_answer, uint32_t timeout) {
|
bool Wait4Answer(WiFiClientSecure& client, const char* linetrigger, const char* expected_answer, uint32_t timeout) {
|
||||||
if (client.connected()) {
|
if (client.connected()) {
|
||||||
String answer;
|
String answer;
|
||||||
uint32_t starttimeout = millis();
|
uint32_t start_time = millis();
|
||||||
while (client.connected() && ((millis() - starttimeout) < timeout)) {
|
while (client.connected() && ((millis() - start_time) < timeout)) {
|
||||||
answer = client.readStringUntil('\n');
|
answer = client.readStringUntil('\n');
|
||||||
log_d("Answer: %s", answer.c_str());
|
log_d("Answer: %s", answer.c_str());
|
||||||
if ((answer.indexOf(linetrigger) != -1) || (strlen(linetrigger) == 0)) {
|
if ((answer.indexOf(linetrigger) != -1) || (strlen(linetrigger) == 0)) {
|
||||||
|
@@ -887,8 +887,8 @@ namespace WebUI {
|
|||||||
_webserver->send(web_error, "text/xml", st);
|
_webserver->send(web_error, "text/xml", st);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t t = millis();
|
uint32_t start_time = millis();
|
||||||
while (millis() - t < timeout) {
|
while ((millis() - start_time) < timeout) {
|
||||||
_socket_server->loop();
|
_socket_server->loop();
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
@@ -1530,7 +1530,7 @@ namespace WebUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Web_Server::handle() {
|
void Web_Server::handle() {
|
||||||
static uint32_t timeout = millis();
|
static uint32_t start_time = millis();
|
||||||
COMMANDS::wait(0);
|
COMMANDS::wait(0);
|
||||||
if (WiFi.getMode() == WIFI_AP) {
|
if (WiFi.getMode() == WIFI_AP) {
|
||||||
dnsServer.processNextRequest();
|
dnsServer.processNextRequest();
|
||||||
@@ -1541,11 +1541,11 @@ namespace WebUI {
|
|||||||
if (_socket_server && _setupdone) {
|
if (_socket_server && _setupdone) {
|
||||||
_socket_server->loop();
|
_socket_server->loop();
|
||||||
}
|
}
|
||||||
if ((millis() - timeout) > 10000 && _socket_server) {
|
if ((millis() - start_time) > 10000 && _socket_server) {
|
||||||
String s = "PING:";
|
String s = "PING:";
|
||||||
s += String(_id_connection);
|
s += String(_id_connection);
|
||||||
_socket_server->broadcastTXT(s);
|
_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* Web_Server::GetAuth(IPAddress ip, const char* sessionID) {
|
||||||
AuthenticationIP* current = _head;
|
AuthenticationIP* current = _head;
|
||||||
//AuthenticationIP * previous = NULL;
|
//AuthenticationIP * previous = NULL;
|
||||||
//get time
|
|
||||||
//uint32_t now = millis();
|
|
||||||
while (current) {
|
while (current) {
|
||||||
if (ip == current->ip) {
|
if (ip == current->ip) {
|
||||||
if (strcmp(sessionID, current->sessionID) == 0) {
|
if (strcmp(sessionID, current->sessionID) == 0) {
|
||||||
@@ -1747,8 +1745,6 @@ namespace WebUI {
|
|||||||
AuthenticationLevel Web_Server::ResetAuthIP(IPAddress ip, const char* sessionID) {
|
AuthenticationLevel Web_Server::ResetAuthIP(IPAddress ip, const char* sessionID) {
|
||||||
AuthenticationIP* current = _head;
|
AuthenticationIP* current = _head;
|
||||||
AuthenticationIP* previous = NULL;
|
AuthenticationIP* previous = NULL;
|
||||||
//get time
|
|
||||||
//uint32_t now = millis();
|
|
||||||
while (current) {
|
while (current) {
|
||||||
if ((millis() - current->last_time) > 360000) {
|
if ((millis() - current->last_time) > 360000) {
|
||||||
//remove
|
//remove
|
||||||
|
@@ -36,7 +36,7 @@ int Stream::timedRead() {
|
|||||||
if (c >= 0) {
|
if (c >= 0) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
} while (millis() - _startMillis < _timeout);
|
} while ((millis() - _startMillis) < _timeout);
|
||||||
return -1; // -1 indicates timeout
|
return -1; // -1 indicates timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ int Stream::timedPeek() {
|
|||||||
if (c >= 0) {
|
if (c >= 0) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
} while (millis() - _startMillis < _timeout);
|
} while ((millis() - _startMillis) < _timeout);
|
||||||
return -1; // -1 indicates timeout
|
return -1; // -1 indicates timeout
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user