I've added the following little convenience function to one of my sketches. I think it might be useful enough to include in Felix's LowPower branch (adapted to his lib for all related functions) instead of keeping it in my local repo. I can create a pull request if it seems a reasonable addition. Comments are welcome in any case.
Calling is similar to the original function, but the first argument is an arbitrary time im ms to sleep.
static int16_t periods[10] = { 15, 30, 60, 120, 250, 500, 1000, 2000, 4000, 8000 };
void longPowerDown(int32_t period, adc_t adc, bod_t bod) {
for (byte i = 9; i >= 0 && period > 0; i--) {
while (period - periods[i] >= 0) {
period -= periods[i];
LowPower.powerDown(i, adc, bod);
}
}
}
EDIT: a quick permutation to use PROGMEM:
const PROGMEM int16_t wdtPeriods[10] = { 15, 30, 60, 120, 250, 500, 1000, 2000, 4000, 8000 };
void longPowerDown(int32_t period, adc_t adc, bod_t bod) {
for (byte i = 9; i >= 0 && period > 0; i--) {
int16_t wdtPeriod = pgm_read_word_near(wdtPeriods + i);
while (period - wdtPeriod >= 0) {
period -= wdtPeriod;
LowPower.powerDown(i, adc, bod);
}
}
}