X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pattern.c;h=23d747e707044b3c10a71a1a148c15325d99b774;hb=a75d0044dc9522e7543ebbe924b46e5ee4e603a2;hp=06911707d059b5a05def1268c280df4a7238665b;hpb=1d7ad9daee131c758cdf95b5608f602254f10427;p=bike-lights.git diff --git a/pattern.c b/pattern.c index 0691170..23d747e 100644 --- a/pattern.c +++ b/pattern.c @@ -85,12 +85,21 @@ void pattern_init() led_counters[i] = 0; led_patterns[i] = off_pattern; } - led_patterns[N_PWMLEDS] = boot_pattern; - led_counters[N_PWMLEDS] = boot_pattern->duration; + led_patterns[N_PWMLEDS+1] = boot_pattern; + led_counters[N_PWMLEDS+1] = boot_pattern->duration; gpio_set(GPIO_LED2, 1); 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)) @@ -107,24 +116,15 @@ static inline pattern_t *pattern_select(unsigned char n) return mode1_pattern; } } - return pattern_num + sizeof(pattern_num)/sizeof(pattern_t) - - 1 - 2*(1+ambient_zone); + 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_PWMLEDS) { - gpio_set(GPIO_LED2, mode); - } - // TODO LED 1 -} - -static void inline led_set_level(unsigned char n, unsigned char level) -{ - if (n == N_PWMLEDS) { - gpio_set(GPIO_LED2, 1); + } else if (n < N_LEDS) { + gpio_set(n - N_PWMLEDS, mode); } }