/* * draw_menu - draw menu on screen * * Returns MENU_CANCEL if the user cancelled, or the item number of the * selected item. * */ static void draw_menu(char *title, char **items, size_t num_items) { size_t i; int x, y, w, h, by; /* draw the outline */ gfx_fillRect(0xaf,MENU_X + 1, MENU_Y + 1, MENU_WIDTH, MENU_HEIGHT); // fillrect(0xaf,SHADOW_RECT); gfx_fillRect(0x00,MENU_X, MENU_Y, MENU_WIDTH, MENU_HEIGHT); // fillrect(0x00,MENU_RECT); gfx_drawRect(0xff,MENU_X, MENU_Y, MENU_WIDTH, MENU_HEIGHT); // drawrect(0xff,MENU_RECT); /* calculate x/y */ x = MENU_X + MENU_ITEM_PAD; y = MENU_Y + MENU_ITEM_PAD * 2; getstringsize(title, &w, &h); h += MENU_ITEM_PAD * 2; /* draw menu stipple */ for (i = MENU_Y; i < (size_t) y + h; i += 2) drawline(MENU_X, i, MENU_X + MENU_WIDTH-1, i,0xff); /* clear title rect */ fillrect((OSD_BITMAP1_WIDTH - w) / 2 - 2, y - 2, w + 4, h,0x00); /* draw centered title on screen */ putsxy((OSD_BITMAP1_WIDTH - w)/2, y, title); /* calculate base Y for items */ by = y + h + MENU_ITEM_PAD; /* iterate over each item and draw it on the screen */ for (i = 0; i < num_items; i++) putsxy(x+2, by + h * i, items[i]); }
static void show_reverse_menu(uint8_t item) { menu_close(); gfx_fillRect(0, 8, 128, 65, SSD1306_BLACK); show_actual_reverse(); menu_init(0, 24, 128, 64 - 24, ARRAY_SIZE(reverse_items), reverse_items); _state = SETTING_STATE_REVERSE; }
int dispName_norm(struct menu_item * item,int x,int y,int clear,int selected) { int color; int w = 0; int h = 0; gfx_getStringSize("M", &w, &h); if(item->sub) { current_menu->submenu_str(item->data,tmp); color=current_menu->sub_color; /* => submenu */ } else { current_menu->item_str(item->data,tmp); color=current_menu->txt_color; /* => item */ } CHG_PLANE if(clear) gfx_fillRect(current_menu->bg_color,x, y , current_menu->width-x, h+1); if(selected) gfx_putS(color, current_menu->select_color,x, y, tmp); else gfx_putS(color, current_menu->bg_color,x, y, tmp); RESTORE_PLANE return 1; }
static void show_brightness_menu(uint8_t item) { menu_close(); gfx_fillRect(0, 8, 128, 65, SSD1306_BLACK); show_actual_brightness(); menu_init(0, 24, 128, 64 - 24, ARRAY_SIZE(brightness_items), brightness_items); _state = SETTING_STATE_BRIGHTNESS; }
static void show_control_menu(uint8_t item) { menu_close(); gfx_fillRect(0, 8, 128, 65, SSD1306_BLACK); show_actual_control(); menu_init(0, 24, 128, 64 - 24, ARRAY_SIZE(control_items), control_items); _state = SETTING_STATE_CONTROL; }
static void show_speed_menu(uint8_t item) { menu_close(); gfx_fillRect(0, 8, 128, 65, SSD1306_BLACK); show_actual_speed(); menu_init(0, 24, 128, 64 - 24, ARRAY_SIZE(speed_items), speed_items); _state = SETTING_STATE_SPEED; }
int dispName_icon(struct menu_item * item,int i,int j,int clear_txt,int clear_icon,int selected) { int color; int x,y; int w,h; BITMAP * icon=NULL; x=current_menu->dx+i*(item_width+space_btw_items); y=current_menu->dy+TITLE_OFFSET+j*(item_height+space_btw_items); if(item->sub) { current_menu->submenu_str(item->data,tmp); color=current_menu->sub_color; /* => submenu */ icon=current_menu->getSubIcon(item->data); } else { current_menu->item_str(item->data,tmp); color=current_menu->txt_color; /* => item */ icon=current_menu->getItemIcon(item->data); } CHG_PLANE if(clear_icon) { gfx_fillRect(current_menu->bg_color,x, y , item_width, icon->height); if(icon && icon->width<=item_width && icon->height<=icon_zone_height) gfx_drawBitmap(icon,x+(item_width-icon->width)/2,y+(icon_zone_height-icon->height)/2); } if(clear_txt) { gfx_fillRect(current_menu->bg_color,x, y + icon_zone_height+1, item_width,item_height-(icon_zone_height+1)); } gfx_getStringSize(tmp, &w, &h); if(selected) gfx_putS(color, current_menu->select_color,x+(item_width-w)/2, y+icon_zone_height+1, tmp); else gfx_putS(color, current_menu->bg_color,x+(item_width-w)/2, y+icon_zone_height+1, tmp); RESTORE_PLANE return 1; }
static void show_color_menu(uint8_t item) { if (item == 2) { _state = SETTING_STATE_FIRST_COLOR; } else if (item == 3) { _state = SETTING_STATE_SECOND_COLOR; } else { _state = SETTING_STATE_THIRD_COLOR; } menu_close(); gfx_fillRect(0, 8, 128, 65, SSD1306_BLACK); show_actual_color(); menu_init(0, 24, 128, 64 - 24, ARRAY_SIZE(color_items), color_items); }
void show_actual_control(void) { bool control = isRunning_WS2812FX(); char actual[10] = {0}; if (control) { snprintf(actual, 50, "Now: %s", "ON"); } else { snprintf(actual, 50, "Now: %s", "OFF"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
void show_warning(void) { gfx_fillRect(0, 8, 128, 56, SSD1306_BLACK); gfx_setCursor(0, 8); // We calculate the number of character we can use // we keep that value for scrolling char buffer[MAX_CHAR_UNDER_STATUS_BAR] = {0}; text_index = MAX_CHAR_UNDER_STATUS_BAR; strncpy(buffer, warning_notice, text_index); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(buffer); gfx_update(); }
void show_actual_reverse(void) { bool reverse = getReverse_WS2812FX(); char actual[10] = {0}; if (reverse) { snprintf(actual, 50, "Now: %s", "True"); } else { snprintf(actual, 50, "Now: %s", "False"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
void show_actual_speed(void) { uint16_t speed = getSpeed_WS2812FX(); char actual[50] = {0}; if (speed >= SUPER_SLOW_SPEED) { snprintf(actual, 50, "Now: %s", "Super slow"); } else if (speed >= SLOW_SPEED) { snprintf(actual, 50, "Now: %s", "Slow"); } else if (speed >= MEDIUM_SPEED) { snprintf(actual, 50, "Now: %s", "Medium"); } else if (speed >= FAST_SPEED) { snprintf(actual, 50, "Now: %s", "Fast"); } else { snprintf(actual, 50, "Now: %s", "Super fast"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
void show_actual_brightness(void) { uint8_t brightness = getBrightness_WS2812FX(); char actual[50] = {0}; if (brightness <= SUPER_LOW_BRIGHTNESS) { snprintf(actual, 50, "Now: %s", "Super Low"); } else if (brightness <= LOW_BRIGHTNESS) { snprintf(actual, 50, "Now: %s", "Low"); } else if (brightness <= MEDIUM_BRIGHTNESS) { snprintf(actual, 50, "Now: %s", "Medium"); } else if (brightness <= HIGH_BRIGHTNESS) { snprintf(actual, 50, "Now: %s", "High"); } else { snprintf(actual, 50, "Now: %s", "Max"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
/* * Callback function when the battery status timeout expires */ static void battery_status_timeout_handler(void *p_context) { char msg[256]; gfx_fillRect(0, 8, 128, 56, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); snprintf(msg, sizeof(msg), "Battery status:\n" " Voltage: %04d mV\n" " Charging: %s\n" " USB plugged: %s\n", battery_get_voltage(), battery_is_charging() ? "Yes" : "No", battery_is_usb_plugged() ? "Yes" : "No"); gfx_puts(msg); gfx_update(); }
void scroll_down_warning(bool change_direction) { if (text_index > strlen(warning_notice)) { return; } gfx_fillRect(0, 8, 128, 56, SSD1306_BLACK); gfx_setCursor(0, 8); if (change_direction) { text_index += MAX_CHAR_UNDER_STATUS_BAR; } char buffer[MAX_CHAR_UNDER_STATUS_BAR] = {0}; strncpy(buffer, warning_notice + text_index, MAX_CHAR_UNDER_STATUS_BAR); text_index += MAX_CHAR_UNDER_STATUS_BAR; gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(buffer); gfx_update(); }
void show_actual_color(void) { uint32_t color; if (_state == SETTING_STATE_FIRST_COLOR) { color = getArrayColor_WS2812FX(0); } else if (_state == SETTING_STATE_SECOND_COLOR) { color = getArrayColor_WS2812FX(1); } else { color = getArrayColor_WS2812FX(2); } char actual[50] = {0}; if (color == RED) { snprintf(actual, 50, "Now: %s", "Red"); } else if (color == GREEN) { snprintf(actual, 50, "Now: %s", "Green"); } else if (color == BLUE) { snprintf(actual, 50, "Now: %s", "Blue"); } else if (color == WHITE) { snprintf(actual, 50, "Now: %s", "White"); } else if (color == BLACK) { snprintf(actual, 50, "Now: %s", "Black"); } else if (color == YELLOW) { snprintf(actual, 50, "Now: %s", "Yellow"); } else if (color == CYAN) { snprintf(actual, 50, "Now: %s", "Cyan"); } else if (color == PURPLE) { snprintf(actual, 50, "Now: %s", "Purple"); } else { snprintf(actual, 50, "Now: %s", "Orange"); } gfx_fillRect(12, 20, 128, 65, SSD1306_BLACK); gfx_setCursor(0, 12); gfx_setTextBackgroundColor(SSD1306_WHITE, SSD1306_BLACK); gfx_puts(actual); }
int app_main(int argc,char** argv) { char * rom; /* to use the medios browser you have to define USE_MEDIOS_BROWSER. This completely changes the way the emu works, it mapps button_off to exit the emulator and return to the browser, While exit in the emu ingame menu still completly exits. Cj tell me if you want to do it this way and also let me know if it works for you? */ int i; for(i=0;i<argc;i++) printf("%d:%s\n",i,argv[i]); #ifdef USE_MEDIOS_BROWSER while(1) { osd_setEntirePalette(gui_pal,256); gfx_planeSetSize(BMAP1,LCD_WIDTH,LCD_HEIGHT,8); gfx_planeSetPos(BMAP1,X_OFFSET,Y_OFFSET); iniIcon(); gfx_openGraphics(); clearScreen(COLOR_WHITE); gfx_fontSet(STD6X9); if(argc<2) { ini_file_browser(); rom=browse("/",1); } else { rom = (char *)malloc(MAX_PATH); strcpy(rom,argv[1]); } if (rom=='0') { cleanup(); reload_firmware(); } gfx_openGraphics(); OSD_BITMAP1_ADDRESS = (int)gfx_planeGetBufferOffset(BMAP1); gfx_planeSetSize(BMAP1,160,144,8); gfx_planeSetPos(BMAP1,(LCD_WIDTH-OSD_BITMAP1_WIDTH) + X_OFFSET,(LCD_HEIGHT-OSD_BITMAP1_HEIGHT)/2 + Y_OFFSET); gfx_fillRect(0x00,0,0,160,144); gfx_fontSet(10); vid_init(); pcm_init(); //rom = (char *)malloc(MAX_PATH); printf("Rom name : %s\n",rom); loader_init(rom); emu_reset(); emu_run(); } #endif #ifndef USE_MEDIOS_BROWSER //this uses the avBoy browser and is the default gfx_openGraphics(); OSD_BITMAP1_ADDRESS = (int)gfx_planeGetBufferOffset(BMAP1); gfx_planeSetSize(BMAP1,160,144,8); gfx_planeSetPos(BMAP1,(LCD_WIDTH-OSD_BITMAP1_WIDTH) + X_OFFSET,(LCD_HEIGHT-OSD_BITMAP1_HEIGHT)/2 + Y_OFFSET); gfx_fillRect(0x00,0,0,160,144); gfx_fontSet(10); vid_init(); pcm_init(); rom = (char *)malloc(MAX_PATH); printf("argc = %d, argv = %x\n",argc,argv); if(argc<2) browser(rom); else strcpy(rom,argv[1]); //browser(rom); printf("Rom name : %s (%x,%x)\n",rom,rom,rom+MAX_PATH); loader_init(rom); emu_reset(); emu_run(); #endif printf("before return\n"); return 0; }
static void do_opt2_menu(void) { int mi, num_items,x,y,c=0; bool done = false; /* set a couple of defaults */ num_items = sizeof(opt2_menu) / sizeof(char*); mi = 0; // snprintf((char *)opt2_menu[0], 17, "Overclock SDR %1d", SDRFreq); #ifdef AV3XX snprintf((char *)opt2_menu[1], 17, "Rotate Scr. %1d", RotScreen); snprintf((char *)opt2_menu[0], 17, "Zoom X %s", (ZoomX ? " ON" : "OFF")); #endif snprintf((char *)opt2_menu[OM2_ITEM_OCA], 17, "Overclock ARM %1d", ARMFreq); while (!done) { mi = do_menu(OPT2_MENU_TITLE, (char**) opt2_menu, num_items, mi); switch(mi) { /* case OM2_ITEM_ZX: gfx_planeSetSize(BMAP1,320,288,8); gfx_planeSetPos(BMAP1,0x14,0x12); (*(volatile unsigned short *)(0x30684))+=0x100; break; case OM2_ITEM_ZN: gfx_planeSetSize(BMAP1,160,144,8); gfx_planeSetPos(BMAP1,168,68); break; case OM2_ITEM_OCS: SDRFreq++; snprintf((char *)opt2_menu[0], 17, "Overclock SDR %1d", SDRFreq); (*(volatile unsigned short *)(0x30884))=0x80C0 + (SDRFreq<<4); break; case OM2_ITEM_CSN: SDRFreq=0; snprintf((char *)opt2_menu[0], 17, "Overclock SDR %1d", SDRFreq); (*(volatile unsigned short *)(0x30884))=0x8031; break;*/ #ifdef AV3XX case OM2_ITEM_ZMX: if(!RotScreen) { ZoomX=!ZoomX; if(ZoomX) { gfx_planeSetSize(BMAP1,320,144,8); gfx_planeSetPos(BMAP1, X_OFFSET,(LCD_HEIGHT-OSD_BITMAP1_HEIGHT)/2 + Y_OFFSET); fb.pitch=320; } else { gfx_planeSetSize(BMAP1,160,144,8); gfx_planeSetPos(BMAP1,(LCD_WIDTH-OSD_BITMAP1_WIDTH) + X_OFFSET,(LCD_HEIGHT-OSD_BITMAP1_HEIGHT)/2 + Y_OFFSET); fb.pitch=OSD_BITMAP1_WIDTH; } snprintf((char *)opt2_menu[0], 17, "Zoom X %s", (ZoomX ? " ON" : "OFF")); } break; case OM2_ITEM_ROT: if(!ZoomX) { RotScreen = (RotScreen+1)%3; snprintf((char *)opt2_menu[1], 17, "Rotate Scr. %1d", RotScreen); if(RotScreen==2) { fb.pitch=-1; gfx_planeSetSize(BMAP1,144,160,8); bt_UP = BTMASK_RIGHT; bt_DOWN = BTMASK_LEFT; bt_LEFT = BTMASK_UP; bt_RIGHT = BTMASK_DOWN; bt_A = BTMASK_F2; bt_B = BTMASK_F3; bt_SELECT = BTMASK_F1; MENU_X=2; } else if(RotScreen==1) { fb.pitch=1; gfx_planeSetSize(BMAP1,144,160,8); bt_UP = BTMASK_LEFT; bt_DOWN = BTMASK_RIGHT; bt_LEFT = BTMASK_DOWN; bt_RIGHT = BTMASK_UP; bt_A = BTMASK_F3; bt_B = BTMASK_F2; bt_SELECT = BTMASK_F1; MENU_X=2; } else { fb.pitch=OSD_BITMAP1_WIDTH; gfx_planeSetSize(BMAP1,160,144,8); bt_UP = BTMASK_UP; bt_DOWN = BTMASK_DOWN; bt_LEFT = BTMASK_LEFT; bt_RIGHT = BTMASK_RIGHT; bt_A = BTMASK_F2; bt_B = BTMASK_F1; bt_SELECT = BTMASK_F3; MENU_X=10; } } break; #endif case OM2_ITEM_OCA: ARMFreq++; snprintf((char *)opt2_menu[OM2_ITEM_OCA], 17, "Overclock ARM %1d", ARMFreq); (*(volatile unsigned short *)(0x30880))=0x8080 + (ARMFreq<<4); break; case OM2_ITEM_CAN: ARMFreq=0; snprintf((char *)opt2_menu[OM2_ITEM_OCA], 17, "Overclock ARM %1d", ARMFreq); (*(volatile unsigned short *)(0x30880))=0x8021; break; case OM2_ITEM_PAL: while (btn_readState()); for (y=0;y<144;y+=9) { for (x=0;x<160;x+=10) { gfx_fillRect(c, x, y, 10, 9); c++; } } while (!btn_readState()); break; case MENU_CANCEL: done = true; break; case OM2_ITEM_BACK: done = true; break; } } }
void browser(char * rom) { int x, y, w, h, by; size_t i; int btn, sel_item=0, curr_item, num_items=6, nb=0,pos=0; char title[]="Start..."; char (*items)[17]; char (*list)[MAX_PATH]; bool done = false; struct dirent *romdir; DIR * romd=NULL; items = malloc(MAX_PATH*6); list = malloc(MAX_PATH); romd=opendir("/aoboy/roms"); if(romd) printf("Dir /aoboy/roms/ opened!\n"); else { mkdir("/aoboy/roms",0); if(romd) printf("Dir /aoboy/roms/ created and opened!\n"); else printf("Dir error!\n"); } while((romdir=readdir(romd))!=NULL) { if(!(romdir->attribute & ATTR_DIRECTORY)) { list[nb][0]='\0'; strcat(list[nb],romdir->d_name); nb++; list = realloc(list,MAX_PATH*(nb+1)); } } gfx_fillRect(0xaf,11,9,140,128); gfx_fillRect(0x00,10,8,140,128); gfx_drawRect(0xff,10,8,140,128); x = 10 + 2; y = 8 + 2 * 2; getstringsize(title, &w, &h); h += 2 * 2; for (i = 8; i < (size_t) y + h; i += 2) drawline(10, i, 10 + 139, i,0xff); fillrect((160 - w) / 2 - 2, y - 2, w + 4, h,0x00); putsxy((160 - w)/2, y, title); by = y + h + 2; while(!done) { if(pos > (nb-6)) num_items=nb-pos; else num_items=6; // for(i=0;i<num_items;i++) {items[i][0]='\0'; strcat(items[i],list[i+pos]);} for(i=0;i<num_items;i++) {strncpy(items[i],list[i+pos],16); items[i][16]='\0';} gfx_fillRect(0x00,11,29,138,106); for (i = 0; i < num_items; i++) putsxy(x+2, by + h * i, items[i]); curr_item = -1; select_item(title, curr_item, sel_item); curr_item = sel_item; while (1) { while (btn_readState()); while(!(btn = btn_readState())); if(btn & BTMASK_DOWN) { sel_item = curr_item + 1; if (sel_item >= (int) num_items) { if(pos < (nb-6)) {sel_item=0;pos+=6;break;} else {sel_item = curr_item;} } else { select_item(title, curr_item, sel_item); curr_item = sel_item; } } else if(btn & BTMASK_UP) { sel_item = curr_item - 1; if (sel_item < 0) { if(pos > 0) {sel_item=5;pos-=6;break;} else {sel_item = curr_item;} } else { select_item(title, curr_item, sel_item); curr_item = sel_item; } } else if(btn & BTMASK_RIGHT) { done = true; break; } else if(btn & BTMASK_LEFT) { } } } rom[0]='\0'; strcat(rom,"/AOBOY/ROMS/"); strcat(rom,list[curr_item+pos]); strcat(rom,"\0"); closedir(romd); free(items); free(list); return; }
void nsec_show_led_settings(void) { gfx_fillRect(0, 8, 128, 65, SSD1306_BLACK); menu_init(0, 12, 128, 64 - 12, ARRAY_SIZE(settings_items), settings_items); nsec_controls_add_handler(setting_handle_buttons); _state = SETTING_STATE_MENU; }