5 static unsigned char led_counters[N_LEDS];
6 static pattern_t *led_patterns[N_LEDS];
8 pattern_t off_pattern[] = {
9 { 0, PATTERN_FOREVER },
12 pattern_t on_pattern[] = {
13 { 1, PATTERN_FOREVER },
16 pattern_t blink_pattern[] = {
22 pattern_t mode1_pattern[] = {
34 pattern_t boot_pattern[] = {
54 pattern_t pattern_num[] = {
79 static unsigned char test_running;
81 static void led_set_mode(unsigned char n, unsigned char mode)
84 pwmled_set_mode(n, mode);
85 } else if (n < N_LEDS) {
86 gpio_set(n - N_PWMLEDS, mode);
90 void led_set_pattern(unsigned char n, pattern_t *pattern)
93 pattern = off_pattern;
95 led_patterns[n] = pattern;
96 led_counters[n] = pattern->duration;
97 led_set_mode(n, pattern->mode);
104 for (i = 0; i < N_LEDS; i++)
105 led_set_pattern(i, off_pattern);
107 led_set_pattern(N_PWMLEDS+1, boot_pattern);
111 pattern_t *number_pattern(unsigned char num)
116 return pattern_num + sizeof(pattern_num)/sizeof(pattern_t)
120 static inline pattern_t *pattern_select(unsigned char n)
122 if (n < N_PWMLEDS && !pwmled_enabled(n))
123 return off_pattern; // Don't mess with non-enabled LEDs
125 return mode1_pattern;
127 return status_pattern_select(0);
129 return status_pattern_select(1);
133 void patterns_next_tick()
137 for (i = 0; i < N_LEDS; i++) {
138 if (led_counters[i] == 0) {
139 pattern_t *p = led_patterns[i];
141 if (p->duration == 0) { // END
142 p = pattern_select(i);
144 led_set_pattern(i, p);
147 if (led_counters[i] < PATTERN_FOREVER)
152 void led_set_status(unsigned char status)
154 led_set_pattern(N_PWMLEDS+1, number_pattern(status));