Add wait() helper that doesn't sleep. Useful for repeaters and sensors that read from the network.

This commit is contained in:
Roy Hooper
2015-02-01 15:00:45 -05:00
parent dfd38ff3bc
commit d45a48d8b7
2 changed files with 26 additions and 0 deletions
+17
View File
@@ -486,6 +486,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;
+9
View File
@@ -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