Project

General

Profile

Revision 1085ef77

ID1085ef7751b530b21865d0ca7d23786578749364
Parent 1b054655
Child 215b2fa6

Added by Thomas Mullins over 11 years ago

Made rfid.c more robust against false negatives

Also changed LED code to be more generally usable, and changed mainbox
to grant access to a particular user id instead of randomly choosing

View differences:

toolbox/led.c
9 9
#define OCR (F_CPU / PRESCALE / 1000UL)
10 10
#define ERROR (F_CPU / PRESCALE - OCR * 1000UL)
11 11

  
12
char count;
13
uint16_t period;
12
char blink_count;
13
enum color_t blink_color;
14
uint16_t blink_period;
14 15

  
15 16
uint16_t ms;
16 17
uint16_t error;
17 18

  
19
static void led_color(enum color_t color) {
20
  switch (color) {
21
    case OFF:
22
      led_off();
23
      break;
24
    case RED:
25
      led_red();
26
      break;
27
    case YELLOW:
28
      led_yellow();
29
      break;
30
    case GREEN:
31
      led_green();
32
      break;
33
  }
34
}
35

  
18 36
static void blink() {
19
  count--;
20
  if (count % 2) {
21
    led_yellow();
37
  blink_count--;
38
  if (blink_count % 2) {
39
    led_color(blink_color);
22 40
  } else {
23 41
    led_off();
24 42
  }
......
30 48
    error -= 1000;
31 49
  } else {
32 50
    ms++;
33
    if (ms == period) {
51
    if (ms == blink_period) {
34 52
      blink();
35
      if (count == 0) {
53
      if (blink_count == 0) {
36 54
        TCCR0B = 0;
37 55
      }
38 56
      ms = 0;
......
40 58
  }
41 59
}
42 60

  
43
void led_blink_start(unsigned int period_ms, char n_times) {
44
  led_yellow();
61
void led_blink_start(unsigned int period_ms, char n_times, enum color_t color) {
62

  
45 63
  ms = 0;
46 64
  error = 0;
47
  count = n_times*2-1;
48
  period = period_ms/2;
65

  
66
  blink_count = n_times*2-1;
67
  blink_period = period_ms/2;
68
  blink_color = color;
69
  led_color(color);
70

  
49 71
  OCR0A = OCR;
50 72
  TIMSK = _BV(OCIE0A);
51 73
  TCCR0A = _BV(WGM01);
52 74
  TCCR0B = CLOCK_SEL;
75

  
53 76
}
54 77

  
55 78
char led_blink_done() {
56
  return count == 0;
79
  return blink_count == 0;
57 80
}

Also available in: Unified diff