From: Jan "Yenya" Kasprzak Date: Tue, 28 Aug 2012 21:43:43 +0000 (+0200) Subject: patterns implemented X-Git-Tag: gedasymbols-20120913~48 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=dbbcaf6e61197990ec21a702102c81deb66f2110;p=bike-lights.git patterns implemented --- diff --git a/Makefile b/Makefile index e7b6355..d51e72d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ PROGRAM=lights -SRC=main.c logging.c adc.c pwm.c tmr.c pwmled.c gpio.c ambient.c +SRC=main.c logging.c adc.c pwm.c tmr.c pwmled.c gpio.c ambient.c pattern.c OBJ=$(SRC:.c=.o) diff --git a/lights.h b/lights.h index 74e887d..2559e57 100644 --- a/lights.h +++ b/lights.h @@ -49,8 +49,12 @@ void gpio_set(unsigned char n, unsigned char on); /* ambient.c */ void ambient_init(); -extern unsigned char ambient_zone; +extern volatile unsigned char ambient_zone; void ambient_adc(uint16_t adc_val); +/* pattern.c */ +void pattern_init(); +void patterns_next_tick(); + #endif /* !LIGHTS_H__ */ diff --git a/main.c b/main.c index 7b63ad8..0953063 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,7 @@ int main(void) pwmled_init(); gpio_init(); ambient_init(); + pattern_init(); log_set_state(3); diff --git a/pattern.c b/pattern.c index 386f9df..0245c3b 100644 --- a/pattern.c +++ b/pattern.c @@ -1,3 +1,5 @@ +#include + #include "lights.h" typedef struct { @@ -15,8 +17,30 @@ pattern_t off_pattern[] = { }; pattern_t blink_pattern[] = { - { 1, 5 }, - { 0, 5 }, + { 1, 0x4 }, + { 0, 0x8 }, + PATTERN_END +}; + +pattern_t pattern_num[] = { + { 1, 0x1 }, + { 0, 0x4 }, + { 1, 0x1 }, + { 0, 0x4 }, + { 1, 0x1 }, + { 0, 0x4 }, + { 1, 0x1 }, + { 0, 0x4 }, + { 1, 0x1 }, + { 0, 0x4 }, + { 1, 0x1 }, + { 0, 0x4 }, + { 1, 0x1 }, + { 0, 0x4 }, + { 1, 0x1 }, + { 0, 0x4 }, + { 1, 0x1 }, + { 0, 0x1F }, PATTERN_END }; @@ -30,6 +54,27 @@ void pattern_init() } } +static inline pattern_t *pattern_select(unsigned char n) +{ + log_byte(ambient_zone); + return pattern_num + sizeof(pattern_num)/sizeof(pattern_t) + - 1 - 2*(1+ambient_zone);; +} + +static void inline led_off(unsigned char n) +{ + if (n == N_PWMLEDS) { + gpio_set(GPIO_LED2, 0); + } +} + +static void inline led_set_level(unsigned char n, unsigned char level) +{ + if (n == N_PWMLEDS) { + gpio_set(GPIO_LED2, 1); + } +} + void patterns_next_tick() { unsigned char i; diff --git a/tmr.c b/tmr.c index b8fb502..2d52189 100644 --- a/tmr.c +++ b/tmr.c @@ -4,6 +4,8 @@ #include "lights.h" volatile uint16_t jiffies; +#define PATTERN_DIV 5 // clk/10 +static unsigned char pattern_div; void init_tmr() { @@ -13,13 +15,18 @@ void init_tmr() TIMSK |= _BV(OCIE0A); jiffies = 0; + pattern_div = PATTERN_DIV; } ISR(TIMER0_COMPA_vect) { ++jiffies; - // patterns_next_tick(); + if (--pattern_div == 0) { + patterns_next_tick(); + pattern_div = PATTERN_DIV; + } + timer_start_adcs(); }