2 #include <stdlib.h> // for NULL
7 static unsigned char led_counters[N_LEDS];
8 static pattern_t *led_patterns[N_LEDS];
10 static pattern_t pattern_num[] = {
35 static pattern_t pattern_invnum[] = {
60 pattern_t off_pattern[] = {
65 pattern_t on1_pattern[] = {
75 static void led_set_mode(unsigned char n, unsigned char mode)
78 case 0: pwmled_on_off(mode); break;
79 case 1: status_led_on_off(mode); break;
83 void led_set_pattern(unsigned char n, pattern_t *pattern)
86 pattern = off_pattern;
88 led_patterns[n] = pattern;
90 led_counters[n] = pattern->duration;
91 led_set_mode(n, pattern->mode);
98 for (i = 0; i < N_LEDS; i++)
99 led_set_pattern(i, NULL);
102 pattern_t *number_pattern(unsigned char num, unsigned char inv)
108 return pattern_invnum
109 + sizeof(pattern_invnum)/sizeof(pattern_t)
113 + sizeof(pattern_num)/sizeof(pattern_t)
118 static pattern_t *pattern_select(unsigned char n)
121 case 0: return pwmled_pattern_select();
122 case 1: return status_led_pattern_select();
123 default: return NULL;
127 void pattern_reload()
131 for (i = 0; i < N_LEDS; i++)
132 led_set_pattern(i, pattern_select(i));
135 static void inline pattern_finished(unsigned char n)
139 led_patterns[n] = NULL;
140 led_set_pattern(n, pattern_select(n));
143 void patterns_next_tick()
147 for (i = 0; i < N_LEDS; i++) {
148 if (!led_patterns[i]) {
153 if (--led_counters[i] == 0) {
154 pattern_t *p = led_patterns[i];
156 if (p->duration == 0) { // END
157 /* Keep the last state, wait for others */
161 led_set_pattern(i, p);