summaryrefslogtreecommitdiffstats
path: root/app/led.c
diff options
context:
space:
mode:
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
+
}