]> www.fi.muni.cz Git - bike-lights.git/blobdiff - firmware/pattern.c
pwm.c: channels running - visible from the outside
[bike-lights.git] / firmware / pattern.c
index d5720b0a304bee8cd7f5c9f9bc654a6a9b9834b9..55b64cc6e5bf23729d75c5a676c69708619999ff 100644 (file)
@@ -47,7 +47,7 @@ static pattern_t pattern_num[] = {
        { 1, 0x1 }, /*  2 */
        { 0, 0x5 },
        { 1, 0x1 }, /*  1 */
-       { 0, 0x1E },
+       { 0, 0xF },
        PATTERN_END
 };
 
@@ -72,12 +72,12 @@ static pattern_t pattern_invnum[] = {
        { 0, 0x1 }, /*  2 */
        { 1, 0x5 },
        { 0, 0x1 }, /*  1 */
-       { 1, 0x1E },
+       { 1, 0xF },
        PATTERN_END
 };
 
 pattern_t off_pattern[] = {
-       { 0, 0x1E },
+       { 0, 0x1 },
        PATTERN_END
 };
 
@@ -113,8 +113,8 @@ void init_pattern()
 
 pattern_t *number_pattern(unsigned char num, unsigned char inv)
 {
-       if (num >= 9)
-               num = 9;
+       if (num >= 10)
+               num = 10;
 
        if (inv) {
                return pattern_invnum
@@ -135,6 +135,7 @@ static pattern_t *pattern_select(unsigned char n)
        case 2: return pwmled2_pattern_select();
        case 3: return status_led_pattern_select();
        case 4: return illumination_led_pattern_select();
+       case 6: return laser_pattern_select();
        default: return NULL;
        }
 }
@@ -147,25 +148,52 @@ void pattern_reload()
                led_set_pattern(i, pattern_select(i));
 }
 
+static void inline pattern_finished(unsigned char n)
+{
+       unsigned char i;
+
+       led_patterns[n] = NULL;
+
+       if (n < N_PWMLEDS) {
+               for (i = 0; i < N_PWMLEDS; i++)
+                       if (led_patterns[i])
+                               return;
+
+               /* all pwmleds finished; restart them */
+               for (i = 0; i < N_PWMLEDS; i++)
+                       led_set_pattern(i, pattern_select(i));
+       } else if (n == 3) {
+               if (!led_patterns[4])
+                       led_set_pattern(4, pattern_select(4));
+       } else if (n == 4) {
+               if (!led_patterns[3])
+                       led_set_pattern(3, pattern_select(3));
+       } else {
+               led_set_pattern(n, pattern_select(n));
+       }
+}
+
 void patterns_next_tick()
 {
        unsigned char i;
 
        for (i = 0; i < N_LEDS; i++) {
-               if (!led_patterns[i])
+               if (!led_patterns[i]) {
+                       pattern_finished(i);
                        continue;
+               }
 
-               if (led_counters[i] == 0) {
+               if (--led_counters[i] == 0) {
                        pattern_t *p = led_patterns[i];
                        p++;
                        if (p->duration == 0) { // END
-                               p = pattern_select(i);
+                               /* Keep the last state, wait for others */
+                               pattern_finished(i);
+                               continue;
                        }
                        led_set_pattern(i, p);
                }
 
-               if (led_counters[i] < PATTERN_FOREVER)
-                       led_counters[i]--;
        }
 }