2 #include <stdlib.h> // for NULL
6 static unsigned char led_counters[N_LEDS];
7 static pattern_t *led_patterns[N_LEDS];
9 static pattern_t boot_pattern[] = {
29 static pattern_t pattern_num[] = {
54 static pattern_t pattern_invnum[] = {
79 pattern_t off_pattern[] = {
84 static void led_set_mode(unsigned char n, unsigned char mode)
87 pwmled_set_mode(n, mode);
88 } else if (n < N_LEDS) {
89 gpio_set(n - N_PWMLEDS, mode);
93 void led_set_pattern(unsigned char n, pattern_t *pattern)
96 pattern = off_pattern;
98 led_patterns[n] = pattern;
100 led_counters[n] = pattern->duration;
101 led_set_mode(n, pattern->mode);
108 for (i = 0; i < N_LEDS; i++)
109 led_set_pattern(i, NULL);
111 led_set_pattern(N_PWMLEDS+1, boot_pattern);
114 pattern_t *number_pattern(unsigned char num, unsigned char inv)
120 return pattern_invnum
121 + sizeof(pattern_invnum)/sizeof(pattern_t)
125 + sizeof(pattern_num)/sizeof(pattern_t)
130 static pattern_t *pattern_select(unsigned char n)
133 case 0: return pwmled0_pattern_select();
134 case 1: return pwmled1_pattern_select();
135 case 2: return pwmled2_pattern_select();
136 case 3: return status_led_pattern_select();
137 case 4: return illumination_led_pattern_select();
138 case 6: return laser_pattern_select();
139 default: return NULL;
143 void pattern_reload()
147 for (i = 0; i < N_LEDS; i++)
148 led_set_pattern(i, pattern_select(i));
151 static void inline pattern_finished(unsigned char n)
155 led_patterns[n] = NULL;
158 for (i = 0; i < N_PWMLEDS; i++)
162 /* all pwmleds finished; restart them */
163 for (i = 0; i < N_PWMLEDS; i++)
164 led_set_pattern(i, pattern_select(i));
166 if (!led_patterns[4])
167 led_set_pattern(4, pattern_select(4));
169 if (!led_patterns[3])
170 led_set_pattern(3, pattern_select(3));
172 led_set_pattern(n, pattern_select(n));
176 void patterns_next_tick()
180 for (i = 0; i < N_LEDS; i++) {
181 if (!led_patterns[i]) {
186 if (--led_counters[i] == 0) {
187 pattern_t *p = led_patterns[i];
189 if (p->duration == 0) { // END
190 /* Keep the last state, wait for others */
194 led_set_pattern(i, p);