Skip to content

Commit e1fa3dc

Browse files
committed
Merge pull request arduino#45 from rhooper/wait-helper
Add wait() helper that doesn't sleep.
2 parents 03b10c7 + d45a48d commit e1fa3dc

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

libraries/MySensors/MySensor.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,23 @@ void MySensor::sleep(unsigned long ms) {
490490
internalSleep(ms);
491491
}
492492

493+
void MySensor::wait(unsigned long ms) {
494+
bool slept_enough = false;
495+
unsigned long start = millis();
496+
unsigned long now;
497+
498+
// Let serial prints finish (debug, log etc)
499+
Serial.flush();
500+
501+
while (!slept_enough) {
502+
MySensor::process();
503+
now = millis();
504+
if (now - start > ms) {
505+
slept_enough = true;
506+
}
507+
}
508+
}
509+
493510
bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
494511
// Let serial prints finish (debug, log etc)
495512
bool pinTriggeredWakeup = true;

libraries/MySensors/MySensor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ class MySensor : public RF24
210210
*/
211211
void sleep(unsigned long ms);
212212

213+
/**
214+
* Wait for a specified amount of time to pass. Keeps process()ing.
215+
* This does not power-down the radio nor the Arduino.
216+
* Because this calls process() in a loop, it is a good way to wait
217+
* in your loop() on a repeater node or sensor that listens to messages.
218+
* @param ms Number of milliseconds to sleep.
219+
*/
220+
void wait(unsigned long ms);
221+
213222
/**
214223
* Sleep (PowerDownMode) the Arduino and radio. Wake up on timer or pin change.
215224
* See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin

0 commit comments

Comments
 (0)