Loading projects/step-up/Makefile +1 −1 Original line number Diff line number Diff line PROGRAM=lights SRC=main.c logging.c pwm.c adc.c pwmled.c SRC=main.c logging.c pwm.c adc.c pwmled.c pattern.c OBJ=$(SRC:.c=.o) Loading projects/step-up/adc.c +12 −0 Original line number Diff line number Diff line Loading @@ -140,9 +140,21 @@ static void adc1_gain20_adc(uint16_t adcsum) } #endif static void inline adc_based_timer() { static uint16_t pattern_counter; if (++pattern_counter > 250) { pattern_counter = 0; patterns_next_tick(); } } ISR(ADC_vect) { // IRQ handler uint16_t adcval = ADCW; adc_based_timer(); if (read_zero) { setup_mux(current_adc); read_zero = 0; Loading projects/step-up/pattern.c +32 −40 Original line number Diff line number Diff line Loading @@ -3,29 +3,10 @@ #include "lights.h" #define N_LEDS 1 static unsigned char led_counters[N_LEDS]; static pattern_t *led_patterns[N_LEDS]; static pattern_t boot_pattern[] = { { 1, 0x6 }, { 0, 0x6 }, { 1, 0x3 }, { 0, 0x3 }, { 1, 0x2 }, { 0, 0x2 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x10 }, { 0, 0x10 }, PATTERN_END }; static pattern_t pattern_num[] = { { 0, 0x5 }, { 1, 0x1 }, /* 10 */ Loading Loading @@ -81,12 +62,20 @@ pattern_t off_pattern[] = { PATTERN_END }; pattern_t on1_pattern[] = { { 1, 1 }, { 0, 2 }, { 1, 1 }, { 0, 8 }, { 1, 1 }, { 0, 8 }, PATTERN_END }; 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); if (n == 0) { pwmled_on_off(mode); } } Loading @@ -107,8 +96,6 @@ void init_pattern() for (i = 0; i < N_LEDS; i++) led_set_pattern(i, NULL); led_set_pattern(N_PWMLEDS+1, boot_pattern); } pattern_t *number_pattern(unsigned char num, unsigned char inv) Loading @@ -129,13 +116,21 @@ pattern_t *number_pattern(unsigned char num, unsigned char inv) static pattern_t *pattern_select(unsigned char n) { static unsigned char count; static unsigned char mode; switch(n) { case 0: return pwmled0_pattern_select(); case 1: return pwmled1_pattern_select(); 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(); case 0: if (++count > 2) { count = 0; if (mode == 0) { mode = 3; } else { mode = 0; } pwmled_set_target(mode); } return number_pattern(mode ? 2 : 3, 0); default: return NULL; } } Loading @@ -154,14 +149,10 @@ static void inline pattern_finished(unsigned char n) 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)); if (n == 0) { led_set_pattern(0, pattern_select(0)); } #if 0 } else if (n == 3) { if (!led_patterns[4]) led_set_pattern(4, pattern_select(4)); Loading @@ -171,6 +162,7 @@ static void inline pattern_finished(unsigned char n) } else { led_set_pattern(n, pattern_select(n)); } #endif } void patterns_next_tick() Loading Loading
projects/step-up/Makefile +1 −1 Original line number Diff line number Diff line PROGRAM=lights SRC=main.c logging.c pwm.c adc.c pwmled.c SRC=main.c logging.c pwm.c adc.c pwmled.c pattern.c OBJ=$(SRC:.c=.o) Loading
projects/step-up/adc.c +12 −0 Original line number Diff line number Diff line Loading @@ -140,9 +140,21 @@ static void adc1_gain20_adc(uint16_t adcsum) } #endif static void inline adc_based_timer() { static uint16_t pattern_counter; if (++pattern_counter > 250) { pattern_counter = 0; patterns_next_tick(); } } ISR(ADC_vect) { // IRQ handler uint16_t adcval = ADCW; adc_based_timer(); if (read_zero) { setup_mux(current_adc); read_zero = 0; Loading
projects/step-up/pattern.c +32 −40 Original line number Diff line number Diff line Loading @@ -3,29 +3,10 @@ #include "lights.h" #define N_LEDS 1 static unsigned char led_counters[N_LEDS]; static pattern_t *led_patterns[N_LEDS]; static pattern_t boot_pattern[] = { { 1, 0x6 }, { 0, 0x6 }, { 1, 0x3 }, { 0, 0x3 }, { 1, 0x2 }, { 0, 0x2 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x1 }, { 0, 0x1 }, { 1, 0x10 }, { 0, 0x10 }, PATTERN_END }; static pattern_t pattern_num[] = { { 0, 0x5 }, { 1, 0x1 }, /* 10 */ Loading Loading @@ -81,12 +62,20 @@ pattern_t off_pattern[] = { PATTERN_END }; pattern_t on1_pattern[] = { { 1, 1 }, { 0, 2 }, { 1, 1 }, { 0, 8 }, { 1, 1 }, { 0, 8 }, PATTERN_END }; 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); if (n == 0) { pwmled_on_off(mode); } } Loading @@ -107,8 +96,6 @@ void init_pattern() for (i = 0; i < N_LEDS; i++) led_set_pattern(i, NULL); led_set_pattern(N_PWMLEDS+1, boot_pattern); } pattern_t *number_pattern(unsigned char num, unsigned char inv) Loading @@ -129,13 +116,21 @@ pattern_t *number_pattern(unsigned char num, unsigned char inv) static pattern_t *pattern_select(unsigned char n) { static unsigned char count; static unsigned char mode; switch(n) { case 0: return pwmled0_pattern_select(); case 1: return pwmled1_pattern_select(); 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(); case 0: if (++count > 2) { count = 0; if (mode == 0) { mode = 3; } else { mode = 0; } pwmled_set_target(mode); } return number_pattern(mode ? 2 : 3, 0); default: return NULL; } } Loading @@ -154,14 +149,10 @@ static void inline pattern_finished(unsigned char n) 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)); if (n == 0) { led_set_pattern(0, pattern_select(0)); } #if 0 } else if (n == 3) { if (!led_patterns[4]) led_set_pattern(4, pattern_select(4)); Loading @@ -171,6 +162,7 @@ static void inline pattern_finished(unsigned char n) } else { led_set_pattern(n, pattern_select(n)); } #endif } void patterns_next_tick() Loading