Merge pull request #45 from rhooper/wait-helper
Add wait() helper that doesn't sleep.
This commit is contained in:
@@ -490,6 +490,23 @@ void MySensor::sleep(unsigned long ms) {
|
|||||||
internalSleep(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) {
|
bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||||
// Let serial prints finish (debug, log etc)
|
// Let serial prints finish (debug, log etc)
|
||||||
bool pinTriggeredWakeup = true;
|
bool pinTriggeredWakeup = true;
|
||||||
|
|||||||
@@ -210,6 +210,15 @@ class MySensor : public RF24
|
|||||||
*/
|
*/
|
||||||
void sleep(unsigned long ms);
|
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.
|
* 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
|
* See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin
|
||||||
|
|||||||
Reference in New Issue
Block a user