From 243ecacbd6e12a329b29b19cc37200829ac17276 Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Thu, 30 Aug 2012 00:52:37 +0200 Subject: [PATCH] pattern selecting reworked --- pattern.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/pattern.c b/pattern.c index 23d747e..3638686 100644 --- a/pattern.c +++ b/pattern.c @@ -77,6 +77,25 @@ pattern_t pattern_num[] = { 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; @@ -85,9 +104,7 @@ void pattern_init() led_counters[i] = 0; led_patterns[i] = off_pattern; } - led_patterns[N_PWMLEDS+1] = boot_pattern; - led_counters[N_PWMLEDS+1] = boot_pattern->duration; - gpio_set(GPIO_LED2, 1); + led_set_pattern(N_PWMLEDS+1, boot_pattern); test_running = 0; } @@ -119,27 +136,18 @@ static inline pattern_t *pattern_select(unsigned char n) return number_pattern(1+ambient_zone); } -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 patterns_next_tick() { unsigned char i; for (i = 0; i < N_LEDS; i++) { if (led_counters[i] == 0) { - led_patterns[i]++; - if (led_patterns[i]->duration == 0) { // END - led_patterns[i] = pattern_select(i); + pattern_t *p = led_patterns[i]; + p++; + if (p->duration == 0) { // END + p = pattern_select(i); } - led_counters[i] = led_patterns[i]->duration; - led_set_mode(i, led_patterns[i]->mode); + led_set_pattern(i, p); } led_counters[i]--; -- 2.43.5