@@ -465,43 +465,49 @@ int MySensor::getInternalTemp(void)
465465 return result/10000 ;
466466}
467467
468- int continueTimer = true ;
468+ int8_t pinIntTrigger = 0 ;
469469void wakeUp () // place to send the interrupts
470470{
471- continueTimer = false ;
471+ pinIntTrigger = 1 ;
472+ }
473+ void wakeUp2 () // place to send the second interrupts
474+ {
475+ pinIntTrigger = 2 ;
472476}
473477
474478void MySensor::internalSleep (unsigned long ms) {
475- while (continueTimer && ms >= 8000 ) { LowPower.powerDown (SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000 ; }
476- if (continueTimer && ms >= 4000 ) { LowPower.powerDown (SLEEP_4S, ADC_OFF, BOD_OFF); ms -= 4000 ; }
477- if (continueTimer && ms >= 2000 ) { LowPower.powerDown (SLEEP_2S, ADC_OFF, BOD_OFF); ms -= 2000 ; }
478- if (continueTimer && ms >= 1000 ) { LowPower.powerDown (SLEEP_1S, ADC_OFF, BOD_OFF); ms -= 1000 ; }
479- if (continueTimer && ms >= 500 ) { LowPower.powerDown (SLEEP_500MS, ADC_OFF, BOD_OFF); ms -= 500 ; }
480- if (continueTimer && ms >= 250 ) { LowPower.powerDown (SLEEP_250MS, ADC_OFF, BOD_OFF); ms -= 250 ; }
481- if (continueTimer && ms >= 125 ) { LowPower.powerDown (SLEEP_120MS, ADC_OFF, BOD_OFF); ms -= 120 ; }
482- if (continueTimer && ms >= 64 ) { LowPower.powerDown (SLEEP_60MS, ADC_OFF, BOD_OFF); ms -= 60 ; }
483- if (continueTimer && ms >= 32 ) { LowPower.powerDown (SLEEP_30MS, ADC_OFF, BOD_OFF); ms -= 30 ; }
484- if (continueTimer && ms >= 16 ) { LowPower.powerDown (SLEEP_15Ms, ADC_OFF, BOD_OFF); ms -= 15 ; }
479+ while (!pinIntTrigger && ms >= 8000 ) { LowPower.powerDown (SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000 ; }
480+ if (!pinIntTrigger && ms >= 4000 ) { LowPower.powerDown (SLEEP_4S, ADC_OFF, BOD_OFF); ms -= 4000 ; }
481+ if (!pinIntTrigger && ms >= 2000 ) { LowPower.powerDown (SLEEP_2S, ADC_OFF, BOD_OFF); ms -= 2000 ; }
482+ if (!pinIntTrigger && ms >= 1000 ) { LowPower.powerDown (SLEEP_1S, ADC_OFF, BOD_OFF); ms -= 1000 ; }
483+ if (!pinIntTrigger && ms >= 500 ) { LowPower.powerDown (SLEEP_500MS, ADC_OFF, BOD_OFF); ms -= 500 ; }
484+ if (!pinIntTrigger && ms >= 250 ) { LowPower.powerDown (SLEEP_250MS, ADC_OFF, BOD_OFF); ms -= 250 ; }
485+ if (!pinIntTrigger && ms >= 125 ) { LowPower.powerDown (SLEEP_120MS, ADC_OFF, BOD_OFF); ms -= 120 ; }
486+ if (!pinIntTrigger && ms >= 64 ) { LowPower.powerDown (SLEEP_60MS, ADC_OFF, BOD_OFF); ms -= 60 ; }
487+ if (!pinIntTrigger && ms >= 32 ) { LowPower.powerDown (SLEEP_30MS, ADC_OFF, BOD_OFF); ms -= 30 ; }
488+ if (!pinIntTrigger && ms >= 16 ) { LowPower.powerDown (SLEEP_15Ms, ADC_OFF, BOD_OFF); ms -= 15 ; }
485489}
486490
487491void MySensor::sleep (unsigned long ms) {
488492 // Let serial prints finish (debug, log etc)
489493 Serial.flush ();
490494 RF24::powerDown ();
491- continueTimer = true ;
495+ pinIntTrigger = 0 ;
492496 internalSleep (ms);
493497}
494498
495- bool MySensor::sleep (int interrupt, int mode, unsigned long ms) {
499+ bool MySensor::sleep (uint8_t interrupt, uint8_t mode, unsigned long ms) {
496500 // Let serial prints finish (debug, log etc)
497501 bool pinTriggeredWakeup = true ;
498502 Serial.flush ();
499503 RF24::powerDown ();
500- attachInterrupt (interrupt, wakeUp, mode); // Interrupt on pin 3 for any change in solar power
504+ attachInterrupt (interrupt, wakeUp, mode);
501505 if (ms>0 ) {
502- continueTimer = true ;
506+ pinIntTrigger = 0 ;
503507 sleep (ms);
504- pinTriggeredWakeup = !continueTimer;
508+ if (0 == pinIntTrigger) {
509+ pinTriggeredWakeup = false ;
510+ }
505511 } else {
506512 Serial.flush ();
507513 LowPower.powerDown (SLEEP_FOREVER, ADC_OFF, BOD_OFF);
@@ -510,7 +516,32 @@ bool MySensor::sleep(int interrupt, int mode, unsigned long ms) {
510516 return pinTriggeredWakeup;
511517}
512518
519+ int8_t MySensor::sleep (uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
520+ int8_t retVal = 1 ;
521+ Serial.flush (); // Let serial prints finish (debug, log etc)
522+ RF24::powerDown ();
523+ attachInterrupt (interrupt1, wakeUp, mode1);
524+ attachInterrupt (interrupt2, wakeUp2, mode2);
525+ if (ms>0 ) {
526+ pinIntTrigger = 0 ;
527+ sleep (ms);
528+ if (0 == pinIntTrigger) {
529+ retVal = -1 ;
530+ }
531+ } else {
532+ Serial.flush ();
533+ LowPower.powerDown (SLEEP_FOREVER, ADC_OFF, BOD_OFF);
534+ }
535+ detachInterrupt (interrupt1);
536+ detachInterrupt (interrupt2);
513537
538+ if (1 == pinIntTrigger) {
539+ retVal = (int8_t )interrupt1;
540+ } else if (2 == pinIntTrigger) {
541+ retVal = (int8_t )interrupt2;
542+ }
543+ return retVal;
544+ }
514545
515546#ifdef DEBUG
516547void MySensor::debugPrint (const char *fmt, ... ) {
0 commit comments