Statistics
| Branch: | Revision:

root / toolbox / led.c @ 94548bf4

History | View | Annotate | Download (860 Bytes)

1
#include "led.h"
2
#include "time.h"
3

    
4
char blink_count;
5
enum color_t blink_color;
6
uint16_t blink_period, blink_ticks;
7

    
8
static void led_color(enum color_t color) {
9
  switch (color) {
10
    case OFF:
11
      led_off();
12
      break;
13
    case RED:
14
      led_red();
15
      break;
16
    case YELLOW:
17
      led_yellow();
18
      break;
19
    case GREEN:
20
      led_green();
21
      break;
22
  }
23
}
24

    
25
void led_tick() {
26
  if (blink_count) {
27
    if (++blink_ticks >= blink_period) {
28
      blink_ticks = 0;
29
      if (--blink_count % 2) {
30
        led_color(blink_color);
31
      } else {
32
        led_off();
33
      }
34
    }
35
  }
36
}
37

    
38
void led_blink_start(unsigned int period_ms, char n_times, enum color_t color) {
39
  blink_count = n_times*2-1;
40
  blink_period = period_ms/2/TICK_MS;
41
  blink_ticks = 0;
42
  blink_color = color;
43
  led_color(color);
44
}
45

    
46
char led_blink_done() {
47
  return blink_count == 0;
48
}