@@ -465,43 +465,49 @@ 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
+ }
473
+ void wakeUp2 () // place to send the second interrupts
474
+ {
475
+ pinIntTrigger = 2 ;
472
476
}
473
477
474
478
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 ; }
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 ; }
485
489
}
486
490
487
491
void MySensor::sleep (unsigned long ms) {
488
492
// Let serial prints finish (debug, log etc)
489
493
Serial.flush ();
490
494
RF24::powerDown ();
491
- continueTimer = true ;
495
+ pinIntTrigger = 0 ;
492
496
internalSleep (ms);
493
497
}
494
498
495
- bool MySensor::sleep (int interrupt, int mode, unsigned long ms) {
499
+ bool MySensor::sleep (uint8_t interrupt, uint8_t mode, unsigned long ms) {
496
500
// Let serial prints finish (debug, log etc)
497
501
bool pinTriggeredWakeup = true ;
498
502
Serial.flush ();
499
503
RF24::powerDown ();
500
- attachInterrupt (interrupt, wakeUp, mode); // Interrupt on pin 3 for any change in solar power
504
+ attachInterrupt (interrupt, wakeUp, mode);
501
505
if (ms>0 ) {
502
- continueTimer = true ;
506
+ pinIntTrigger = 0 ;
503
507
sleep (ms);
504
- pinTriggeredWakeup = !continueTimer;
508
+ if (0 == pinIntTrigger) {
509
+ pinTriggeredWakeup = false ;
510
+ }
505
511
} else {
506
512
Serial.flush ();
507
513
LowPower.powerDown (SLEEP_FOREVER, ADC_OFF, BOD_OFF);
@@ -510,7 +516,32 @@ bool MySensor::sleep(int interrupt, int mode, unsigned long ms) {
510
516
return pinTriggeredWakeup;
511
517
}
512
518
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);
513
537
538
+ if (1 == pinIntTrigger) {
539
+ retVal = (int8_t )interrupt1;
540
+ } else if (2 == pinIntTrigger) {
541
+ retVal = (int8_t )interrupt2;
542
+ }
543
+ return retVal;
544
+ }
514
545
515
546
#ifdef DEBUG
516
547
void MySensor::debugPrint (const char *fmt, ... ) {
0 commit comments