Minor refactoring of delay variables
This is a preparation for handling multiple interrupts in delay(). It also reduces the size of the interrupt-related variables and arguments to int8_t as that should be ample enough for any Arduino implementation.
This commit is contained in:
@@ -465,43 +465,45 @@ int MySensor::getInternalTemp(void)
|
|||||||
return result/10000;
|
return result/10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
int continueTimer = true;
|
int8_t pinIntTrigger = 0;
|
||||||
void wakeUp() //place to send the interrupts
|
void wakeUp() //place to send the interrupts
|
||||||
{
|
{
|
||||||
continueTimer = false;
|
pinIntTrigger = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MySensor::internalSleep(unsigned long ms) {
|
void MySensor::internalSleep(unsigned long ms) {
|
||||||
while (continueTimer && ms >= 8000) { LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000; }
|
while (!pinIntTrigger && ms >= 8000) { LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); ms -= 8000; }
|
||||||
if (continueTimer && ms >= 4000) { LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF); ms -= 4000; }
|
if (!pinIntTrigger && ms >= 4000) { LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF); ms -= 4000; }
|
||||||
if (continueTimer && ms >= 2000) { LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF); ms -= 2000; }
|
if (!pinIntTrigger && ms >= 2000) { LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF); ms -= 2000; }
|
||||||
if (continueTimer && ms >= 1000) { LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); ms -= 1000; }
|
if (!pinIntTrigger && ms >= 1000) { LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); ms -= 1000; }
|
||||||
if (continueTimer && ms >= 500) { LowPower.powerDown(SLEEP_500MS, ADC_OFF, BOD_OFF); ms -= 500; }
|
if (!pinIntTrigger && ms >= 500) { LowPower.powerDown(SLEEP_500MS, ADC_OFF, BOD_OFF); ms -= 500; }
|
||||||
if (continueTimer && ms >= 250) { LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF); ms -= 250; }
|
if (!pinIntTrigger && ms >= 250) { LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF); ms -= 250; }
|
||||||
if (continueTimer && ms >= 125) { LowPower.powerDown(SLEEP_120MS, ADC_OFF, BOD_OFF); ms -= 120; }
|
if (!pinIntTrigger && ms >= 125) { LowPower.powerDown(SLEEP_120MS, ADC_OFF, BOD_OFF); ms -= 120; }
|
||||||
if (continueTimer && ms >= 64) { LowPower.powerDown(SLEEP_60MS, ADC_OFF, BOD_OFF); ms -= 60; }
|
if (!pinIntTrigger && ms >= 64) { LowPower.powerDown(SLEEP_60MS, ADC_OFF, BOD_OFF); ms -= 60; }
|
||||||
if (continueTimer && ms >= 32) { LowPower.powerDown(SLEEP_30MS, ADC_OFF, BOD_OFF); ms -= 30; }
|
if (!pinIntTrigger && ms >= 32) { LowPower.powerDown(SLEEP_30MS, ADC_OFF, BOD_OFF); ms -= 30; }
|
||||||
if (continueTimer && ms >= 16) { LowPower.powerDown(SLEEP_15Ms, ADC_OFF, BOD_OFF); ms -= 15; }
|
if (!pinIntTrigger && ms >= 16) { LowPower.powerDown(SLEEP_15Ms, ADC_OFF, BOD_OFF); ms -= 15; }
|
||||||
}
|
}
|
||||||
|
|
||||||
void MySensor::sleep(unsigned long ms) {
|
void MySensor::sleep(unsigned long ms) {
|
||||||
// Let serial prints finish (debug, log etc)
|
// Let serial prints finish (debug, log etc)
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
RF24::powerDown();
|
RF24::powerDown();
|
||||||
continueTimer = true;
|
pinIntTrigger = 0;
|
||||||
internalSleep(ms);
|
internalSleep(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MySensor::sleep(int interrupt, int mode, unsigned long ms) {
|
bool MySensor::sleep(uint8_t interrupt, uint8_t mode, unsigned long ms) {
|
||||||
// Let serial prints finish (debug, log etc)
|
// Let serial prints finish (debug, log etc)
|
||||||
bool pinTriggeredWakeup = true;
|
bool pinTriggeredWakeup = true;
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
RF24::powerDown();
|
RF24::powerDown();
|
||||||
attachInterrupt(interrupt, wakeUp, mode); //Interrupt on pin 3 for any change in solar power
|
attachInterrupt(interrupt, wakeUp, mode);
|
||||||
if (ms>0) {
|
if (ms>0) {
|
||||||
continueTimer = true;
|
pinIntTrigger = 0;
|
||||||
sleep(ms);
|
sleep(ms);
|
||||||
pinTriggeredWakeup = !continueTimer;
|
if (0 == pinIntTrigger) {
|
||||||
|
pinTriggeredWakeup = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
|
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ class MySensor : public RF24
|
|||||||
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
* @param ms Number of milliseconds to sleep or 0 to sleep forever
|
||||||
* @return true if wake up was triggered by pin change and false means timer woke it up.
|
* @return true if wake up was triggered by pin change and false means timer woke it up.
|
||||||
*/
|
*/
|
||||||
bool sleep(int interrupt, int mode, unsigned long ms=0);
|
bool sleep(uint8_t interrupt, uint8_t mode, unsigned long ms=0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getInternalTemp
|
* getInternalTemp
|
||||||
|
|||||||
Reference in New Issue
Block a user