@@ -465,43 +465,45 @@ int MySensor::getInternalTemp(void)
465
465
return result/10000 ;
466
466
}
467
467
468
- int continueTimer = true ;
468
+ int8_t pinIntTrigger = 0 ;
469
469
void wakeUp () // place to send the interrupts
470
470
{
471
- continueTimer = false ;
471
+ pinIntTrigger = 1 ;
472
472
}
473
473
474
474
void 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 ; }
485
485
}
486
486
487
487
void MySensor::sleep (unsigned long ms) {
488
488
// Let serial prints finish (debug, log etc)
489
489
Serial.flush ();
490
490
RF24::powerDown ();
491
- continueTimer = true ;
491
+ pinIntTrigger = 0 ;
492
492
internalSleep (ms);
493
493
}
494
494
495
- bool MySensor::sleep (int interrupt, int mode, unsigned long ms) {
495
+ bool MySensor::sleep (uint8_t interrupt, uint8_t mode, unsigned long ms) {
496
496
// Let serial prints finish (debug, log etc)
497
497
bool pinTriggeredWakeup = true ;
498
498
Serial.flush ();
499
499
RF24::powerDown ();
500
- attachInterrupt (interrupt, wakeUp, mode); // Interrupt on pin 3 for any change in solar power
500
+ attachInterrupt (interrupt, wakeUp, mode);
501
501
if (ms>0 ) {
502
- continueTimer = true ;
502
+ pinIntTrigger = 0 ;
503
503
sleep (ms);
504
- pinTriggeredWakeup = !continueTimer;
504
+ if (0 == pinIntTrigger) {
505
+ pinTriggeredWakeup = false ;
506
+ }
505
507
} else {
506
508
Serial.flush ();
507
509
LowPower.powerDown (SLEEP_FOREVER, ADC_OFF, BOD_OFF);
0 commit comments