int view_text(const char *title, const char *text) { struct view_info info; const struct button_mapping *view_contexts[] = { pla_main_ctx, }; int button; init_view(&info, title, text); draw_text(&info); /* wait for keypress */ while(1) { button = pluginlib_getaction(TIMEOUT_BLOCK, view_contexts, ARRAYLEN(view_contexts)); switch (button) { case PLA_UP: case PLA_UP_REPEAT: #ifdef HAVE_SCROLLWHEEL case PLA_SCROLL_BACK: case PLA_SCROLL_BACK_REPEAT: #endif scroll_up(&info, 1); break; case PLA_DOWN: case PLA_DOWN_REPEAT: #ifdef HAVE_SCROLLWHEEL case PLA_SCROLL_FWD: case PLA_SCROLL_FWD_REPEAT: #endif scroll_down(&info, 1); break; case PLA_LEFT: scroll_up(&info, info.display_lines); break; case PLA_RIGHT: scroll_down(&info, info.display_lines); break; case PLA_LEFT_REPEAT: scroll_to_top(&info); break; case PLA_RIGHT_REPEAT: scroll_to_bottom(&info); break; case PLA_EXIT: case PLA_CANCEL: return PLUGIN_OK; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; break; } } return PLUGIN_OK; }
enum plugin_status plugin_start(const void* parameter) { int button; (void)(parameter); #ifdef HAVE_LCD_CHARCELLS if (!pgfx_init(4, 2)) { rb->splash(HZ*2, "Old LCD :("); return PLUGIN_OK; } #endif #ifdef HAVE_LCD_COLOR rb->lcd_clear_display(); rb->lcd_set_foreground(LCD_WHITE); rb->lcd_set_background(LCD_DEFAULT_BG); #endif snow_init(); while (1) { snow_move(); mylcd_update(); #ifdef HAVE_REMOTE_LCD rb->lcd_remote_update(); #endif rb->sleep(HZ/20); /*We get button from PLA this way */ button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts, ARRAYLEN(plugin_contexts)); if ((button == SNOW_QUIT) || (button == SNOW_QUIT2)) { #ifdef HAVE_LCD_CHARCELLS pgfx_release(); #endif return PLUGIN_OK; } else if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { #ifdef HAVE_LCD_CHARCELLS pgfx_release(); #endif return PLUGIN_USB_CONNECTED; } } }
zchar do_input(int timeout, bool show_cursor) { int action; long timeout_at; zchar menu_ret; dumb_show_screen(show_cursor); /* Convert timeout (tenths of a second) to ticks */ if (timeout > 0) timeout = (timeout * HZ) / 10; else timeout = TIMEOUT_BLOCK; timeout_at = *rb->current_tick + timeout; for (;;) { action = pluginlib_getaction(timeout, plugin_contexts, 1); switch (action) { case PLA_QUIT: return ZC_HKEY_QUIT; case PLA_MENU: menu_ret = menu(); if (menu_ret != ZC_BAD) return menu_ret; timeout_at = *rb->current_tick + timeout; break; case PLA_FIRE: return ZC_RETURN; case PLA_START: return ZC_BAD; default: if (timeout != TIMEOUT_BLOCK && !TIME_BEFORE(*rb->current_tick, timeout_at)) return ZC_TIME_OUT; } } }
void wait_for_key() { int action; dumb_show_screen(false); for (;;) { action = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts, 1); switch (action) { case PLA_QUIT: hot_key_quit(); break; case PLA_FIRE: return; } } }
enum plugin_status plugin_start(const void* parameter) { int action, i; struct jackpot game; (void)parameter; rb->srand(*rb->current_tick); #ifdef HAVE_LCD_CHARCELLS patterns_init(rb->screens[SCREEN_MAIN]); #endif /* HAVE_LCD_CHARCELLS */ jackpot_init(&game); FOR_NB_SCREENS(i){ rb->screens[i]->clear_display(); jackpot_display_slot_machine(&game, rb->screens[i]); } /*Empty the event queue*/ rb->button_clear_queue(); while (true) { action = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts, ARRAYLEN(plugin_contexts)); switch ( action ) { case PLA_CANCEL: return PLUGIN_OK; case PLA_SELECT: jackpot_play_turn(&game); break; default: if (rb->default_event_handler_ex(action, jackpot_exit, NULL) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; break; } } jackpot_exit(NULL); return PLUGIN_OK; }
static inline int get_button(void) { return pluginlib_getaction(HZ/2, plugin_contexts, ARRAYLEN(plugin_contexts)); }
enum plugin_status plugin_start(const void* parameter) { int button; #ifdef MAZE_NEW_PRE int lastbutton = BUTTON_NONE; #endif int quit = 0; struct maze maze; (void)parameter; /* Turn off backlight timeout */ backlight_ignore_timeout(); /* Seed the RNG */ rb->srand(*rb->current_tick); FOR_NB_SCREENS(i) rb->screens[i]->set_viewport(NULL); /* Draw the background */ #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); #if LCD_DEPTH >= 16 rb->lcd_set_foreground(LCD_RGBPACK( 0, 0, 0)); rb->lcd_set_background(LCD_RGBPACK(182, 198, 229)); /* rockbox blue */ #elif LCD_DEPTH == 2 rb->lcd_set_foreground(0); rb->lcd_set_background(LCD_DEFAULT_BG); #endif #endif /* Initialize and draw the maze */ maze_init(&maze); maze_generate(&maze); FOR_NB_SCREENS(i) maze_draw(&maze, rb->screens[i]); while(!quit) { #ifdef __PLUGINLIB_ACTIONS_H__ button = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts, ARRAYLEN(plugin_contexts)); #else button = rb->button_get(true); #endif switch(button) { case MAZE_NEW: #ifdef MAZE_NEW_PRE if(lastbutton != MAZE_NEW_PRE) break; #endif maze_init(&maze); maze_generate(&maze); FOR_NB_SCREENS(i) maze_draw(&maze, rb->screens[i]); break; case MAZE_SOLVE: maze_solve(&maze); FOR_NB_SCREENS(i) maze_draw(&maze, rb->screens[i]); break; case MAZE_UP: case MAZE_UP_REPEAT: maze_move_player_up(&maze); FOR_NB_SCREENS(i) maze_draw(&maze, rb->screens[i]); break; case MAZE_RIGHT: case MAZE_RIGHT_REPEAT: maze_move_player_right(&maze); FOR_NB_SCREENS(i) maze_draw(&maze, rb->screens[i]); break; case MAZE_DOWN: case MAZE_DOWN_REPEAT: maze_move_player_down(&maze); FOR_NB_SCREENS(i) maze_draw(&maze, rb->screens[i]); break; case MAZE_LEFT: case MAZE_LEFT_REPEAT: maze_move_player_left(&maze); FOR_NB_SCREENS(i) maze_draw(&maze, rb->screens[i]); break; case MAZE_QUIT: /* quit plugin */ quit=1; break; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { /* quit plugin */ quit=2; } break; } #ifdef MAZE_NEW_PRE if( button != BUTTON_NONE ) lastbutton = button; #endif } /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); return ((quit == 1) ? PLUGIN_OK : PLUGIN_USB_CONNECTED); }
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; } } }
static void time_greyscale(void) { char str[32]; /* text buffer */ long time_start; /* start tickcount */ long time_end; /* end tickcount */ long time_1, time_2; int frames_1, frames_2; int fps, load; size_t gbuf_size; unsigned char *gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); #if NUM_CORES > 1 int i; for (i = 0; i < NUM_CORES; i++) { rb->snprintf(str, sizeof(str), "Greyscale (%s)", (i > 0) ? "COP" : "CPU"); log_text(str); #else const int i = 0; log_text("Greyscale library"); { #endif if (!grey_init(gbuf, gbuf_size, (i > 0) ? GREY_ON_COP : 0, LCD_WIDTH, LCD_HEIGHT, NULL)) { log_text("greylib: out of memory."); return; } make_grey_rect(LCD_WIDTH, LCD_HEIGHT); /* Test 1 - greyscale overlay not yet enabled */ frames_1 = 0; rb->sleep(0); /* sync to tick */ time_start = *rb->current_tick; while((time_end = *rb->current_tick) - time_start < DURATION) { grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT); frames_1++; } time_1 = time_end - time_start; /* Test 2 - greyscale overlay enabled */ grey_show(true); frames_2 = 0; rb->sleep(0); /* sync to tick */ time_start = *rb->current_tick; while((time_end = *rb->current_tick) - time_start < DURATION) { grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT); frames_2++; } time_2 = time_end - time_start; grey_release(); fps = calc_tenth_fps(frames_2, time_2); load = 100 - (100 * frames_2 * time_1) / (frames_1 * time_2); rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10); log_text(str); if (load > 0 && load < 100) { rb->snprintf(str, sizeof(str), "CPU load: %d%%", load); log_text(str); } else log_text("CPU load err (boost?)"); } } #endif void plugin_quit(void) { #ifdef HAVE_TOUCHSCREEN static struct touchbutton button[] = {{ .action = ACTION_STD_OK, .title = "OK", /* .vp runtime initialized, rest false/NULL */ }}; struct viewport *vp = &button[0].vp; struct screen *lcd = rb->screens[SCREEN_MAIN]; rb->viewport_set_defaults(vp, SCREEN_MAIN); const int border = 10; const int height = 50; lcd->set_viewport(vp); /* button matches the bottom center in the grid */ vp->x = lcd->lcdwidth/3; vp->width = lcd->lcdwidth/3; vp->height = height; vp->y = lcd->lcdheight - height - border; touchbutton_draw(button, ARRAYLEN(button)); lcd->update_viewport(); if (rb->touchscreen_get_mode() == TOUCHSCREEN_POINT) { while(touchbutton_get(button, ARRAYLEN(button)) != ACTION_STD_OK); } else #endif while (1) { int btn = pluginlib_getaction(TIMEOUT_BLOCK, plugin_contexts, ARRAYLEN(plugin_contexts)); exit_on_usb(btn); if ((btn == FPS_QUIT) || (btn == FPS_QUIT2)) break; } }
/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { (void)parameter; b = rb->lcd_framebuffer; rb->lcd_set_background(LCD_RGBPACK(0,0,0)); rb->lcd_clear_display(); // TODO: Optimizes this by e.g. invalidating rects input_bmp.data = (char*)input_bmp_data; output_bmp.data = (char*)output_bmp_data; int ret = rb->read_bmp_file("/test.bmp", &input_bmp, sizeof(input_bmp_data), FORMAT_NATIVE, NULL); if (ret < 0) { rb->splash(HZ, "Could not load /test.bmp"); return PLUGIN_ERROR; } int button; output_bmp.width = 50; output_bmp.height = 50; DEBUGF("input_bmp_data starts at %p\n", input_bmp_data); DEBUGF("output_bmp_data starts at %p\n", output_bmp_data); int scale_algorithm = 0; while(1) { rb->lcd_clear_display(); rb->lcd_bitmap(input_bmp_data, 0, 0, input_bmp.width, input_bmp.height); switch ( scale_algorithm ) { case 0: smooth_resize_bitmap(&input_bmp, &output_bmp); rb->lcd_putsxy(0,0,"smooth_resize_bitmap"); break; case 1: simple_resize_bitmap(&input_bmp, &output_bmp); rb->lcd_putsxy(0,0,"simple_resize_bitmap"); break; } rb->lcd_bitmap(output_bmp_data, 0, 100, output_bmp.width, output_bmp.height); rb->lcd_update(); button = pluginlib_getaction(HZ, plugin_contexts, ARRAYLEN(plugin_contexts)); switch (button) { case BUTTON_QUIT: return PLUGIN_OK; case SIZE_INCREASE: case SIZE_INCREASE_REPEAT: if (output_bmp.width < MAX_OUTPUT_WIDTH - 2) output_bmp.width += 2; if (output_bmp.height < MAX_OUTPUT_HEIGHT - 2) output_bmp.height += 2; break; case SIZE_DECREASE: case SIZE_DECREASE_REPEAT: if (output_bmp.width > 2) output_bmp.width -= 2; if (output_bmp.height > 2) output_bmp.height -= 2; break; case WIDTH_INCREASE: case WIDTH_INCREASE_REPEAT: if (output_bmp.width < MAX_OUTPUT_WIDTH - 2) output_bmp.width += 2; break; case WIDTH_DECREASE: case WIDTH_DECREASE_REPEAT: if (output_bmp.width > 2) output_bmp.width -= 2; break; case CHANGE_MODE: scale_algorithm = (scale_algorithm+1)%2; break; } } return PLUGIN_OK; }
/********************************************************************** * Plugin starts here **********************************************************************/ enum plugin_status plugin_start(const void* parameter){ int button; int last_second = -1; bool redraw=true; struct time time; struct counter counter; bool exit_clock = false; (void)parameter; atexit(cleanup); #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); #endif load_settings(); /* init xlcd functions */ counter_init(&counter); clock_draw_set_colors(); while(!exit_clock){ clock_update_time(&time); if(!clock_settings.general.idle_poweroff) rb->reset_poweroff_timer(); /************************* * Scan for button presses ************************/ button = pluginlib_getaction(HZ/10, plugin_contexts, PLA_ARRAY_COUNT); redraw=true;/* we'll set it to false afterwards if there was no action */ switch (button){ case ACTION_COUNTER_TOGGLE: /* start/stop counter */ if(clock_settings.general.show_counter) counter_toggle(&counter); break; case ACTION_COUNTER_RESET: /* reset counter */ if(clock_settings.general.show_counter) counter_reset(&counter); break; case ACTION_MODE_NEXT_REPEAT: case ACTION_MODE_NEXT: clock_settings.mode++; if(clock_settings.mode >= NB_CLOCK_MODES) clock_settings.mode = 0; break; case ACTION_MODE_PREV_REPEAT: case ACTION_MODE_PREV: clock_settings.mode--; if(clock_settings.mode < 0) clock_settings.mode = NB_CLOCK_MODES-1; break; case ACTION_SKIN_PREV_REPEAT: case ACTION_SKIN_PREV: clock_settings_skin_next(&clock_settings); break; case ACTION_SKIN_NEXT_REPEAT: case ACTION_SKIN_NEXT: clock_settings_skin_previous(&clock_settings); break; case ACTION_MENU: clock_draw_restore_colors(); exit_clock=main_menu(); break; default: exit_on_usb(button); if(time.second != last_second){ last_second=time.second; redraw=true; }else redraw=false; break; } if(redraw){ clock_draw_set_colors(); FOR_NB_SCREENS(i) clock_draw(rb->screens[i], &time, &counter); redraw=false; } } return PLUGIN_OK; }
int main(void) { plasma_frequency = 1; int action, x, y; unsigned char p1,p2,p3,p4,t1,t2,t3,t4, z,z0; #ifdef HAVE_ADJUSTABLE_CPU_FREQ long last_tick = *rb->current_tick; int delay; int cumulated_lag = 0; #endif #ifdef HAVE_LCD_COLOR #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256) unsigned char *ptr; #else fb_data *ptr; #endif int time=0; #else unsigned char *ptr; #endif /*Generate the neccesary pre calced stuff*/ wave_table_generate(); #ifndef HAVE_LCD_COLOR shades_generate(); /* statically */ /* get the remainder of the plugin buffer */ gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL)) { rb->splash(HZ, "Couldn't init greyscale display"); return PLUGIN_ERROR; } /* switch on greyscale overlay */ grey_show(true); #endif atexit(cleanup); sp1 = 4; sp2 = 2; sp3 = 4; sp4 = 2; p1=p2=p3=p4=0; while (true) { #ifdef HAVE_LCD_COLOR shades_generate(time++); /* dynamically */ #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256) ptr = (unsigned char*)rb->lcd_framebuffer; #else ptr = rb->lcd_framebuffer; #endif #else ptr = greybuffer; #endif t1=p1; t2=p2; for(y = 0; y < LCD_HEIGHT; ++y) { t3=p3; t4=p4; z0 = wave_array[t1] + wave_array[t2]; for(x = 0; x < LCD_WIDTH; ++x) { z = z0 + wave_array[t3] + wave_array[t4]; #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256) *ptr++ = z; #else *ptr++ = colours[z]; #endif t3+=1; t4+=2; } t1+=2; t2+=1; rb->yield(); } p1+=sp1; p2-=sp2; p3+=sp3; p4-=sp4; #ifdef HAVE_LCD_COLOR #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256) rb->lcd_blit_pal256( (unsigned char*)rb->lcd_framebuffer, 0,0,0,0,LCD_WIDTH,LCD_HEIGHT); #else rb->lcd_update(); #endif #else grey_ub_gray_bitmap(greybuffer, 0, 0, LCD_WIDTH, LCD_HEIGHT); #endif #ifdef HAVE_ADJUSTABLE_CPU_FREQ delay = last_tick - *rb->current_tick + HZ/33; if (!boosted && delay < 0) { cumulated_lag -= delay; /* proportional increase */ if (cumulated_lag >= HZ) rb->cpu_boost(boosted = true); } else if (boosted && delay > 1) /* account for jitter */ { if (--cumulated_lag <= 0) /* slow decrease */ rb->cpu_boost(boosted = false); } last_tick = *rb->current_tick; #endif action = pluginlib_getaction(0, plugin_contexts, ARRAYLEN(plugin_contexts)); switch(action) { case PLA_EXIT: case PLA_CANCEL: return PLUGIN_OK; break; #ifdef HAVE_SCROLLWHEEL case PLA_SCROLL_FWD: case PLA_SCROLL_FWD_REPEAT: #endif case PLA_UP: case PLA_UP_REPEAT: ++plasma_frequency; wave_table_generate(); break; #ifdef HAVE_SCROLLWHEEL case PLA_SCROLL_BACK: case PLA_SCROLL_BACK_REPEAT: #endif case PLA_DOWN: case PLA_DOWN_REPEAT: if(plasma_frequency>1) { --plasma_frequency; wave_table_generate(); } break; #ifdef HAVE_LCD_COLOR case PLA_SELECT: redfactor=rb->rand()%4; greenfactor=rb->rand()%4; bluefactor=rb->rand()%4; redphase=rb->rand()%256; greenphase=rb->rand()%256; bluephase=rb->rand()%256; break; #endif default: exit_on_usb(action); break; } } }