]> www.fi.muni.cz Git - bike-lights.git/commitdiff
main.c: allow only long keypress to wake us
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 3 Oct 2012 19:33:46 +0000 (21:33 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 3 Oct 2012 19:40:29 +0000 (21:40 +0200)
firmware/main.c

index 5db08b17d7335ed07b370b775de44416819978e8..d10a322bd34c721aca16d3bfbc63e12c2e4bb570 100644 (file)
@@ -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();
 }