Index: uisimulator/sdl/button.c =================================================================== --- uisimulator/sdl/button.c (revision 22649) +++ uisimulator/sdl/button.c (working copy) @@ -1250,6 +1250,11 @@ return btn; } +void button_set(int newbtn) +{ + btn = newbtn; +} + #ifdef HAVE_TOUCHSCREEN extern bool debug_wps; Index: uisimulator/sdl/button_defines.h =================================================================== --- uisimulator/sdl/button_defines.h (revision 0) +++ uisimulator/sdl/button_defines.h (revision 0) @@ -0,0 +1,199 @@ +/* + * Generated with the following command: + * for b in $(grep -o "BUTTON[_A-Z]*" button.c |sort |uniq); do + * printf "#ifdef %s\n { \"%s\", %s },\n#endif\n" $b $b $b >> button_defines.h + * done + * + * Plus some manual editing + */ +struct buttonpairs { + char *define; + int value; +}; + +static struct buttonpairs buttons[] = { + + /* USB connection events */ +#ifdef SYS_USB_CONNECTED + { "SYS_USB_CONNECTED", SYS_USB_CONNECTED }, +#endif +#ifdef SYS_USB_DISCONNECTED + { "SYS_USB_DISCONNECTED", SYS_USB_DISCONNECTED }, +#endif + + /* Button events */ +#ifdef BUTTON_A + { "BUTTON_A", BUTTON_A }, +#endif +#ifdef BUTTON_BACK + { "BUTTON_BACK", BUTTON_BACK }, +#endif +#ifdef BUTTON_BOTTOMLEFT + { "BUTTON_BOTTOMLEFT", BUTTON_BOTTOMLEFT }, +#endif +#ifdef BUTTON_BOTTOMMIDDLE + { "BUTTON_BOTTOMMIDDLE", BUTTON_BOTTOMMIDDLE }, +#endif +#ifdef BUTTON_BOTTOMRIGHT + { "BUTTON_BOTTOMRIGHT", BUTTON_BOTTOMRIGHT }, +#endif +#ifdef BUTTON_CENTER + { "BUTTON_CENTER", BUTTON_CENTER }, +#endif +#ifdef BUTTON_CUSTOM + { "BUTTON_CUSTOM", BUTTON_CUSTOM }, +#endif +#ifdef BUTTON_DISPLAY + { "BUTTON_DISPLAY", BUTTON_DISPLAY }, +#endif +#ifdef BUTTON_DOWN + { "BUTTON_DOWN", BUTTON_DOWN }, +#endif +#ifdef BUTTON_EQ + { "BUTTON_EQ", BUTTON_EQ }, +#endif +#ifdef BUTTON_F + { "BUTTON_F", BUTTON_F }, +#endif +#ifdef BUTTON_FF + { "BUTTON_FF", BUTTON_FF }, +#endif +#ifdef BUTTON_FFWD + { "BUTTON_FFWD", BUTTON_FFWD }, +#endif +#ifdef BUTTON_HOLD + { "BUTTON_HOLD", BUTTON_HOLD }, +#endif +#ifdef BUTTON_HOME + { "BUTTON_HOME", BUTTON_HOME }, +#endif +#ifdef BUTTON_LEFT + { "BUTTON_LEFT", BUTTON_LEFT }, +#endif +#ifdef BUTTON_MENU + { "BUTTON_MENU", BUTTON_MENU }, +#endif +#ifdef BUTTON_MIDLEFT + { "BUTTON_MIDLEFT", BUTTON_MIDLEFT }, +#endif +#ifdef BUTTON_MIDRIGHT + { "BUTTON_MIDRIGHT", BUTTON_MIDRIGHT }, +#endif +#ifdef BUTTON_MINUS + { "BUTTON_MINUS", BUTTON_MINUS }, +#endif +#ifdef BUTTON_MODE + { "BUTTON_MODE", BUTTON_MODE }, +#endif +#ifdef BUTTON_NEXT + { "BUTTON_NEXT", BUTTON_NEXT }, +#endif +#ifdef BUTTON_NONE + { "BUTTON_NONE", BUTTON_NONE }, +#endif +#ifdef BUTTON_OFF + { "BUTTON_OFF", BUTTON_OFF }, +#endif +#ifdef BUTTON_ON + { "BUTTON_ON", BUTTON_ON }, +#endif +#ifdef BUTTON_PLAY + { "BUTTON_PLAY", BUTTON_PLAY }, +#endif +#ifdef BUTTON_PLAYLIST + { "BUTTON_PLAYLIST", BUTTON_PLAYLIST }, +#endif +#ifdef BUTTON_PLUS + { "BUTTON_PLUS", BUTTON_PLUS }, +#endif +#ifdef BUTTON_POWER + { "BUTTON_POWER", BUTTON_POWER }, +#endif +#ifdef BUTTON_PREV + { "BUTTON_PREV", BUTTON_PREV }, +#endif +#ifdef BUTTON_RC_DOWN + { "BUTTON_RC_DOWN", BUTTON_RC_DOWN }, +#endif +#ifdef BUTTON_RC_FF + { "BUTTON_RC_FF", BUTTON_RC_FF }, +#endif +#ifdef BUTTON_RC_HEART + { "BUTTON_RC_HEART", BUTTON_RC_HEART }, +#endif +#ifdef BUTTON_RC_MODE + { "BUTTON_RC_MODE", BUTTON_RC_MODE }, +#endif +#ifdef BUTTON_RC_PLAY + { "BUTTON_RC_PLAY", BUTTON_RC_PLAY }, +#endif +#ifdef BUTTON_RC_REW + { "BUTTON_RC_REW", BUTTON_RC_REW }, +#endif +#ifdef BUTTON_RC_VOL_DOWN + { "BUTTON_RC_VOL_DOWN", BUTTON_RC_VOL_DOWN }, +#endif +#ifdef BUTTON_RC_VOL_UP + { "BUTTON_RC_VOL_UP", BUTTON_RC_VOL_UP }, +#endif +#ifdef BUTTON_REC + { "BUTTON_REC", BUTTON_REC }, +#endif +#ifdef BUTTON_REMOTE + { "BUTTON_REMOTE", BUTTON_REMOTE }, +#endif +#ifdef BUTTON_REW + { "BUTTON_REW", BUTTON_REW }, +#endif +#ifdef BUTTON_RIGHT + { "BUTTON_RIGHT", BUTTON_RIGHT }, +#endif +#ifdef BUTTON_SCROLL_BACK + { "BUTTON_SCROLL_BACK", BUTTON_SCROLL_BACK }, +#endif +#ifdef BUTTON_SCROLL_DOWN + { "BUTTON_SCROLL_DOWN", BUTTON_SCROLL_DOWN }, +#endif +#ifdef BUTTON_SCROLL_FWD + { "BUTTON_SCROLL_FWD", BUTTON_SCROLL_FWD }, +#endif +#ifdef BUTTON_SCROLL_UP + { "BUTTON_SCROLL_UP", BUTTON_SCROLL_UP }, +#endif +#ifdef BUTTON_SELECT + { "BUTTON_SELECT", BUTTON_SELECT }, +#endif +#ifdef BUTTON_STOP + { "BUTTON_STOP", BUTTON_STOP }, +#endif +#ifdef BUTTON_TOPLEFT + { "BUTTON_TOPLEFT", BUTTON_TOPLEFT }, +#endif +#ifdef BUTTON_TOPMIDDLE + { "BUTTON_TOPMIDDLE", BUTTON_TOPMIDDLE }, +#endif +#ifdef BUTTON_TOPRIGHT + { "BUTTON_TOPRIGHT", BUTTON_TOPRIGHT }, +#endif +#ifdef BUTTON_TOUCHSCREEN + { "BUTTON_TOUCHSCREEN", BUTTON_TOUCHSCREEN }, +#endif +#ifdef BUTTON_UP + { "BUTTON_UP", BUTTON_UP }, +#endif +#ifdef BUTTON_VIEW + { "BUTTON_VIEW", BUTTON_VIEW }, +#endif +#ifdef BUTTON_VOLDOWN + { "BUTTON_VOLDOWN", BUTTON_VOLDOWN }, +#endif +#ifdef BUTTON_VOL_DOWN + { "BUTTON_VOL_DOWN", BUTTON_VOL_DOWN }, +#endif +#ifdef BUTTON_VOLUP + { "BUTTON_VOLUP", BUTTON_VOLUP }, +#endif +#ifdef BUTTON_VOL_UP + { "BUTTON_VOL_UP", BUTTON_VOL_UP }, +#endif +}; Index: uisimulator/sdl/uisdl.c =================================================================== --- uisimulator/sdl/uisdl.c (revision 22649) +++ uisimulator/sdl/uisdl.c (working copy) @@ -41,6 +41,15 @@ #include "SDL_mutex.h" #include "SDL_thread.h" +#include "button_defines.h" +#include "sim_tasks.h" +#include "backlight.h" +#include +#define PIPEBUFFER 255 +FILE *cmdpipe = NULL; +void cmdpipe_loop(void); +void button_set(int newbtn); + /* extern functions */ extern void new_key(int key); @@ -102,6 +111,77 @@ } } +void cmdpipe_loop(void) +{ + char line[PIPEBUFFER + 1]; + char *argument = NULL; + int i, button_num; + + button_num = sizeof(buttons)/sizeof(struct buttonpairs); + + if (queue_empty(&button_queue)) { + /* + * Only attempt to read from the pipe if the queue is ready to accept + * input + */ + if (fgets(line, PIPEBUFFER, cmdpipe) != NULL) { + line[strlen(line) - 1] = 0; + //* + argument = line; + while(*argument++ != 0) { + if (*argument == ' ') { + *argument = 0; + } + else if (*argument == 0) { + break; + } + } + //*/ + + if (strcmp(line, "SCREENSHOT") == 0) { + sim_enter_irq_handler(); + backlight_on(); + sim_trigger_screendump(); + sim_exit_irq_handler(); + } + else if (strcmp(line, "STARTPLUGIN") == 0 ) { + sim_start_plugin(argument); + } + for (i = 0; i < button_num; i++) + { + if (strcmp(line, buttons[i].define) == 0) { + /* + * This is not "real" button handling. We simply post key + * events directly into the queue as we get them and force + * the backlight on. + * Furthermore, we put the pressed key in the button status + */ + sim_enter_irq_handler(); + backlight_on(); + + if (strcmp(argument, "REL") == 0) { + printf("Button: %s|BUTTON_REL (%d)\n", buttons[i].define, buttons[i].value|BUTTON_REL); + button_set(BUTTON_NONE); + queue_post(&button_queue, buttons[i].value|BUTTON_REL, 0); + } + else if (strcmp(argument, "REPEAT") == 0) { + printf("Button: %s|BUTTON_REPEAT (%d)\n", buttons[i].define, buttons[i].value|BUTTON_REPEAT); + button_set(buttons[i].value); + queue_post(&button_queue, buttons[i].value|BUTTON_REPEAT, 0); + } + else { + printf("Button: %s (%d)\n", buttons[i].define, buttons[i].value); + button_set(buttons[i].value); + queue_post(&button_queue, buttons[i].value, 0); + } + + sim_exit_irq_handler(); + } + } + } + } +} + bool gui_startup(void) { SDL_Surface *picture_surface; @@ -177,6 +257,8 @@ int main(int argc, char *argv[]) { + int i, button_num; + if (argc >= 1) { int x; @@ -225,17 +307,39 @@ printf("Root directory: %s\n", sim_root_dir); } } + else if (!strcmp("--cmdpipe", argv[x])) + { + x++; + if (x < argc) + { + printf("Command pipe: %s\n", argv[x]); + printf("Opening pipe..\n"); + cmdpipe = fopen(argv[x], "r"); + printf("Pipe opened\n"); + if (cmdpipe == NULL) + { + printf("Couldn't open file: %s\n", argv[x]); + exit(1); + } + + int fd = fileno(cmdpipe); + int flags = fcntl(fd, F_GETFL, 0); + flags |= O_NONBLOCK; + fcntl(fd, F_SETFL, flags); + } + } else { printf("rockboxui\n"); printf("Arguments:\n"); - printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n"); - printf(" --debugwps \t Print advanced WPS debug info\n"); + printf(" --debugaudio \t\t Write raw PCM data to audiodebug.raw\n"); + printf(" --debugwps \t\t Print advanced WPS debug info\n"); printf(" --nobackground \t Disable the background image\n"); - printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n"); - printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n"); - printf(" --alarm \t Simulate a wake-up on alarm\n"); - printf(" --root [DIR]\t Set root directory\n"); + printf(" --old_lcd \t\t [Player] simulate old playermodel (ROM version<4.51)\n"); + printf(" --zoom [VAL]\t\t Window zoom (will disable backgrounds)\n"); + printf(" --alarm \t\t Simulate a wake-up on alarm\n"); + printf(" --cmdpipe [FILE] \t Read commands from a named pipe (not keyboard)\n"); + printf(" --root [DIR]\t\t Set root directory\n"); exit(0); } } @@ -261,8 +365,25 @@ return -1; } + if (cmdpipe != NULL) { + button_num = sizeof(buttons)/sizeof(struct buttonpairs); + + printf("Available commands:\n"); + printf(" SCREENSHOT\n"); + printf(" STARTPLUGIN path\n"); + for (i = 0; i < button_num; i++) + { + printf(" %s [REL|REPEAT]\n", buttons[i].define); + } + + tick_add_task(cmdpipe_loop); + } + gui_message_loop(); + if (cmdpipe != NULL) { + fclose(cmdpipe); + } return gui_shutdown(); } Index: uisimulator/common/sim_tasks.h =================================================================== --- uisimulator/common/sim_tasks.h (revision 22649) +++ uisimulator/common/sim_tasks.h (working copy) @@ -23,3 +23,4 @@ void sim_tasks_init(void); void sim_trigger_screendump(void); +void sim_start_plugin(char*); Index: uisimulator/common/sim_tasks.c =================================================================== --- uisimulator/common/sim_tasks.c (revision 22649) +++ uisimulator/common/sim_tasks.c (working copy) @@ -26,6 +26,8 @@ #include "screendump.h" #include "thread.h" +int plugin_load(const char*, const void*); + static void sim_thread(void); static long sim_thread_stack[DEFAULT_STACK_SIZE/sizeof(long)]; /* stack isn't actually used in the sim */ @@ -35,6 +37,7 @@ /* possible events for the sim thread */ enum { SIM_SCREENDUMP, + SIM_STARTPLUGIN, }; void sim_thread(void) @@ -52,6 +55,10 @@ remote_screen_dump(); #endif break; + case SIM_STARTPLUGIN: + printf("EVENT START PLUGIN %s\n", ev.data); + plugin_load(ev.data, NULL); + break; } } } @@ -68,3 +75,8 @@ { queue_post(&sim_queue, SIM_SCREENDUMP, 0); } + +void sim_start_plugin(char *path) +{ + queue_post(&sim_queue, SIM_STARTPLUGIN, path); +}