static int mystify_timer(TWidget *wid) { if(paused){ return 0; } if(polygons.nb_items > nb_polygons){ /* We have too many polygons, we must drop some of them */ fifo_pop(&polygons); } if(nb_polygons == polygons.nb_items){ /* We have the good number of polygons, we can safely drop the last one to add the new one later */ fifo_pop(&polygons); } fifo_push(&polygons, &leading_polygon); /* * Then we update the leading polygon for the next round acording to * current move (the move may be altered in case of sreen border * collision) */ polygon_update(&leading_polygon, &move); change_color(); wid->dirty++; return 0; }
int plugin_main(void) { int action; int sleep_time=DEFAULT_WAIT_TIME; int nb_wanted_polygons=DEFAULT_NB_POLYGONS; int i; struct polygon_fifo polygons[NB_SCREENS]; struct polygon_move move[NB_SCREENS]; /* This describes the movement of the leading polygon, the others just follow */ struct polygon leading_polygon[NB_SCREENS]; FOR_NB_SCREENS(i) { #ifdef HAVE_LCD_COLOR struct screen *display = rb->screens[i]; if (display->is_color) display->set_background(LCD_BLACK); #endif fifo_init(&polygons[i]); polygon_move_init(&move[i]); polygon_init(&leading_polygon[i], rb->screens[i]); } #ifdef HAVE_LCD_COLOR struct line_color color; color_init(&color); #endif while (true) { FOR_NB_SCREENS(i) { struct screen * display=rb->screens[i]; if(polygons[i].nb_items>nb_wanted_polygons) { /* We have too many polygons, we must drop some of them */ fifo_pop(&polygons[i]); } if(nb_wanted_polygons==polygons[i].nb_items) { /* We have the good number of polygons, we can safely drop the last one to add the new one later */ fifo_pop(&polygons[i]); } fifo_push(&polygons[i], &leading_polygon[i]); /* * Then we update the leading polygon for the next round acording to * current move (the move may be altered in case of sreen border * collision) */ polygon_update(&leading_polygon[i], display, &move[i]); /* Now the drawing part */ #ifdef HAVE_LCD_COLOR color_apply(&color, display); #endif display->clear_display(); polygons_draw(&polygons[i], display); display->update(); } #ifdef HAVE_LCD_COLOR color_change(&color); #endif /* Speed handling*/ if (sleep_time<0)/* full speed */ rb->yield(); else rb->sleep(sleep_time); action = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts, ARRAYLEN(plugin_contexts)); switch(action) { case DEMYSTIFY_QUIT: cleanup(NULL); return PLUGIN_OK; case DEMYSTIFY_ADD_POLYGON: case DEMYSTIFY_ADD_POLYGON_REPEAT: if(nb_wanted_polygons<MAX_POLYGONS) ++nb_wanted_polygons; break; case DEMYSTIFY_REMOVE_POLYGON: case DEMYSTIFY_REMOVE_POLYGON_REPEAT: if(nb_wanted_polygons>MIN_POLYGONS) --nb_wanted_polygons; break; case DEMYSTIFY_INCREASE_SPEED: case DEMYSTIFY_INCREASE_SPEED_REPEAT: if(sleep_time>=0) --sleep_time; break; case DEMYSTIFY_DECREASE_SPEED: case DEMYSTIFY_DECREASE_SPEED_REPEAT: ++sleep_time; break; default: if (rb->default_event_handler_ex(action, cleanup, NULL) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; break; } } }