]> www.fi.muni.cz Git - bike-lights.git/blobdiff - pattern.c
firmware source moved into subdirectory
[bike-lights.git] / pattern.c
diff --git a/pattern.c b/pattern.c
deleted file mode 100644 (file)
index fb74ae0..0000000
--- a/pattern.c
+++ /dev/null
@@ -1,156 +0,0 @@
-#include <avr/io.h>
-
-#include "lights.h"
-
-typedef struct {
-       unsigned char mode: 3;
-       unsigned char duration: 5;
-} pattern_t;
-
-static unsigned char led_counters[N_LEDS];
-static pattern_t *led_patterns[N_LEDS];
-
-#define PATTERN_END { 0, 0 }
-pattern_t off_pattern[] = {
-       { 0, 0x1F },
-       PATTERN_END
-};
-
-pattern_t blink_pattern[] = {
-       { 1, 0x4 },
-       { 0, 0x8 },
-       PATTERN_END
-};
-
-pattern_t mode1_pattern[] = {
-       { 3, 0x1 },
-       { 0, 0x1 },
-       { 3, 0x1 },
-       { 0, 0x8 },
-       { 1, 0x1 },
-       { 0, 0x1 },
-       { 1, 0x1 },
-       { 0, 0x8 },
-       PATTERN_END
-};
-
-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, 0x10 },
-       { 0, 0x10 },
-       PATTERN_END
-};
-
-pattern_t pattern_num[] = {
-       { 1, 0x1 }, /* 10 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  9 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  8 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  7 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  6 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  5 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  4 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  3 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  2 */
-       { 0, 0x4 },
-       { 1, 0x1 }, /*  1 */
-       { 0, 0x1F },
-       PATTERN_END
-};
-
-static unsigned char test_running;
-
-static void led_set_mode(unsigned char n, unsigned char mode)
-{
-       if (n < N_PWMLEDS) {
-               pwmled_set_mode(n, mode);
-       } else if (n < N_LEDS) {
-               gpio_set(n - N_PWMLEDS, mode);
-       }
-}
-
-void led_set_pattern(unsigned char n, pattern_t *pattern)
-{
-       if (!pattern)
-               pattern = off_pattern;
-
-       led_patterns[n] = pattern;
-       led_counters[n] = pattern->duration;
-       led_set_mode(n, pattern->mode);
-}
-
-void pattern_init()
-{
-       unsigned char i;
-
-       for (i = 0; i < N_LEDS; i++) {
-               led_counters[i] = 0;
-               led_patterns[i] = off_pattern;
-       }
-       led_set_pattern(N_PWMLEDS+1, boot_pattern);
-       test_running = 0;
-}
-
-static pattern_t *number_pattern(unsigned char num)
-{
-       if (num >= 9)
-               num = 9;
-
-       return pattern_num + sizeof(pattern_num)/sizeof(pattern_t)
-               - 1 - 2*num;
-}
-
-static inline pattern_t *pattern_select(unsigned char n)
-{
-       if (n < N_PWMLEDS && !pwmled_enabled(n))
-               return off_pattern; // Don't mess with non-enabled LEDs
-
-       if (n == 2) {
-               return mode1_pattern;
-       }
-       // return number_pattern(1+ambient_zone);
-       return off_pattern;
-}
-
-void patterns_next_tick()
-{
-       unsigned char i;
-
-       for (i = 0; i < N_LEDS; i++) {
-               if (led_counters[i] == 0) {
-                       pattern_t *p = led_patterns[i];
-                       p++;
-                       if (p->duration == 0) { // END
-                               p = pattern_select(i);
-                       }
-                       led_set_pattern(i, p);
-               }
-
-               led_counters[i]--;
-       }
-}
-
-void led_set_status(unsigned char status)
-{
-       led_set_pattern(N_PWMLEDS+1, number_pattern(status));
-}