summaryrefslogtreecommitdiffstats
path: root/app/led.c
diff options
context:
space:
mode:
authorroot <root@new-selene.erebei.org>2015-12-01 02:10:53 +0000
committerroot <root@new-selene.erebei.org>2015-12-01 02:10:53 +0000
commitb55240eb43a92c552003b8b324a385e041f84f12 (patch)
treeab932136ecfaa42e1e417e0253aebcc5b5f178aa /app/led.c
parent061430973e82995368d27ff9081391f9475da3c7 (diff)
downloadcandlestick-b55240eb43a92c552003b8b324a385e041f84f12.tar.gz
candlestick-b55240eb43a92c552003b8b324a385e041f84f12.tar.bz2
candlestick-b55240eb43a92c552003b8b324a385e041f84f12.zip
fish
Diffstat (limited to 'app/led.c')
-rw-r--r--app/led.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/app/led.c b/app/led.c
index ddbbc34..dfa343e 100644
--- a/app/led.c
+++ b/app/led.c
@@ -1,7 +1,10 @@
#include "project.h"
+#define LED_PERIOD 1000
+
+static int led_on = 0;
+static int led_cycle = 0;
-static int led = 0;
void
led_init (void)
@@ -17,34 +20,37 @@ void
led_blink (void)
{
gpio_set (GPIOA, GPIO9);
- led = 50;
+ led_on = 50;
}
void
led_tick (void)
{
-#if 0
- if (led)
+ if (led_on)
{
- led--;
- if (!led)
+ led_on--;
+ if (!led_on)
gpio_clear (GPIOA, GPIO9);
}
-#else
- static int c;
- c++;
- if (c > 1000)
+ led_cycle++;
+
+ if (led_cycle == LED_PERIOD)
{
- led ^= 1;
- if (led)
- gpio_set (GPIOA, GPIO9);
- else
- gpio_clear (GPIOA, GPIO9);
+ led_cycle = 0;
+
- c = 0;
+ if (have_key && locked)
+ led_on = 50;
+ if (have_key && !locked)
+ led_on = 500;
+ if (!have_key)
+ led_on = 1000;
+
+ gpio_set (GPIOA, GPIO9);
+
}
-#endif
+
}