コード例 #1
0
ファイル: main.c プロジェクト: tazjel/elovalo
static void pick_startup_mode(void)
{
	cube_start(0);

	// Quick fix to start in kiosk mode
	mode = MODE_PLAYLIST;
	select_playlist_item(playlists[0]);
	init_current_effect();
}
コード例 #2
0
ファイル: main.c プロジェクト: tazjel/elovalo
uint8_t change_playlist(uint8_t i) {
	if (i >= playlists_len) { return 1; }

	// Change mode and run init
	mode = MODE_PLAYLIST;
	select_playlist_item(playlists[i]);
	init_current_effect();

	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: tazjel/elovalo
static void pick_startup_mode(void)
{
	// Start normally
	cube_start(0);

	mode = simulation_mode;
	switch (mode) {
	case MODE_EFFECT:
		effect = effects + simulation_effect;
		init_current_effect();
		break;
	case MODE_PLAYLIST:
		select_playlist_item(playlists[0]);
		init_current_effect();
		break;
	default:
		mode = MODE_IDLE;
	}
}
コード例 #4
0
ファイル: main.c プロジェクト: tazjel/elovalo
uint8_t change_current_effect(uint8_t i) {
	if (i >= effects_len) { return 1; }

	// Change mode and pick correct effect from the array.
	mode = MODE_EFFECT;
	effect = effects + i;

	// Prepare running of the new effect
	init_current_effect();

	return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: elovalo/elovalo
uint8_t change_playlist(uint8_t i) {
    if (i >= playlists_len) {
        return 1;
    }

    active_playlist = i;

    // Change mode and run init
    mode = MODE_PLAYLIST;
    select_playlist_item(pgm_get(playlists[i],byte));
    init_current_effect();

    return 0;
}
コード例 #6
0
ファイル: main.c プロジェクト: elovalo/elovalo
void use_stored_playlist(void)
{
    if (mode != MODE_PLAYLIST) return;
    if (!(modified.playlist || modified.mode)) return;

    uint8_t new_playlist = read_playlist();
    // Avoid dangling pointers and extra initialization
    if (new_playlist >= playlists_len) new_playlist = 0;

    // Activate
    active_playlist = new_playlist;
    select_playlist_item(pgm_get(playlists[new_playlist],byte));
    init_current_effect();
}
コード例 #7
0
ファイル: main.c プロジェクト: elovalo/elovalo
uint8_t change_current_effect(uint8_t i) {
    if (i >= effects_len) {
        return 1;
    }

    // Change mode and pick correct effect from the array.
    mode = MODE_EFFECT;
    effect = effects + i;
    custom_data = NULL; // Used in playlists only

    // Prepare running of the new effect
    init_current_effect();

    return 0;
}
コード例 #8
0
ファイル: main.c プロジェクト: elovalo/elovalo
void use_stored_effect(void)
{
    if (mode != MODE_EFFECT) return;
    if (!(modified.effect || modified.mode ||
            (modified.text && pgm_get(effect->dynamic_text, byte))))
    {
        return;
    }

    uint8_t new_effect = read_effect();
    // Avoid dangling pointers and extra initialization
    if (new_effect >= effects_len) new_effect = 0;

    effect = effects + new_effect;
    custom_data = NULL; // Used in playlists only
    init_current_effect();
}
コード例 #9
0
ファイル: main.c プロジェクト: elovalo/elovalo
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_boot_report();

    // Select correct startup mode
    pick_startup_mode();

    while(1) {
        /* Serial processing is implementation specific and defined in
         * serial_common.c */
        process_serial();

        switch (mode) {
        case MODE_SLEEP:
        // Fall through to MODE_IDLE
        case MODE_IDLE:
            // No operation
            sleep_if_no_traffic();
            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, wait interrupts
            if (flags.may_flip) {
                sleep_if_no_traffic();
                break;
            }

            // Update clock
            ticks = centisecs();

            /* Go back to serial handler if drawing time
             * is reached. By doing this we avoid serial
             * port slowdown when FPS is low */
            if (ticks < next_draw_at ) {
                sleep_if_no_traffic();
                break;
            }

            /* Restart effect if maximum ticks is
             * reached. This may result a glitch but is
             * better than the effect to stop. */
            if (ticks == ~0) {
                init_current_effect();
                ticks = 0;
            }

            // Update sensor values
            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);
            }

            // Update time when next drawing is allowed
            next_draw_at = ticks + pgm_get(effect->minimum_ticks,byte);

            break;
        }
    }

    return 0;
}
コード例 #10
0
ファイル: main.c プロジェクト: tazjel/elovalo
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;
}