@@ -465,43 +465,45 @@ 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 ;
472472}
473473
474474void 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 ; }
475+ while (!pinIntTrigger && ms >= 8000 ) { LowPower.powerDown (SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000 ; }
476+ if (!pinIntTrigger && ms >= 4000 ) { LowPower.powerDown (SLEEP_4S, ADC_OFF, BOD_OFF); ms -= 4000 ; }
477+ if (!pinIntTrigger && ms >= 2000 ) { LowPower.powerDown (SLEEP_2S, ADC_OFF, BOD_OFF); ms -= 2000 ; }
478+ if (!pinIntTrigger && ms >= 1000 ) { LowPower.powerDown (SLEEP_1S, ADC_OFF, BOD_OFF); ms -= 1000 ; }
479+ if (!pinIntTrigger && ms >= 500 ) { LowPower.powerDown (SLEEP_500MS, ADC_OFF, BOD_OFF); ms -= 500 ; }
480+ if (!pinIntTrigger && ms >= 250 ) { LowPower.powerDown (SLEEP_250MS, ADC_OFF, BOD_OFF); ms -= 250 ; }
481+ if (!pinIntTrigger && ms >= 125 ) { LowPower.powerDown (SLEEP_120MS, ADC_OFF, BOD_OFF); ms -= 120 ; }
482+ if (!pinIntTrigger && ms >= 64 ) { LowPower.powerDown (SLEEP_60MS, ADC_OFF, BOD_OFF); ms -= 60 ; }
483+ if (!pinIntTrigger && ms >= 32 ) { LowPower.powerDown (SLEEP_30MS, ADC_OFF, BOD_OFF); ms -= 30 ; }
484+ if (!pinIntTrigger && ms >= 16 ) { LowPower.powerDown (SLEEP_15Ms, ADC_OFF, BOD_OFF); ms -= 15 ; }
485485}
486486
487487void MySensor::sleep (unsigned long ms) {
488488 // Let serial prints finish (debug, log etc)
489489 Serial.flush ();
490490 RF24::powerDown ();
491- continueTimer = true ;
491+ pinIntTrigger = 0 ;
492492 internalSleep (ms);
493493}
494494
495- bool MySensor::sleep (int interrupt, int mode, unsigned long ms) {
495+ bool MySensor::sleep (uint8_t interrupt, uint8_t mode, unsigned long ms) {
496496 // Let serial prints finish (debug, log etc)
497497 bool pinTriggeredWakeup = true ;
498498 Serial.flush ();
499499 RF24::powerDown ();
500- attachInterrupt (interrupt, wakeUp, mode); // Interrupt on pin 3 for any change in solar power
500+ attachInterrupt (interrupt, wakeUp, mode);
501501 if (ms>0 ) {
502- continueTimer = true ;
502+ pinIntTrigger = 0 ;
503503 sleep (ms);
504- pinTriggeredWakeup = !continueTimer;
504+ if (0 == pinIntTrigger) {
505+ pinTriggeredWakeup = false ;
506+ }
505507 } else {
506508 Serial.flush ();
507509 LowPower.powerDown (SLEEP_FOREVER, ADC_OFF, BOD_OFF);
0 commit comments