summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2011-06-14 00:28:16 +0200
committerNicolas Schodet2011-09-26 19:40:54 +0200
commitba617778ee01eaf7d0ed64709a472f082839c923 (patch)
tree5b65baeb20476bc4b5b1aacc533efb44980812b0
parente428c4205e7727213b4a8a5115b7aadd07bd0b0b (diff)
src/common: stop led display when button is pressed
-rw-r--r--src/binwatch/Makefile2
-rw-r--r--src/binwatch/counter.c3
-rw-r--r--src/common/button.c7
-rw-r--r--src/common/button.h4
-rw-r--r--src/common/led.c4
5 files changed, 19 insertions, 1 deletions
diff --git a/src/binwatch/Makefile b/src/binwatch/Makefile
index cf20b6d..43bf9db 100644
--- a/src/binwatch/Makefile
+++ b/src/binwatch/Makefile
@@ -1,6 +1,6 @@
BASE = $b/digital/avr
AVR_PROGS = counter
-counter_SOURCES = counter.c led.c
+counter_SOURCES = counter.c led.c button.c
MODULES = utils
CONFIGFILE = avrconfig.h
# atmega8, atmega8535, atmega128...
diff --git a/src/binwatch/counter.c b/src/binwatch/counter.c
index fe1bd1f..71f9ba5 100644
--- a/src/binwatch/counter.c
+++ b/src/binwatch/counter.c
@@ -23,10 +23,13 @@
* }}} */
#include "common.h"
#include "common/led.h"
+#include "common/button.h"
int
main (void)
{
+ led_init ();
+ button_init ();
uint16_t i;
while (1)
{
diff --git a/src/common/button.c b/src/common/button.c
index 716941d..78e5b26 100644
--- a/src/common/button.c
+++ b/src/common/button.c
@@ -43,3 +43,10 @@ button_wait (void)
while (!IO_GET (BUTTON_IO))
;
}
+
+uint8_t
+button_pressed (void)
+{
+ return !IO_GET (BUTTON_IO);
+}
+
diff --git a/src/common/button.h b/src/common/button.h
index e76211a..d98adf7 100644
--- a/src/common/button.h
+++ b/src/common/button.h
@@ -32,4 +32,8 @@ button_init (void);
void
button_wait (void);
+/** Return true if button is currently pressed. */
+uint8_t
+button_pressed (void);
+
#endif /* button_h */
diff --git a/src/common/led.c b/src/common/led.c
index 194e20e..db674c4 100644
--- a/src/common/led.c
+++ b/src/common/led.c
@@ -26,6 +26,7 @@
#include "io.h"
#include "led.h"
+#include "button.h"
/** Time a led is lit. */
#define LED_UP_MS 0.05
@@ -85,6 +86,9 @@ led_display (uint16_t leds, uint16_t duration)
DDRB = ddrb;
PORTB = portb | LED_MASK;
utils_delay_ms (LED_DOWN_MS);
+ /* Stop now if button is pressed, it disturbs leds. */
+ if (button_pressed ())
+ return;
}
}
}