/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { (void)parameter; int ret; rb->lcd_setfont(FONT_SYSFIXED); #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 /* Turn off backlight timeout */ backlight_ignore_timeout(); rb->srand( *rb->current_tick ); configfile_load(CFG_FILE, config, 1, 0); chopper_load(true); ret = chopGameLoop(); configfile_save(CFG_FILE, config, 1, 0); rb->lcd_setfont(FONT_UI); /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); return ret; }
void cleanup(void *parameter) { (void)parameter; grey_release(); /* switch off overlay and deinitialize */ /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); }
void cleanup(void *parameter) { (void)parameter; backlight_use_settings(); #ifdef HAVE_REMOTE_LCD remote_backlight_use_settings(); #endif }
void exit_handler(void) { sys_save_settings(save_sys); sys_stopAudio(save_sys); rb->timer_unregister(); #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(false); #endif backlight_use_settings(); }
void cleanup(void *parameter) { (void)parameter; #ifdef HAVE_ADJUSTABLE_CPU_FREQ if (boosted) rb->cpu_boost(false); #endif #ifndef HAVE_LCD_COLOR grey_release(); #endif /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); /* backlight control in lib/helper.c */ }
enum plugin_status plugin_start (const void *parameter) { (void) parameter; rb->srand (*rb->current_tick); /* Load HighScore if any */ highscore_load(SCORE_FILE, highscores, NUM_SCORES); #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); #endif #ifdef HAVE_LCD_BITMAP rb->lcd_setfont (FONT_SYSFIXED); #else if (!pgfx_init(4, 2)) { rb->splash(HZ*2, "Old LCD :("); return PLUGIN_OK; } #endif /* Turn off backlight timeout */ backlight_ignore_timeout(); load_game(); resume_file = resume; while(!rockblox_loop()) { if(!resume) { int position = highscore_update(rockblox_status.score, rockblox_status.level, "", highscores, NUM_SCORES); if (position != -1) { if (position == 0) rb->splash(HZ*2, "New High Score"); highscore_show(position, highscores, NUM_SCORES, true); } } } #ifndef HAVE_LCD_BITMAP pgfx_release(); #endif /* Save user's HighScore */ highscore_save(SCORE_FILE, highscores, NUM_SCORES); backlight_use_settings(); return PLUGIN_OK; }
enum plugin_status plugin_start(const void* parameter) { int ret; (void)parameter; /* Turn off backlight timeout */ backlight_ignore_timeout(); ret = plugin_main(); /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); return ret; }
static void cleanup(void) { #ifdef HAVE_ADJUSTABLE_CPU_FREQ if (boosted) rb->cpu_boost(false); #endif #ifndef HAVE_LCD_COLOR grey_release(); #endif /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256) rb->lcd_set_mode(LCD_MODE_RGB565); #endif }
/* plugin entry point */ enum plugin_status plugin_start(const void* parameter) { #if (CONFIG_PLATFORM & PLATFORM_NATIVE) char str[32]; int cpu_freq; #endif /* standard stuff */ (void)parameter; #ifdef HAVE_TOUCHSCREEN rb->touchscreen_set_mode(rb->global_settings->touch_mode); #endif log_init(); #if (CONFIG_PLATFORM & PLATFORM_NATIVE) cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */ #endif backlight_ignore_timeout(); time_main_update(); rb->sleep(HZ); #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2) time_main_yuv(); #endif #if LCD_DEPTH < 4 time_greyscale(); #endif #ifdef HAVE_REMOTE_LCD time_remote_update(); #endif #if (CONFIG_PLATFORM & PLATFORM_NATIVE) if (*rb->cpu_frequency != cpu_freq) rb->snprintf(str, sizeof(str), "CPU clock changed!"); else rb->snprintf(str, sizeof(str), "CPU: %d MHz", (cpu_freq + 500000) / 1000000); log_text(str); #endif backlight_use_settings(); /* wait until user closes plugin */ plugin_quit(); return PLUGIN_OK; }
/* plugin entry point */ enum plugin_status plugin_start(const void* parameter) { #ifndef SIMULATOR char str[32]; int cpu_freq; #endif /* standard stuff */ PLUGIN_IRAM_INIT(rb) (void)parameter; log_init(); #ifndef SIMULATOR cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */ #endif backlight_force_on(); /* backlight control in lib/helper.c */ log_text("Main LCD Update"); time_main_update(); #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2) log_text("Main LCD YUV"); time_main_yuv(); #endif #if LCD_DEPTH < 4 log_text("Greyscale library"); time_greyscale(); #endif #ifdef HAVE_REMOTE_LCD log_text("Remote LCD Update"); time_remote_update(); #endif #ifndef SIMULATOR if (*rb->cpu_frequency != cpu_freq) rb->snprintf(str, sizeof(str), "CPU clock changed!"); else rb->snprintf(str, sizeof(str), "CPU: %d MHz", (cpu_freq + 500000) / 1000000); log_text(str); #endif backlight_use_settings(); /* backlight control in lib/helper.c */ /* wait until user closes plugin */ while (rb->button_get(true) != FPS_QUIT); return PLUGIN_OK; }
static int rockblox_loop (void) { int button; #if defined(ROCKBLOX_OFF_PRE) || defined(ROCKBLOX_DROP_PRE) int lastbutton = BUTTON_NONE; #endif long next_down_tick = *rb->current_tick + level_speed(rockblox_status.level); if (rockblox_menu()) { return 1; } resume = false; resume_file = false; while (1) { #ifdef HAS_BUTTON_HOLD if (rb->button_hold ()) { /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); rb->splash(0, "Paused"); while (rb->button_hold ()) rb->sleep(HZ/10); /* Turn off backlight timeout */ backlight_ignore_timeout(); /* get rid of the splash text */ rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT); show_details (); #ifdef HIGH_SCORE_Y show_highscores (); #endif draw_next_block (); refresh_board (); } #endif button = rb->button_get_w_tmo (MAX(next_down_tick - *rb->current_tick, 1)); switch (button) { #ifdef ROCKBLOX_RC_OFF case ROCKBLOX_RC_OFF: #endif case ROCKBLOX_OFF: #ifdef ROCKBLOX_OFF_PRE if (lastbutton != ROCKBLOX_OFF_PRE) break; #endif resume = true; return 0; break; #if defined(ROCKBLOX_ROTATE) case ROCKBLOX_ROTATE: #endif case ROCKBLOX_ROTATE_CCW: case ROCKBLOX_ROTATE_CCW | BUTTON_REPEAT: #ifdef HAVE_SCROLLWHEEL /* if the wheel is disabled, add an event to the stack. */ if(wheel_enabled == false) wheel_events++; /* if it's enabled, go ahead and rotate.. */ if(wheel_enabled) #endif #ifdef ROCKBLOX_ROTATE_CCW2 /* fallback */ case ROCKBLOX_ROTATE_CCW2: #endif move_block (0, 0, (rockblox_status.co + 1) % figures[rockblox_status.cf].max_or); break; case ROCKBLOX_ROTATE_CW: case ROCKBLOX_ROTATE_CW | BUTTON_REPEAT: #ifdef HAVE_SCROLLWHEEL if(wheel_enabled == false) wheel_events++; if(wheel_enabled) #endif #ifdef ROCKBLOX_ROTATE_CW2 /* fallback */ case ROCKBLOX_ROTATE_CW2: #endif move_block (0, 0, (rockblox_status.co + figures[rockblox_status.cf].max_or - 1) % figures[rockblox_status.cf].max_or); break; case ROCKBLOX_DOWN: case ROCKBLOX_DOWN | BUTTON_REPEAT: move_block (0, 1, rockblox_status.co); break; case ROCKBLOX_RIGHT: case ROCKBLOX_RIGHT | BUTTON_REPEAT: move_block (1, 0, rockblox_status.co); break; case ROCKBLOX_LEFT: case ROCKBLOX_LEFT | BUTTON_REPEAT: move_block (-1, 0, rockblox_status.co); break; case ROCKBLOX_DROP: #ifdef ROCKBLOX_DROP_PRE if (lastbutton != ROCKBLOX_DROP_PRE) break; #endif while (canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co)) move_block (0, 1, rockblox_status.co); rockblox_status.dropped = true; break; #ifdef ROCKBLOX_RESTART case ROCKBLOX_RESTART: rb->splash (HZ * 1, "Restarting..."); init_rockblox (false); break; #endif default: if (rb->default_event_handler (button) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; break; } #if defined(ROCKBLOX_OFF_PRE) || defined(ROCKBLOX_DROP_PRE) if (button != BUTTON_NONE) lastbutton = button; #endif #ifdef HAVE_SCROLLWHEEL /* check if we should enable the scroll wheel, if events * begin to stack up... */ if(wheel_enabled == false) { /* stopped rotating the wheel, reset the count */ if(wheel_events == last_wheel_event) { last_wheel_event = 0; wheel_events = 0; } /* rotated the wheel a while constantly, enable it. */ else if(wheel_events > 3) { wheel_enabled = true; } /* this evens out the last event and the "current" event. * if we get an event next time through button reading, it will * remain ahead of last_event. if we don't, they'll end up equaling * each other.. thus, the scroll count will be reset. */ if(wheel_enabled == false && wheel_events > last_wheel_event) last_wheel_event++; } #endif if (TIME_AFTER(*rb->current_tick, next_down_tick)) { move_down (); next_down_tick += level_speed(rockblox_status.level); if (TIME_AFTER(*rb->current_tick, next_down_tick)) /* restart time "raster" when we had to wait longer than usual * (pause, game restart etc) */ next_down_tick = *rb->current_tick + level_speed(rockblox_status.level); } if (rockblox_status.gameover) { #if LCD_DEPTH >= 2 rb->lcd_set_foreground (LCD_BLACK); #endif show_game_over(); resume = false; return 0; } refresh_board (); } return 0; }
int plugin_main(void) { char str_buffer[40]; int button, avg_peak, t_disp=0; int font_h, font_w; bool pulse=true; 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==true){ /* Get the peaks. ( Borrowed from vu_meter ) */ #if (CONFIG_CODEC == SWCODEC) int left_peak, right_peak; rb->pcm_calculate_peaks(&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; rb->snprintf(str_buffer, sizeof(str_buffer), "star:%d speed:%d", starfield.nb_stars, starfield.z_move); #ifdef HAVE_LCD_COLOR rb->lcd_set_foreground(LCD_WHITE); #endif rb->lcd_putsxy(0, LCD_HEIGHT-font_h, str_buffer); } 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): case(SYS_USB_CONNECTED): /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); /* backlight control in lib/helper.c*/ return PLUGIN_OK; break; } } }
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); }
/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { enum plugin_status status = PLUGIN_OK; long button; bool quit = false; (void)parameter; #ifdef HAVE_LCD_COLOR int cs = 0; bool update = false; #endif /* HAVE_LCD_COLOR */ #if LCD_DEPTH > 1 unsigned bg_color = rb->lcd_get_background(); rb->lcd_set_backdrop(NULL); rb->lcd_set_background(LCD_WHITE); #endif #ifdef HAVE_BACKLIGHT_BRIGHTNESS int current_brightness = MAX_BRIGHTNESS_SETTING; backlight_brightness_set(MAX_BRIGHTNESS_SETTING); #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS buttonlight_brightness_set(MAX_BRIGHTNESS_SETTING); #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ #ifdef HAVE_LCD_INVERT #ifdef HAVE_NEGATIVE_LCD rb->lcd_set_invert_display(true); #else rb->lcd_set_invert_display(false); #endif /* HAVE_NEGATIVE_LCD */ #endif /* HAVE_LCD_INVERT */ backlight_force_on(); #ifdef HAVE_BUTTON_LIGHT buttonlight_force_on(); #endif /* HAVE_BUTTON_LIGHT */ rb->lcd_clear_display(); rb->lcd_update(); do { #ifdef HAVE_LCD_COLOR if(update) { if(cs < 0) cs = NUM_COLORSETS-1; if(cs >= NUM_COLORSETS) cs = 0; rb->lcd_set_background(colorset[cs]); rb->lcd_clear_display(); rb->lcd_update(); update = false; } #endif /* HAVE_LCD_COLOR */ switch((button = rb->button_get_w_tmo(HZ*30))) { #ifdef HAVE_LCD_COLOR case LAMP_RIGHT: #ifdef LAMP_NEXT case LAMP_NEXT: #endif /* LAMP_NEXT */ cs++; update = true; break; case LAMP_LEFT: #ifdef LAMP_PREV case LAMP_PREV: #endif /* LAMP_PREV */ cs--; update = true; break; #endif /* HAVE_LCD_COLOR */ #ifdef HAVE_BACKLIGHT_BRIGHTNESS case LAMP_UP: case (LAMP_UP|BUTTON_REPEAT): if (current_brightness < MAX_BRIGHTNESS_SETTING) backlight_brightness_set(++current_brightness); break; case LAMP_DOWN: case (LAMP_DOWN|BUTTON_REPEAT): if (current_brightness > MIN_BRIGHTNESS_SETTING) backlight_brightness_set(--current_brightness); break; #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ case BUTTON_NONE: /* time out */ break; default: if(rb->default_event_handler(button) == SYS_USB_CONNECTED) { status = PLUGIN_USB_CONNECTED; quit = true; } if(!(button & (BUTTON_REL|BUTTON_REPEAT)) && !IS_SYSEVENT(button)) quit = true; break; } rb->reset_poweroff_timer(); } while (!quit); /* restore */ backlight_use_settings(); #ifdef HAVE_BUTTON_LIGHT buttonlight_use_settings(); #endif /* HAVE_BUTTON_LIGHT */ #ifdef HAVE_LCD_INVERT rb->lcd_set_invert_display(rb->global_settings->invert); #endif /* HAVE_LCD_INVERT */ #ifdef HAVE_BACKLIGHT_BRIGHTNESS backlight_brightness_use_setting(); #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS buttonlight_brightness_use_setting(); #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ #if LCD_DEPTH > 1 rb->lcd_set_background(bg_color); #endif return status; }
static void color_to_resistance(void) { backlight_ignore_timeout(); bool quit = false; int button_input = 0; /* The colors of the bands */ enum color first_band = 0; enum color second_band = 0; enum color third_band = 0; enum color fourth_band = 0; int total_resistance_centiunits = 0; char total_resistance_str [35]; rb->splash(HZ/2, "Colour to resistance"); rb->lcd_clear_display(); while(!quit) { first_band = do_first_band_menu(); if(first_band==RES_INVALID) break; second_band = do_second_band_menu(); if(second_band==RES_INVALID) break; third_band = do_third_band_menu(); if(third_band==RES_INVALID) break; fourth_band = do_fourth_band_menu(); if(third_band==RES_INVALID) break; total_resistance_centiunits = calculate_resistance(first_band, second_band, third_band); rb->lcd_clear_display(); lineno = INITIAL_TEXT_Y; #ifndef USE_TEXT_ONLY draw_resistor(first_band, second_band, third_band, fourth_band); #endif draw_resistor_text(first_band, second_band, third_band, fourth_band); if(total_resistance_centiunits % 100 == 0) { /* No decimals */ rb->snprintf(total_resistance_str, sizeof(total_resistance_str), "Resistance: %d %s", total_resistance_centiunits/100, unit_abbrev); } else { rb->snprintf(total_resistance_str, sizeof(total_resistance_str), "Resistance: %d.%2.2d %s", total_resistance_centiunits/100, total_resistance_centiunits%100, unit_abbrev); } display->set_viewport(&text_vp); rb->lcd_puts_scroll(total_resistance_str_x, lineno++, total_resistance_str); rb->lcd_puts_scroll(tolerance_str_x, lineno++, get_tolerance_str(fourth_band)); rb->lcd_update(); button_input = rb->button_get(true); switch(button_input) { case PLA_RIGHT: break; case PLA_EXIT: case PLA_SELECT: default: quit = true; backlight_use_settings(); break; } } display->set_viewport(&text_vp); rb->lcd_stop_scroll(); display->set_viewport(&screen_vp); rb->lcd_clear_display(); return; }
static void resistance_to_color(void) { backlight_ignore_timeout(); int menu_selection; int menu_selection_tol; int button_press; int i; bool quit = false; char kbd_buffer [10]; int kbd_input_int; int temp; int in_resistance_int; int power_ten=0; int first_band_int = 0; int second_band_int = 0; enum color first_band; enum color second_band; enum color multiplier; enum color fourth_band = 0; enum color units_used = 0; char out_str[20]; for(i=0; i<=10; i++) { kbd_buffer[i] = 0; } /* This cleans out the mysterious garbage that appears */ rb->lcd_clear_display(); rb->splash(HZ/2, "Resistance to Colour"); MENUITEM_STRINGLIST(r_to_c_menu, "Select unit to use:", NULL, "Ohms", "Kiloohms (KOhms)", "Megaohms (MOhms)", "Gigaohms (GOhms)"); MENUITEM_STRINGLIST(r_to_c_menu_tol, "Tolerance to display:", NULL, "5%", "10%", "1%", "2%", "20%"); while(!quit) { int ret; ret=menu_selection = rb->do_menu(&r_to_c_menu, &menu_selection, NULL, false); if(ret<0) break; rb->kbd_input(kbd_buffer, sizeof(kbd_buffer)); /* As stated above somewhere, we (I) need to make a calculator-like keypad, that keyboard isn't all that fun to use. */ ret = rb->do_menu(&r_to_c_menu_tol, &menu_selection_tol, NULL, false); if(ret<0) break; switch(menu_selection_tol) { case 0: /* 5% */ fourth_band = RES_GOLD; break; case 1: /* 10% */ fourth_band = RES_SILVER; break; case 2: /* 1% */ fourth_band = RES_BROWN; break; case 3: /* 2% */ fourth_band = RES_RED; break; case 4: /* 20% */ fourth_band = RES_NONE; break; } kbd_input_int = rb->atoi(kbd_buffer); in_resistance_int = kbd_input_int; switch(menu_selection) { case 0: power_ten=0; units_used = RES_BLACK; break; case 1: /* KOhms */ power_ten=3; units_used = RES_ORANGE; break; case 2: /* MOhms */ power_ten=6; units_used = RES_BLUE; break; case 3: /* GOhms */ power_ten=9; units_used = RES_WHITE; break; } temp=kbd_input_int; while(temp>=100) { temp/=10; power_ten++; } first_band_int=temp/10; second_band_int=temp%10; first_band = get_band_rtoc(first_band_int); second_band = get_band_rtoc(second_band_int); multiplier = get_band_rtoc(power_ten); if( first_band == RES_INVALID || second_band == RES_INVALID || multiplier == RES_INVALID) { rb->splashf(HZ, "%d %s can not be represented", in_resistance_int,band_data[units_used].unit); return; } rb->lcd_clear_display(); lineno = INITIAL_TEXT_Y; #ifndef USE_TEXT_ONLY draw_resistor(first_band, second_band, multiplier, fourth_band); #endif draw_resistor_text(first_band, second_band, multiplier, fourth_band); rb->snprintf(out_str, sizeof(out_str), "Input: %d %s", in_resistance_int, band_data[units_used].unit); display->set_viewport(&text_vp); rb->lcd_puts_scroll(r_to_c_out_str_x, lineno++, out_str); rb->lcd_update(); button_press = rb->button_get(true); switch(button_press) { case PLA_SELECT: break; default: quit = true; backlight_use_settings(); break; } } display->set_viewport(&text_vp); rb->lcd_stop_scroll(); display->set_viewport(&screen_vp); rb->lcd_clear_display(); }
static void led_resistance_calc(void) { backlight_ignore_timeout(); int voltage_menu_selection, button_press, j, k, l, foreward_current = 0; int fwd_current_selection = 0; bool quit = false; char kbd_buffer [5]; char fwd_kbd_buffer [5]; int input_voltage, led_voltage = 0; int resistance = 0; int rounded_resistance = 0; int temp; int power_rating_in = 0; int rounded_power_rating = 0; int out_int = 0; char current_out_str [16]; char true_current_out_str [40]; char rounded_resistance_out_str [40]; char power_rating_out_str [40]; int power_ten, first_band_int, second_band_int = 0; enum color first_band; enum color second_band; enum color multiplier; enum color fourth_band = RES_NONE; rb->lcd_clear_display(); MENUITEM_STRINGLIST(voltage_menu, "Select LED voltage:", NULL, "2v (Common red, orange)", "1.5v (IR)", "2.1v (Yellow)", "2.2v (Green)", "3.3v (True green, blue, white, UV)", "4.6v (Blue - 430nm)"); MENUITEM_STRINGLIST(fwd_current_menu, "Select foreward current:", NULL, "20mA - Most common for 5mm and 3mm LEDs - select if unsure.", "Key in other (only if already known)"); while(!quit) { int ret; ret = voltage_menu_selection = rb->do_menu(&voltage_menu, &voltage_menu_selection, NULL, false); if(ret<0) break; ret = fwd_current_selection = rb->do_menu(&fwd_current_menu, &fwd_current_selection, NULL, false); if(ret<0) break; rb->lcd_clear_display(); rb->splash(HZ*2, "(First) Input the supply voltage:"); memset(kbd_buffer,0,sizeof(kbd_buffer)); rb->kbd_input(kbd_buffer, sizeof(kbd_buffer)); input_voltage = rb->atoi(kbd_buffer); if(input_voltage == 0) break; if(input_voltage != (int)input_voltage) { input_voltage *= 10; } else { input_voltage *= 100; } switch(voltage_menu_selection) { case 0: /* 2v */ led_voltage = 200; break; case 1: /* 1.5v */ led_voltage = 150; break; case 2: /* 2.1 */ led_voltage = 210; break; case 3: led_voltage = 220; break; case 4: led_voltage = 330; break; case 5: led_voltage = 460; break; } switch(fwd_current_selection) { case 0: /* 20mA */ foreward_current = 2; /* 20mA * 100 */ break; case 1: rb->lcd_clear_display(); rb->splash(HZ*2, "Input the foreward current, in mA"); memset(fwd_kbd_buffer,0,sizeof(fwd_kbd_buffer)); rb->kbd_input(fwd_kbd_buffer, sizeof(fwd_kbd_buffer)); foreward_current = ((rb->atoi(fwd_kbd_buffer))/10); break; } if(foreward_current == 0) break; rb->lcd_clear_display(); resistance = (input_voltage - led_voltage) / foreward_current; out_int = resistance; int total_common_values = 11; int total_power_values = 9; if(led_voltage > input_voltage) { rb->splash(HZ, "Problem: LED voltage is higher than the source."); break; } for(j = 0; j < total_common_values; j++) { for(k = 1; k < 5; k++) { if( resistance == (common_values[j] * powi(10, k))) { rounded_resistance = (common_values[j] * powi(10, k)); /* perfect match */ break; } else if(resistance >= (common_values[j] * powi(10, k)) && resistance <= (common_values[j+1] * powi(10, k))) { rounded_resistance = (common_values[j+1] * powi(10, k)); /* the higher resistance, to be safe */ break; } else { break; } } } if(rounded_resistance == 0) { rb->splash(HZ, "Problem: Input voltage too high."); break; } power_rating_in = ((input_voltage/100)*(input_voltage/100)*1000 / rounded_resistance); /* in mW */ for(l = 0; l < total_power_values; l++) { if((int)power_rating_in == power_ratings[l]) { rounded_power_rating = (power_ratings[l]); break; } else if(power_rating_in >= power_ratings[l] && power_rating_in <= power_ratings[l+1]) { rounded_power_rating = power_ratings[l+1]; break; } else { break; } } get_power_rating_str(rounded_power_rating); power_ten=0; temp=rounded_resistance; while(temp>=100) { temp/=10; power_ten++; } first_band_int=temp/10; second_band_int=temp%10; first_band = get_band_rtoc(first_band_int); second_band = get_band_rtoc(second_band_int); multiplier = get_band_rtoc(power_ten); rb->lcd_clear_display(); lineno = INITIAL_TEXT_Y; #ifndef USE_TEXT_ONLY draw_resistor(first_band, second_band, multiplier, fourth_band); #endif draw_resistor_text(first_band, second_band, multiplier, fourth_band); rb->snprintf(current_out_str, sizeof(current_out_str), "%d mA", (foreward_current*10)); rb->snprintf(true_current_out_str, sizeof(true_current_out_str), "Input: %dv, %d Ohms @ %s", (input_voltage/100), out_int, current_out_str); rb->snprintf(rounded_resistance_out_str, sizeof(rounded_resistance_out_str), "Rounded/displayed: [%d %s]", rounded_resistance, band_data[multiplier].unit); rb->snprintf(power_rating_out_str, sizeof(power_rating_out_str), "Recommended: %s or greater", get_power_rating_str(rounded_power_rating)); display->set_viewport(&text_vp); rb->lcd_puts_scroll(resistance_val_x, lineno++, true_current_out_str); rb->lcd_puts_scroll(resistance_val_x, lineno++, rounded_resistance_out_str); rb->lcd_puts_scroll(resistance_val_x, lineno++, power_rating_out_str); rb->lcd_update(); button_press = rb->button_get(true); switch(button_press) { case PLA_SELECT: break; default: quit = true; backlight_use_settings(); break; } } display->set_viewport(&text_vp); rb->lcd_stop_scroll(); display->set_viewport(&screen_vp); rb->lcd_clear_display(); }
/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { struct pong pong; int game = 1; int blink_timer = 0; int blink_rate = 20; bool blink = true; /* init the struct with some silly values to start with */ pong.ball.x = 20*RES; pong.ball.y = 20*RES; pong.ball.speedx = SPEEDX; pong.ball.speedy = SPEEDY; pong.player[0].xpos = 0; pong.player[0].e_pad = 0; pong.player[0].w_pad = 7; pong.player[1].xpos = LCD_WIDTH-PAD_WIDTH; pong.player[1].e_pad = 0; pong.player[1].w_pad = 40; /* start every game in demo mode */ pong.player[0].iscpu = pong.player[1].iscpu = true; pong.player[0].score = pong.player[1].score = 0; /* lets start at 0 - 0 ;-) */ /* if you don't use the parameter, you can do like this to avoid the compiler warning about it */ (void)parameter; /* Turn off backlight timeout */ backlight_ignore_timeout(); /* Clear screen */ rb->lcd_clear_display(); /* go go go */ while(game > 0) { if (game == 2) { /* Game Paused */ rb->splash(0, "PAUSED"); while(game == 2) game = keys(&pong); /* short circuit */ rb->lcd_clear_display(); } if( pong.player[0].iscpu && pong.player[1].iscpu ) { if(blink_timer<blink_rate) { ++blink_timer; } else { blink_timer=0; blink = !blink; } if(blink==true) { blink_demo(); } else { rb->lcd_clear_display(); } } showscore(&pong); pad(&pong, 0); /* draw left pad */ pad(&pong, 1); /* draw right pad */ ball(&pong); /* move and draw ball */ rb->lcd_update(); game = keys(&pong); /* deal with keys */ } /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED; }
/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { rb->lcd_setfont(FONT_SYSFIXED); rb->lcd_clear_display(); if (!parameter) { rb->splash(HZ*3, "Play gameboy ROM file! (.gb/.gbc)"); return PLUGIN_OK; } if(rb->audio_status()) { audio_bufferbase = audio_bufferpointer = rb->plugin_get_buffer(&audio_buffer_free); plugbuf=true; } else { audio_bufferbase = audio_bufferpointer = rb->plugin_get_audio_buffer(&audio_buffer_free); plugbuf=false; } #if MEMORYSIZE <= 8 && (CONFIG_PLATFORM & PLATFORM_NATIVE) /* loaded as an overlay plugin, protect from overwriting ourselves */ if ((unsigned)(plugin_start_addr - (unsigned char *)audio_bufferbase) < audio_buffer_free) audio_buffer_free = plugin_start_addr - (unsigned char *)audio_bufferbase; #endif setoptions(); shut=0; cleanshut=0; #ifdef HAVE_WHEEL_POSITION rb->wheel_send_events(false); #endif #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256) rb->lcd_set_mode(LCD_MODE_PAL256); #endif /* ignore backlight time out */ backlight_ignore_timeout(); gnuboy_main(parameter); #ifdef HAVE_WHEEL_POSITION rb->wheel_send_events(true); #endif #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256) rb->lcd_set_mode(LCD_MODE_RGB565); #endif backlight_use_settings(); if(!rb->audio_status()) rockboy_pcm_close(); if(shut&&!cleanshut) { rb->splash(HZ/2, errormsg); return PLUGIN_ERROR; } rb->splash(HZ/2, "Closing Rockboy"); savesettings(); cleanup(); return PLUGIN_OK; }
/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { long button; (void)parameter; #ifdef HAVE_LCD_COLOR int cs = 0; bool quit = false; #endif /* HAVE_LCD_COLOR */ #ifdef HAVE_BACKLIGHT_BRIGHTNESS short old_brightness = rb->global_settings->brightness; #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS short old_buttonlight_brightness = rb->global_settings->buttonlight_brightness; #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ #if LCD_DEPTH > 1 unsigned bg_color=rb->lcd_get_background(); rb->lcd_set_backdrop(NULL); rb->lcd_set_background(LCD_WHITE); #endif #ifdef HAVE_BACKLIGHT_BRIGHTNESS rb->backlight_set_brightness(MAX_BRIGHTNESS_SETTING); #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS rb->buttonlight_set_brightness(MAX_BRIGHTNESS_SETTING); #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ #ifdef HAVE_LCD_INVERT #ifdef HAVE_NEGATIVE_LCD rb->lcd_set_invert_display(true); #else rb->lcd_set_invert_display(false); #endif /* HAVE_NEGATIVE_LCD */ #endif /* HAVE_LCD_INVERT */ backlight_force_on(); #ifdef HAVE_BUTTON_LIGHT buttonlight_force_on(); #endif /* HAVE_BUTTON_LIGHT */ #ifdef HAVE_LCD_COLOR do { if(cs < 0) cs = NUM_COLORSETS-1; if(cs >= NUM_COLORSETS) cs = 0; rb->lcd_set_background( LCD_RGBPACK( colorset[cs][0], colorset[cs][1], colorset[cs][2] ) ); rb->lcd_clear_display(); rb->lcd_update(); switch((button = rb->button_get(true))) { case LAMP_RIGHT: #ifdef LAMP_NEXT case LAMP_NEXT: #endif /* LAMP_NEXT */ cs++; break; case LAMP_LEFT: #ifdef LAMP_PREV case LAMP_PREV: #endif /* LAMP_PREV */ cs--; break; case (LAMP_RIGHT|BUTTON_REPEAT): case (LAMP_RIGHT|BUTTON_REL): case (LAMP_LEFT|BUTTON_REPEAT): case (LAMP_LEFT|BUTTON_REL): #ifdef LAMP_NEXT case (LAMP_NEXT|BUTTON_REPEAT): case (LAMP_NEXT|BUTTON_REL): #endif /* LAMP_NEXT */ #ifdef LAMP_PREV case (LAMP_PREV|BUTTON_REPEAT): case (LAMP_PREV|BUTTON_REL): #endif /* LAMP_PREV */ /* eat these... */ break; default: quit = true; } } while (!quit); #else /* HAVE_LCD_COLOR */ rb->lcd_clear_display(); rb->lcd_update(); /* wait */ do { button = rb->button_get(false); if (button && !IS_SYSEVENT(button)) break; rb->yield(); } while (1); #endif /*HAVE_LCD_COLOR */ /* restore */ backlight_use_settings(); #ifdef HAVE_BUTTON_LIGHT buttonlight_use_settings(); #endif /* HAVE_BUTTON_LIGHT */ #ifdef HAVE_LCD_INVERT rb->lcd_set_invert_display(rb->global_settings->invert); #endif /* HAVE_LCD_INVERT */ #ifdef HAVE_BACKLIGHT_BRIGHTNESS rb->backlight_set_brightness(old_brightness); #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS rb->buttonlight_set_brightness(old_buttonlight_brightness); #endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ #if LCD_DEPTH > 1 rb->lcd_set_background(bg_color); #endif return PLUGIN_OK; }
/* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { (void)parameter; int j, i; int thisrocket=0; int start_tick, elapsed_tick; int button; /* set everything up.. no BL timeout, no backdrop, white-text-on-black-background. */ backlight_force_on(); /* backlight control in lib/helper.c */ #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); rb->lcd_set_background(LCD_BLACK); rb->lcd_set_foreground(LCD_WHITE); #endif #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(true); #endif fireworks_menu(); start_tick = *rb->current_tick; while(!quit_plugin) { rb->lcd_clear_display(); /* loop through every possible rocket */ for(j=0; j<MAX_ROCKETS; j++) { /* if the current rocket is actually moving/"alive" then go on and * move/update/explode it */ if(rocket_phase[j] > -1) { #ifdef HAVE_LCD_COLOR /* draw trail, if requested */ if(show_rockets==2) { rb->lcd_set_foreground(LCD_RGBPACK(128,128,128)); rb->lcd_fillrect(rocket_xpos[j], rocket_ypos[j], ROCKET_SIZE, ROCKET_SIZE); rb->lcd_set_foreground(LCD_RGBPACK(64,64,64)); rb->lcd_fillrect(rocket_xpos[j]-rocket_xspeed[j], rocket_ypos[j]+rocket_yspeed[j], ROCKET_SIZE, ROCKET_SIZE); } #endif /* move rocket */ rocket_xpos[j] += rocket_xspeed[j]; rocket_ypos[j] -= rocket_yspeed[j]; #ifdef HAVE_LCD_COLOR rb->lcd_set_foreground(LCD_WHITE); #endif if(show_rockets==2 || show_rockets==1) rb->lcd_fillrect(rocket_xpos[j], rocket_ypos[j], ROCKET_SIZE, ROCKET_SIZE); /* if(rocket isn't "there" yet) keep moving * if(rocket IS there) explode it. */ if(rocket_phase[j] < rocket_targetphase[j]) rocket_phase[j]++; else { rocket_phase[j] = -1; firework_phase[j] = 0; init_explode(rocket_xpos[j], rocket_ypos[j], j, particle_values[particles_per_firework]); } } /* and now onto the fireworks for this particular rocket... */ if(firework_phase[j] > -1) { for(i=0; i<particle_values[particles_per_firework]; i++) { firework_xpoints[j][i] += firework_xspeed[j][i]; firework_ypoints[j][i] += firework_yspeed[j][i]; if(gravity != 0) firework_ypoints[j][i] += firework_phase[j] /gravity_values[gravity]; #ifdef HAVE_LCD_COLOR rb->lcd_set_foreground( firework_darkest_colors[firework_color[j][i]]); rb->lcd_fillrect(firework_xpoints[j][i]-1, firework_ypoints[j][i]-1, FIREWORK_SIZE+2, FIREWORK_SIZE+2); int phase_left = particle_life_values[particle_life] - firework_phase[j]; if(phase_left > 10) rb->lcd_set_foreground( firework_colors[firework_color[j][i]]); else if(phase_left > 7) rb->lcd_set_foreground( firework_dark_colors[firework_color[j][i]]); else if(phase_left > 3) rb->lcd_set_foreground( firework_darker_colors[firework_color[j][i]]); else rb->lcd_set_foreground( firework_darkest_colors[firework_color[j][i]]); #endif rb->lcd_fillrect(firework_xpoints[j][i], firework_ypoints[j][i], FIREWORK_SIZE, FIREWORK_SIZE); /* WIP - currently ugly explosion effect #ifdef HAVE_LCD_COLOR if(firework_phase[j] < 10) { rb->lcd_set_foreground(EXPLOSION_COLOR); rb->lcd_fillrect(rocket_xpos[j]-firework_phase[j], rocket_ypos[j]-firework_phase[j], firework_phase[j]*2, firework_phase[j]*2); } #endif */ } #ifdef HAVE_LCD_COLOR rb->lcd_set_foreground(LCD_WHITE); #endif /* firework at its destination age? * no = keep aging; yes = delete it. */ if(firework_phase[j] < particle_life_values[particle_life]) firework_phase[j]++; else firework_phase[j] = -1; } } /* is autofire on? */ if(autofire_delay != 0) { elapsed_tick = *rb->current_tick - start_tick; if(elapsed_tick > autofire_delay_values[autofire_delay]) { init_rocket(thisrocket); if(++thisrocket == MAX_ROCKETS) thisrocket = 0; start_tick = *rb->current_tick; } } rb->lcd_update(); button = rb->button_get_w_tmo(HZ/fps_values[frames_per_second]); switch(button) { case BTN_MENU: /* back to config menu */ fireworks_menu(); break; case BTN_FIRE: /* fire off rockets manually */ case BTN_FIRE|BUTTON_REPEAT: init_rocket(thisrocket); if(++thisrocket == MAX_ROCKETS) thisrocket=0; break; } } /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); /* backlight control in lib/helper.c */ #ifdef HAVE_ADJUSTABLE_CPU_FREQ rb->cpu_boost(false); #endif return PLUGIN_OK; }