X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=blobdiff_plain;f=firmware%2Fmain.c;h=8166771478bd207e8cced92f6bf9f11eaef4a754;hp=ea3bb69d1384dd5840c5e6a90066dda0807a229c;hb=fad6d0df251d09246816d5f6480543b8af588641;hpb=e3bdcf1423fef9c2e77b410357ad150d60a85b44 diff --git a/firmware/main.c b/firmware/main.c index ea3bb69..8166771 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -10,6 +10,7 @@ static void hw_setup() { wdt_enable(WDTO_1S); + init_battery(); init_pwm(); init_adc(); @@ -30,59 +31,32 @@ static void hw_suspend() susp_adc(); susp_tmr(); susp_gpio(); + susp_buttons(); + wdt_disable(); } - void power_down() { - uint16_t wake_count = 0; - unsigned char btn; - hw_suspend(); -sleep_again: - // enable PCINT14, so that user can wake up later - GIMSK |= _BV(PCIE1); - PCMSK1 |= _BV(PCINT14); - - // G'night - set_sleep_mode(SLEEP_MODE_PWR_DOWN); - sleep_enable(); - sleep_bod_disable(); - sei(); - sleep_cpu(); - - // G'morning - cli(); - - sleep_disable(); - - // Disable PCINT14 - GIMSK &= ~_BV(PCIE1); - PCMSK1 &= ~_BV(PCINT14); - - // allow wakeup by long button-press only - for (btn = 0; btn < 5; btn++) { - if ((PINB & _BV(PB6)) != 0) { - wake_count++; - goto sleep_again;; - } - _delay_ms(100); - } - // ok, so I will wake up - log_byte(0xb1); - log_word(wake_count); - log_flush(); + do { + // G'night + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + sleep_enable(); + sleep_bod_disable(); + sei(); + sleep_cpu(); - hw_setup(); -} + // G'morning + cli(); + sleep_disable(); + // allow wakeup by long button-press only + } while (!buttons_wait_for_release()); -ISR(PCINT_vect) -{ - GIMSK &= ~_BV(PCIE1); - PCMSK1 &= ~_BV(PCINT14); + // ok, so I will wake up + hw_setup(); } int main(void)