X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=firmware%2Fmain.c;h=25ea829511781e3e365c282a9bc0ae0e4357b8c3;hb=ed608010c0a708b9be0d3577d7f4d3313eb2e851;hp=5db08b17d7335ed07b370b775de44416819978e8;hpb=33c451a9ba18c59b405d735b2420bc7b549643a4;p=bike-lights.git diff --git a/firmware/main.c b/firmware/main.c index 5db08b1..25ea829 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -10,6 +10,7 @@ void hw_setup() { wdt_enable(WDTO_1S); + init_battery(); init_pwm(); init_adc(); init_tmr(); @@ -35,6 +36,10 @@ void hw_suspend() void power_down() { + uint16_t wake_count = 0; + unsigned char btn; + +sleep_again: // enable PCINT14, so that user can wake up later GIMSK |= _BV(PCIE1); PCMSK1 |= _BV(PCINT14); @@ -55,6 +60,20 @@ void power_down() 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(); + hw_setup(); }