@@ -450,43 +450,49 @@ uint8_t MySensor::getChildRoute(uint8_t childId) {
450450}
451451
452452
453- int continueTimer = true ;
453+ int8_t pinIntTrigger = 0 ;
454454void wakeUp () // place to send the interrupts
455455{
456- continueTimer = false ;
456+ pinIntTrigger = 1 ;
457+ }
458+ void wakeUp2 () // place to send the second interrupts
459+ {
460+ pinIntTrigger = 2 ;
457461}
458462
459463void MySensor::internalSleep (unsigned long ms) {
460- while (continueTimer && ms >= 8000 ) { LowPower.powerDown (SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000 ; }
461- if (continueTimer && ms >= 4000 ) { LowPower.powerDown (SLEEP_4S, ADC_OFF, BOD_OFF); ms -= 4000 ; }
462- if (continueTimer && ms >= 2000 ) { LowPower.powerDown (SLEEP_2S, ADC_OFF, BOD_OFF); ms -= 2000 ; }
463- if (continueTimer && ms >= 1000 ) { LowPower.powerDown (SLEEP_1S, ADC_OFF, BOD_OFF); ms -= 1000 ; }
464- if (continueTimer && ms >= 500 ) { LowPower.powerDown (SLEEP_500MS, ADC_OFF, BOD_OFF); ms -= 500 ; }
465- if (continueTimer && ms >= 250 ) { LowPower.powerDown (SLEEP_250MS, ADC_OFF, BOD_OFF); ms -= 250 ; }
466- if (continueTimer && ms >= 125 ) { LowPower.powerDown (SLEEP_120MS, ADC_OFF, BOD_OFF); ms -= 120 ; }
467- if (continueTimer && ms >= 64 ) { LowPower.powerDown (SLEEP_60MS, ADC_OFF, BOD_OFF); ms -= 60 ; }
468- if (continueTimer && ms >= 32 ) { LowPower.powerDown (SLEEP_30MS, ADC_OFF, BOD_OFF); ms -= 30 ; }
469- if (continueTimer && ms >= 16 ) { LowPower.powerDown (SLEEP_15Ms, ADC_OFF, BOD_OFF); ms -= 15 ; }
464+ while (!pinIntTrigger && ms >= 8000 ) { LowPower.powerDown (SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000 ; }
465+ if (!pinIntTrigger && ms >= 4000 ) { LowPower.powerDown (SLEEP_4S, ADC_OFF, BOD_OFF); ms -= 4000 ; }
466+ if (!pinIntTrigger && ms >= 2000 ) { LowPower.powerDown (SLEEP_2S, ADC_OFF, BOD_OFF); ms -= 2000 ; }
467+ if (!pinIntTrigger && ms >= 1000 ) { LowPower.powerDown (SLEEP_1S, ADC_OFF, BOD_OFF); ms -= 1000 ; }
468+ if (!pinIntTrigger && ms >= 500 ) { LowPower.powerDown (SLEEP_500MS, ADC_OFF, BOD_OFF); ms -= 500 ; }
469+ if (!pinIntTrigger && ms >= 250 ) { LowPower.powerDown (SLEEP_250MS, ADC_OFF, BOD_OFF); ms -= 250 ; }
470+ if (!pinIntTrigger && ms >= 125 ) { LowPower.powerDown (SLEEP_120MS, ADC_OFF, BOD_OFF); ms -= 120 ; }
471+ if (!pinIntTrigger && ms >= 64 ) { LowPower.powerDown (SLEEP_60MS, ADC_OFF, BOD_OFF); ms -= 60 ; }
472+ if (!pinIntTrigger && ms >= 32 ) { LowPower.powerDown (SLEEP_30MS, ADC_OFF, BOD_OFF); ms -= 30 ; }
473+ if (!pinIntTrigger && ms >= 16 ) { LowPower.powerDown (SLEEP_15Ms, ADC_OFF, BOD_OFF); ms -= 15 ; }
470474}
471475
472476void MySensor::sleep (unsigned long ms) {
473477 // Let serial prints finish (debug, log etc)
474478 Serial.flush ();
475479 RF24::powerDown ();
476- continueTimer = true ;
480+ pinIntTrigger = 0 ;
477481 internalSleep (ms);
478482}
479483
480- bool MySensor::sleep (int interrupt, int mode, unsigned long ms) {
484+ bool MySensor::sleep (uint8_t interrupt, uint8_t mode, unsigned long ms) {
481485 // Let serial prints finish (debug, log etc)
482486 bool pinTriggeredWakeup = true ;
483487 Serial.flush ();
484488 RF24::powerDown ();
485- attachInterrupt (interrupt, wakeUp, mode); // Interrupt on pin 3 for any change in solar power
489+ attachInterrupt (interrupt, wakeUp, mode);
486490 if (ms>0 ) {
487- continueTimer = true ;
491+ pinIntTrigger = 0 ;
488492 sleep (ms);
489- pinTriggeredWakeup = !continueTimer;
493+ if (0 == pinIntTrigger) {
494+ pinTriggeredWakeup = false ;
495+ }
490496 } else {
491497 Serial.flush ();
492498 LowPower.powerDown (SLEEP_FOREVER, ADC_OFF, BOD_OFF);
@@ -495,7 +501,32 @@ bool MySensor::sleep(int interrupt, int mode, unsigned long ms) {
495501 return pinTriggeredWakeup;
496502}
497503
504+ int8_t MySensor::sleep (uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mode2, unsigned long ms) {
505+ int8_t retVal = 1 ;
506+ Serial.flush (); // Let serial prints finish (debug, log etc)
507+ RF24::powerDown ();
508+ attachInterrupt (interrupt1, wakeUp, mode1);
509+ attachInterrupt (interrupt2, wakeUp2, mode2);
510+ if (ms>0 ) {
511+ pinIntTrigger = 0 ;
512+ sleep (ms);
513+ if (0 == pinIntTrigger) {
514+ retVal = -1 ;
515+ }
516+ } else {
517+ Serial.flush ();
518+ LowPower.powerDown (SLEEP_FOREVER, ADC_OFF, BOD_OFF);
519+ }
520+ detachInterrupt (interrupt1);
521+ detachInterrupt (interrupt2);
498522
523+ if (1 == pinIntTrigger) {
524+ retVal = (int8_t )interrupt1;
525+ } else if (2 == pinIntTrigger) {
526+ retVal = (int8_t )interrupt2;
527+ }
528+ return retVal;
529+ }
499530
500531#ifdef DEBUG
501532void MySensor::debugPrint (const char *fmt, ... ) {
0 commit comments