#include "lights.h"
static pattern_t panic_pattern[] = {
- { 3, 1 }, // FIXME: will be 4, but let's be safe while testing
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
- { 3, 1 },
- { 0, 1 },
+ { 3, D_1 }, // FIXME: will be 4, but let's be safe while testing
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_1 },
PATTERN_END
};
pattern_t on1_pattern [] = {
- { 1, 0x7 },
+ { 1, D_8 },
PATTERN_END
};
static pattern_t on2_pattern [] = {
- { 2, 0x7 },
+ { 2, D_8 },
PATTERN_END
};
static pattern_t on3_pattern [] = {
- { 3, 0x7 },
+ { 3, D_8 },
PATTERN_END
};
static pattern_t brake_pattern [] = {
- { 4, 0x2 },
- { 3, 0x7 },
+ { 4, D_2 },
+ { 3, D_8 },
PATTERN_END
};
static pattern_t normal2_pattern[] = {
- { 2, 0x1 },
- { 0, 0x1 },
- { 2, 0x1 },
- { 0, 0x7 },
- { 1, 0x1 },
- { 0, 0x1 },
- { 1, 0x1 },
- { 0, 0x7 },
+ { 2, D_1 },
+ { 0, D_1 },
+ { 2, D_1 },
+ { 0, D_8 },
+ { 1, D_1 },
+ { 0, D_1 },
+ { 1, D_1 },
+ { 0, D_8 },
PATTERN_END
};
static pattern_t normal3_pattern[] = {
- { 3, 0x1 },
- { 0, 0x1 },
- { 3, 0x1 },
- { 0, 0x7 },
- { 1, 0x1 },
- { 0, 0x1 },
- { 1, 0x1 },
- { 0, 0x7 },
+ { 3, D_1 },
+ { 0, D_1 },
+ { 3, D_1 },
+ { 0, D_8 },
+ { 1, D_1 },
+ { 0, D_1 },
+ { 1, D_1 },
+ { 0, D_8 },
PATTERN_END
};
static pattern_t normal4_pattern[] = {
- { 4, 0x1 },
- { 0, 0x1 },
- { 4, 0x1 },
- { 0, 0x7 },
- { 1, 0x1 },
- { 0, 0x1 },
- { 1, 0x1 },
- { 0, 0x7 },
+ { 4, D_1 },
+ { 0, D_1 },
+ { 4, D_1 },
+ { 0, D_8 },
+ { 1, D_1 },
+ { 0, D_1 },
+ { 1, D_1 },
+ { 0, D_8 },
PATTERN_END
};
static pattern_t slow1_pattern[] = {
- { 1, 0x01 },
- { 0, 0x7 },
- { 0, 0x7 },
+ { 1, D_1 },
+ { 0, D_13 },
PATTERN_END
};
static pattern_t slow2_pattern[] = {
- { 2, 0x01 },
- { 0, 0x7 },
- { 0, 0x7 },
+ { 2, D_1 },
+ { 0, D_13 },
PATTERN_END
};
static pattern_t slow3_pattern[] = {
- { 3, 0x01 },
- { 0, 0x7 },
- { 0, 0x7 },
+ { 3, D_1 },
+ { 0, D_13 },
PATTERN_END
};
/* pattern.c */
typedef struct {
unsigned char mode: 5;
- unsigned char duration: 3;
+ unsigned char duration_fib: 3;
} pattern_t;
#define PATTERN_END { 0, 0 }
+#define D_1 1
+#define D_2 2
+#define D_3 3
+#define D_5 4
+#define D_8 5
+#define D_13 6
+#define D_21 7
+
void init_pattern();
void patterns_next_tick();
void led_set_pattern(unsigned char led, pattern_t *pattern);
static unsigned char led_counters[N_LEDS];
static pattern_t *led_patterns[N_LEDS];
+static unsigned char fibonacci[8] = {
+ 0, 1, 2, 3, 5, 8, 13, 21,
+};
+
static pattern_t boot_pattern[] = {
- { 1, 0x6 },
- { 0, 0x6 },
- { 1, 0x3 },
- { 0, 0x3 },
- { 1, 0x2 },
- { 0, 0x2 },
- { 1, 0x1 },
- { 0, 0x1 },
- { 1, 0x1 },
- { 0, 0x1 },
- { 1, 0x1 },
- { 0, 0x1 },
- { 1, 0x1 },
- { 0, 0x1 },
- { 1, 0x7 },
- { 0, 0x7 },
+ { 1, D_5 },
+ { 0, D_5 },
+ { 1, D_3 },
+ { 0, D_3 },
+ { 1, D_2 },
+ { 0, D_2 },
+ { 1, D_1 },
+ { 0, D_1 },
+ { 1, D_1 },
+ { 0, D_1 },
+ { 1, D_1 },
+ { 0, D_1 },
+ { 1, D_1 },
+ { 0, D_1 },
+ { 1, D_8 },
+ { 0, D_8 },
PATTERN_END
};
static pattern_t pattern_num[] = {
- { 0, 0x5 },
- { 1, 0x1 }, /* 10 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 9 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 8 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 7 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 6 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 5 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 4 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 3 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 2 */
- { 0, 0x5 },
- { 1, 0x1 }, /* 1 */
- { 0, 0x7 },
- { 0, 0x7 },
+ { 0, D_5 },
+ { 1, D_1 }, /* 10 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 9 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 8 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 7 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 6 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 5 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 4 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 3 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 2 */
+ { 0, D_5 },
+ { 1, D_1 }, /* 1 */
+ { 0, D_13 },
PATTERN_END
};
static pattern_t pattern_invnum[] = {
- { 1, 0x5 },
- { 0, 0x1 }, /* 10 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 9 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 8 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 7 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 6 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 5 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 4 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 3 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 2 */
- { 1, 0x5 },
- { 0, 0x1 }, /* 1 */
- { 1, 0x7 },
- { 1, 0x7 },
+ { 1, D_5 },
+ { 0, D_1 }, /* 10 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 9 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 8 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 7 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 6 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 5 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 4 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 3 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 2 */
+ { 1, D_5 },
+ { 0, D_1 }, /* 1 */
+ { 1, D_13 },
PATTERN_END
};
pattern_t off_pattern[] = {
- { 0, 0x1 },
+ { 0, D_1 },
PATTERN_END
};
led_patterns[n] = pattern;
- led_counters[n] = pattern->duration;
+ led_counters[n] = fibonacci[pattern->duration_fib];
+
led_set_mode(n, pattern->mode);
}
if (--led_counters[i] == 0) {
pattern_t *p = led_patterns[i];
p++;
- if (p->duration == 0) { // END
+ if (p->duration_fib == 0) { // END
/* Keep the last state, wait for others */
pattern_finished(i);
continue;