Merge pull request #45 from rhooper/wait-helper

Add wait() helper that doesn't sleep.
This commit is contained in:
Henrik Ekblad
2015-02-03 22:06:17 +01:00
2 changed files with 26 additions and 0 deletions
+17
View File
@@ -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;
+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