/** * Load data allocate buffers, initialize structure of the starfield * @return TRUE if it completed successfully or FALSE otherwise */ bool starfield_once_init (void) { if (!starfield_load ()) { return FALSE; } /* allocate starfield data structure */ if (stars == NULL) { stars = (star_structure *) memory_allocation (NUMOF_STARS * sizeof (star_structure)); if (stars == NULL) { LOG_ERR ("'stars' out of memory"); return FALSE; } } starfield_init (); return TRUE; }
static int plugin_main(void) { int button, avg_peak, t_disp=0; int font_h, font_w; bool pulse __attribute__ ((unused)) = true; /* 'unused' resolves warnings */ rb->lcd_getstringsize("A", &font_w, &font_h); starfield_init(&starfield); starfield_add_stars(&starfield, INIT_STARS); #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); #endif #ifdef HAVE_LCD_COLOR rb->lcd_set_background(LCD_BLACK); rb->lcd_set_foreground(LCD_WHITE); #endif while (true) { rb->sleep(1); rb->lcd_clear_display(); #if ((CONFIG_CODEC == SWCODEC) || !defined(SIMULATOR) && \ ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))) /* This will make the stars pulse to the music */ if(pulse){ /* Get the peaks. ( Borrowed from vu_meter ) */ #if (CONFIG_CODEC == SWCODEC) int left_peak, right_peak; rb->mixer_channel_calculate_peaks(PCM_MIXER_CHAN_PLAYBACK, &left_peak, &right_peak); #else int left_peak = rb->mas_codec_readreg(0xC); int right_peak = rb->mas_codec_readreg(0xD); #endif /* Devide peak data by 4098 to bring the max value down from ~32k to 8 */ left_peak = left_peak/0x1000; right_peak = right_peak/0x1000; /* Make sure they dont stop */ if(left_peak<0x1) left_peak = 0x1; if(right_peak<0x1) right_peak = 0x1; /* And make sure they dont go over 8 */ if(left_peak>0x8) left_peak = 0x8; if(right_peak>0x8) right_peak = 0x8; /* We need the average of both chanels */ avg_peak = ( left_peak + right_peak )/2; /* Set the speed to the peak meter */ starfield.z_move = avg_peak; } /* if pulse */ #else (void) avg_peak; #endif starfield_move_and_draw(&starfield); #ifdef HAVE_LCD_COLOR rb->lcd_set_foreground(LCD_WHITE); #endif /* if a parameter is updated (by the user), we must print it */ if (t_disp > 0) { --t_disp; #ifdef HAVE_LCD_COLOR rb->lcd_set_foreground(LCD_WHITE); #endif rb->lcd_putsxyf(0, LCD_HEIGHT-font_h, "star:%d speed:%d", starfield.nb_stars, starfield.z_move); } rb->lcd_update(); button = rb->button_get(false); switch(button) { case (STARFIELD_INCREASE_ZMOVE): case (STARFIELD_INCREASE_ZMOVE | BUTTON_REPEAT): ++(starfield.z_move); pulse=false; t_disp=MSG_DISP_TIME; break; case (STARFIELD_DECREASE_ZMOVE): case (STARFIELD_DECREASE_ZMOVE | BUTTON_REPEAT): --(starfield.z_move); pulse=false; t_disp=MSG_DISP_TIME; break; case(STARFIELD_INCREASE_NB_STARS): case(STARFIELD_INCREASE_NB_STARS | BUTTON_REPEAT): starfield_add_stars(&starfield, STARFIELD_INCREASE_STEP); t_disp=MSG_DISP_TIME; break; case(STARFIELD_DECREASE_NB_STARS): case(STARFIELD_DECREASE_NB_STARS | BUTTON_REPEAT): starfield_del_stars(&starfield, STARFIELD_INCREASE_STEP); t_disp=MSG_DISP_TIME; break; #ifdef HAVE_LCD_COLOR case(STARFIELD_TOGGLE_COLOR): starfield.color=!starfield.color; break; #endif #ifdef STARFIELD_RC_QUIT case STARFIELD_RC_QUIT: #endif case(STARFIELD_QUIT): return PLUGIN_OK; break; default: exit_on_usb(button); break; } } }