diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index 6518520..07f8423 100755 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -490,6 +490,23 @@ void MySensor::sleep(unsigned long ms) { internalSleep(ms); } +void MySensor::wait(unsigned long ms) { + bool slept_enough = false; + unsigned long start = millis(); + unsigned long now; + + // Let serial prints finish (debug, log etc) + Serial.flush(); + + while (!slept_enough) { + MySensor::process(); + now = millis(); + if (now - start > ms) { + slept_enough = true; + } + } +} + bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) { // Let serial prints finish (debug, log etc) bool pinTriggeredWakeup = true; diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index 9abf5fb..571367b 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -210,6 +210,15 @@ class MySensor : public RF24 */ void sleep(unsigned long ms); + /** + * Wait for a specified amount of time to pass. Keeps process()ing. + * This does not power-down the radio nor the Arduino. + * Because this calls process() in a loop, it is a good way to wait + * in your loop() on a repeater node or sensor that listens to messages. + * @param ms Number of milliseconds to sleep. + */ + void wait(unsigned long ms); + /** * Sleep (PowerDownMode) the Arduino and radio. Wake up on timer or pin change. * See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin