int main() { cli(); wdt_disable(); // To make sure nothing weird happens init_tlc5940(); init_spi(); init_ps(); init_blank_timer(); init_effect_timer(); init_playlist(); initUSART(); sei(); hcsr04_start_continuous_meas(); adc_start(); serial_elo_init(); // Select correct startup mode pick_startup_mode(); while(1) { if(serial_available()) { uint8_t cmd = serial_read(); #if defined AVR_ZCL serial_zcl_process(cmd); #elif defined AVR_ELO serial_elo_process(cmd); #elif defined SIMU // Do nothing #else #error Unsupported serial communication type #endif } switch (mode) { case MODE_SLEEP: // Fall through to MODE_IDLE case MODE_IDLE: // No operation sleep_mode(); break; case MODE_PLAYLIST: ticks = centisecs(); if (ticks > effect_length) { next_effect(); init_current_effect(); } // no need to break! // fall to MODE_EFFECT on purpose case MODE_EFFECT: // If a buffer is not yet flipped if (flags.may_flip) break; // Update clock and sensor values ticks = centisecs(); sensors.distance1 = hcsr04_get_distance_in_cm(); sensors.distance2 = hcsr04_get_distance_in_cm(); //TODO: use separate sensor sensors.ambient_light = adc_get(0) >> 2; sensors.sound_pressure_level = adc_get(1) >> 2; // Do the actual drawing draw_t draw = (draw_t)pgm_get(effect->draw,word); if (draw != NULL) { draw(); allow_flipping(true); } // Slow down drawing if FPS is going to be too high uint16_t target_ticks = ticks + pgm_get(effect->minimum_ticks,byte); while (centisecs() < target_ticks ) { sleep_mode(); } break; } } return 0; }
void process_serial(void) { if (!serial_available()) return; uint8_t cmd = serial_read(); serial_elo_process(cmd); }