summaryrefslogtreecommitdiff
path: root/src/common/button.c
diff options
context:
space:
mode:
authorNicolas Schodet2012-06-23 09:39:17 +0200
committerNicolas Schodet2012-06-23 09:39:17 +0200
commitfad163117fe1d7a1e3b905c4d54be1b884be8299 (patch)
tree52e8478b7e2e1b1c4a16e15fcd98178e886a8ed0 /src/common/button.c
parentb8be7983e8ab14b3324c1da147cb3119046229e2 (diff)
src/common: go to sleep for very long button pressHEADmaster
Diffstat (limited to 'src/common/button.c')
-rw-r--r--src/common/button.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/common/button.c b/src/common/button.c
index a733772..6079514 100644
--- a/src/common/button.c
+++ b/src/common/button.c
@@ -31,6 +31,9 @@
/** Delay for the button to be considered debounced. */
#define BUTTON_DEBOUNCE_MS 100
+/** Maximum mesured press duration. */
+#define BUTTON_PRESS_MAX_MS 11000
+
void
button_init (void)
{
@@ -63,8 +66,15 @@ button_wait (void)
else
{
debounce_ms = 0;
- if (press_ms < 60000)
+ if (press_ms < BUTTON_PRESS_MAX_MS)
press_ms++;
+ /* If press is really long, go to sleep and wait for interrupt. */
+ if (press_ms == BUTTON_PRESS_MAX_MS)
+ {
+ GIFR = _BV (PCIF); /* Clear previous interrupt. */
+ if (!IO_GET (BUTTON_IO))
+ power_sleep ();
+ }
}
}
return press_ms;