Skip to content

Commit 78d0579

Browse files
committed
improve timeout loops for millis() rollover
1 parent 92dd9fe commit 78d0579

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/GSMPIN.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int GSMPIN::isPIN()
3535
{
3636
String response;
3737

38-
for (unsigned long start = millis(); millis() < (start + 1000);) {
38+
for (unsigned long start = millis(); (millis() - start) < 1000;) {
3939
MODEM.send("AT+CPIN?");
4040

4141
if (MODEM.waitForResponse(10000, &response) == 1) {
@@ -124,7 +124,7 @@ void GSMPIN::switchPIN(String pin)
124124

125125
int GSMPIN::checkReg()
126126
{
127-
for (unsigned long start = millis(); millis() < (start + 10000L);) {
127+
for (unsigned long start = millis(); (millis() - start) < 10000L;) {
128128
MODEM.send("AT+CREG?");
129129

130130
String response = "";

src/GSMVoiceCall.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int GSMVoiceCall::voiceCall(const char* to, unsigned long timeout)
6363
}
6464

6565
_callStatus = CALLING;
66-
for (unsigned long start = millis(); (timeout == 0) || (millis() < (start + timeout));) {
66+
for (unsigned long start = millis(); (timeout == 0) || ((millis() - start) < timeout);) {
6767
if (getvoiceCallStatus() != CALLING) {
6868
break;
6969
}

src/Modem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void ModemClass::debug()
103103

104104
int ModemClass::autosense(int timeout)
105105
{
106-
for (unsigned long start = millis(); millis() < (start + timeout);) {
106+
for (unsigned long start = millis(); (millis() - start) < timeout;) {
107107
if (noop() == 1) {
108108
return 1;
109109
}
@@ -186,7 +186,7 @@ void ModemClass::sendf(const char *fmt, ...)
186186
int ModemClass::waitForResponse(unsigned long timeout, String* responseDataStorage)
187187
{
188188
_responseDataStorage = responseDataStorage;
189-
for (unsigned long start = millis(); millis() < (start + timeout);) {
189+
for (unsigned long start = millis(); (millis() - start) < timeout;) {
190190
int r = ready();
191191

192192
if (r != 0) {

0 commit comments

Comments
 (0)