From: Jan "Yenya" Kasprzak Date: Wed, 3 Oct 2012 19:33:46 +0000 (+0200) Subject: main.c: allow only long keypress to wake us X-Git-Tag: gerber-fab-20121029-1711~26 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=bike-lights.git;a=commitdiff_plain;h=a444b197e7f5d489227ea6952b78201f26aa82a0 main.c: allow only long keypress to wake us --- diff --git a/firmware/main.c b/firmware/main.c index 5db08b1..d10a322 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -35,6 +35,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 +59,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(); }