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)
/* 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__ */
pwmled_init();
gpio_init();
ambient_init();
+ pattern_init();
log_set_state(3);
+#include <avr/io.h>
+
#include "lights.h"
typedef struct {
};
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
};
}
}
+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;
#include "lights.h"
volatile uint16_t jiffies;
+#define PATTERN_DIV 5 // clk/10
+static unsigned char pattern_div;
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();
}