#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <avr/power.h>
-#include <avr/wdt.h>
#include "lights.h"
static void hw_setup()
{
- wdt_enable(WDTO_1S);
-
init_battery();
init_pwm();
init_adc();
init_gpio();
init_ambient();
init_pattern();
+ init_control();
set_sleep_mode(SLEEP_MODE_IDLE);
}
susp_adc();
susp_tmr();
susp_gpio();
+ susp_ambient();
susp_buttons();
-
- wdt_disable();
}
void power_down()
sei();
#if 1
while (1) {
- wdt_reset();
- sleep_mode();
+ cli();
+ if (TIMER1_IS_ON()) {
+ set_sleep_mode(SLEEP_MODE_IDLE);
+ } else if (adc_is_on) {
+ set_sleep_mode(SLEEP_MODE_ADC);
+ } else {
+ set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+ }
+
+ sleep_enable();
+ // keep BOD active, no sleep_bod_disable();
+ sei();
+ sleep_cpu();
+ sleep_disable();
}
#endif