Added constructor to sleep() for monitoring two interrupts
The new constructor allows two separate interrupts with two separate trigger policies to wake up device.
This commit is contained in:
@@ -470,6 +470,10 @@ void wakeUp() //place to send the interrupts
|
||||
{
|
||||
pinIntTrigger = 1;
|
||||
}
|
||||
void wakeUp2() //place to send the second interrupts
|
||||
{
|
||||
pinIntTrigger = 2;
|
||||
}
|
||||
|
||||
void MySensor::internalSleep(unsigned long ms) {
|
||||
while (!pinIntTrigger && ms >= 8000) { LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000; }
|
||||
@@ -512,7 +516,32 @@ bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||
return pinTriggeredWakeup;
|
||||
}
|
||||
|
||||
int8_t MySensor::sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
|
||||
int8_t retVal = 1;
|
||||
Serial.flush(); // Let serial prints finish (debug, log etc)
|
||||
RF24::powerDown();
|
||||
attachInterrupt(interrupt1, wakeUp, mode1);
|
||||
attachInterrupt(interrupt2, wakeUp2, mode2);
|
||||
if (ms>0) {
|
||||
pinIntTrigger = 0;
|
||||
sleep(ms);
|
||||
if (0 == pinIntTrigger) {
|
||||
retVal = -1;
|
||||
}
|
||||
} else {
|
||||
Serial.flush();
|
||||
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
|
||||
}
|
||||
detachInterrupt(interrupt1);
|
||||
detachInterrupt(interrupt2);
|
||||
|
||||
if (1 == pinIntTrigger) {
|
||||
retVal = (int8_t)interrupt1;
|
||||
} else if (2 == pinIntTrigger) {
|
||||
retVal = (int8_t)interrupt2;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
void MySensor::debugPrint(const char *fmt, ... ) {
|
||||
|
||||
@@ -221,6 +221,19 @@ class MySensor : public RF24
|
||||
*/
|
||||
bool sleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
||||
|
||||
/**
|
||||
* Sleep (PowerDownMode) the Arduino and radio. Wake up on timer or pin change for two separate interrupts.
|
||||
* See: http://arduino.cc/en/Reference/attachInterrupt for details on modes and which pin
|
||||
* is assigned to what interrupt. On Nano/Pro Mini: 0=Pin2, 1=Pin3
|
||||
* @param interrupt1 First interrupt that should trigger the wakeup
|
||||
* @param mode1 Mode for first interrupt (RISING, FALLING, CHANGE)
|
||||
* @param interrupt2 Second interrupt that should trigger the wakeup
|
||||
* @param mode2 Mode for second interrupt (RISING, FALLING, CHANGE)
|
||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||
* @return Interrupt number wake up was triggered by pin change and negative if timer woke it up.
|
||||
*/
|
||||
int8_t sleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms=0);
|
||||
|
||||
/**
|
||||
* getInternalTemp
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user