Skip to content

Commit 722a23c

Browse files
committed
Merge pull request arduino#58 from tekka007/Hotfix
simplify wait(), substitute waitForReply(), adding watchdog resets
2 parents 5a0d773 + 08a0bc2 commit 722a23c

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

libraries/MySensors/MySensor.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void MySensor::begin(void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, b
8282
if (nc.nodeId != AUTO) {
8383
setupNode();
8484
// Wait configuration reply.
85-
waitForReply();
85+
wait(2000);
8686
}
8787
}
8888

@@ -127,7 +127,7 @@ void MySensor::requestNodeId() {
127127
debug(PSTR("req node id\n"));
128128
RF24::openReadingPipe(CURRENT_NODE_PIPE, TO_ADDR(nc.nodeId));
129129
sendRoute(build(msg, nc.nodeId, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_ID_REQUEST, false).set(""));
130-
waitForReply();
130+
wait(2000);
131131
}
132132

133133
void MySensor::setupNode() {
@@ -155,13 +155,15 @@ void MySensor::findParentNode() {
155155
sendWrite(BROADCAST_ADDRESS, msg, true);
156156

157157
// Wait for ping response.
158-
waitForReply();
158+
wait(2000);
159159
}
160160

161161
void MySensor::waitForReply() {
162162
unsigned long enter = millis();
163163
// Wait a couple of seconds for response
164164
while (millis() - enter < 2000) {
165+
// reset watchdog
166+
wdt_reset();
165167
process();
166168
}
167169
}
@@ -498,19 +500,13 @@ void MySensor::sleep(unsigned long ms) {
498500
}
499501

500502
void MySensor::wait(unsigned long ms) {
501-
bool slept_enough = false;
502-
unsigned long start = millis();
503-
unsigned long now;
504-
505503
// Let serial prints finish (debug, log etc)
506504
Serial.flush();
507-
508-
while (!slept_enough) {
509-
MySensor::process();
510-
now = millis();
511-
if (now - start > ms) {
512-
slept_enough = true;
513-
}
505+
unsigned long enter = millis();
506+
while (millis() - enter < ms) {
507+
// reset watchdog
508+
wdt_reset();
509+
process();
514510
}
515511
}
516512

0 commit comments

Comments
 (0)