X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ui%2Fncurses%2Fps3-cui.c;h=d9a66fad74a94ca140d0a916452f5063c61ef0e5;hb=5c682a67a63c45f39b5f656513d17080d8fc5394;hp=96a6e72090c16eb646a912a3c5dea65800c5b87e;hpb=aea1d55d7e09f4544f96ccc54196c674d52420e8;p=petitboot diff --git a/ui/ncurses/ps3-cui.c b/ui/ncurses/ps3-cui.c index 96a6e72..d9a66fa 100644 --- a/ui/ncurses/ps3-cui.c +++ b/ui/ncurses/ps3-cui.c @@ -53,7 +53,7 @@ static void print_usage(void) print_version(); printf( "Usage: pb-cui [-h, --help] [-l, --log log-file] [-r, --reset-defaults]\n" -" [-V, --version]\n"); +" [-t, --timeout] [-V, --version]\n"); } /** @@ -70,6 +70,7 @@ struct opts { enum opt_value show_help; const char *log_file; enum opt_value reset_defaults; + enum opt_value use_timeout; enum opt_value show_version; }; @@ -83,10 +84,11 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) {"help", no_argument, NULL, 'h'}, {"log", required_argument, NULL, 'l'}, {"reset-defaults", no_argument, NULL, 'r'}, + {"timeout", no_argument, NULL, 't'}, {"version", no_argument, NULL, 'V'}, { NULL, 0, NULL, 0}, }; - static const char short_options[] = "hl:rV"; + static const char short_options[] = "hl:trV"; static const struct opts default_values = { .log_file = "pb-cui.log", }; @@ -107,6 +109,9 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) case 'l': opts->log_file = optarg; break; + case 't': + opts->use_timeout = opt_yes; + break; case 'r': opts->reset_defaults = opt_yes; break; @@ -119,7 +124,7 @@ static int opts_parse(struct opts *opts, int argc, char *argv[]) } } - return 0; + return optind != argc; } /** @@ -151,6 +156,83 @@ static struct ps3_cui *ps3_from_item(struct pmenu_item *item) return ps3_from_cui(cui_from_item(item)); } +/** + * ps3_sixaxis_map - Map a Linux joystick event to an ncurses key code. + * + */ + +static int ps3_sixaxis_map(const struct js_event *e) +{ +#if 0 + static const int axis_map[] = { + 0, /* 0 Left thumb X */ + 0, /* 1 Left thumb Y */ + 0, /* 2 Right thumb X */ + 0, /* 3 Right thumb Y */ + 0, /* 4 nothing */ + 0, /* 5 nothing */ + 0, /* 6 nothing */ + 0, /* 7 nothing */ + 0, /* 8 Dpad Up */ + 0, /* 9 Dpad Right */ + 0, /* 10 Dpad Down */ + 0, /* 11 Dpad Left */ + 0, /* 12 L2 */ + 0, /* 13 R2 */ + 0, /* 14 L1 */ + 0, /* 15 R1 */ + 0, /* 16 Triangle */ + 0, /* 17 Circle */ + 0, /* 18 Cross */ + 0, /* 19 Square */ + 0, /* 20 nothing */ + 0, /* 21 nothing */ + 0, /* 22 nothing */ + 0, /* 23 nothing */ + 0, /* 24 nothing */ + 0, /* 25 nothing */ + 0, /* 26 nothing */ + 0, /* 27 nothing */ + }; +#endif + static const int button_map[] = { + 0, /* 0 Select */ + 0, /* 1 L3 */ + 0, /* 2 R3 */ + 0, /* 3 Start */ + KEY_UP, /* 4 Dpad Up */ + 0, /* 5 Dpad Right */ + KEY_DOWN, /* 6 Dpad Down */ + 0, /* 7 Dpad Left */ + KEY_UP, /* 8 L2 */ + KEY_DOWN, /* 9 R2 */ + KEY_HOME, /* 10 L1 */ + KEY_END, /* 11 R1 */ + 0, /* 12 Triangle */ + 0, /* 13 Circle */ + 13, /* 14 Cross */ + 0, /* 15 Square */ + 0, /* 16 PS Button */ + 0, /* 17 nothing */ + 0, /* 18 nothing */ + }; + + if (!e->value) + return 0; + + if (e->type == JS_EVENT_BUTTON + && e->number < sizeof(button_map) / sizeof(button_map[0])) + return button_map[e->number]; + +#if 0 + if (e->type == JS_EVENT_AXIS + && e->number < sizeof(axis_map) / sizeof(axis_map[0])) + return axis_map[e->number]; +#endif + + return 0; +} + /** * ps3_set_mode - Set video mode helper. * @@ -188,22 +270,51 @@ static int ps3_svm_cb(struct pmenu_item *item) * ps3_kexec_cb - The kexec callback. * * Writes config data to PS3 flash then calls pb_run_kexec(). + * Adds a video mode arg to the kernel command line if needed. */ static int ps3_kexec_cb(struct cui *cui, struct cui_opt_data *cod) { struct ps3_cui *ps3 = ps3_from_cui(cui); + int result; + int altered_args; + char *orig_args; - pb_log("%s: %s:%s\n", __func__, cod->dev->name, cod->opt->name); + pb_log("%s: %s\n", __func__, cod->name); assert(ps3->cui->current == &ps3->cui->main->scr); - if (cui->default_item != cod->opt_hash || ps3->dirty_values) { + /* Save values to flash if needed */ + + if ((cod->opt_hash && cod->opt_hash != cui->default_item) + || ps3->dirty_values) { ps3->values.default_item = cod->opt_hash; ps3_flash_set_values(&ps3->values); } - return pb_run_kexec(cod->kd); + /* Add a default kernel video mode. */ + + if (!cod->kd->args) { + altered_args = 1; + orig_args = NULL; + cod->kd->args = talloc_asprintf(NULL, "video=ps3fb:mode:%u", + (unsigned int)ps3->values.video_mode); + } else if (!strstr(cod->kd->args, "video=")) { + altered_args = 1; + orig_args = cod->kd->args; + cod->kd->args = talloc_asprintf(NULL, "%s video=ps3fb:mode:%u", + orig_args, (unsigned int)ps3->values.video_mode); + } else + altered_args = 0; + + result = pb_run_kexec(cod->kd); + + if (altered_args) { + talloc_free(cod->kd->args); + cod->kd->args = orig_args; + } + + return result; } /** @@ -311,8 +422,7 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui) int result; struct pmenu *m; struct pmenu_item *i; - static const char *const bgo[] = - {"/usr/sbin/ps3-boot-game-os-NOT", NULL}; + static const char *const bgo[] = {"/usr/sbin/ps3-boot-game-os", NULL}; m = pmenu_init(ps3_cui->cui, 3, cui_on_exit); @@ -322,22 +432,26 @@ static struct pmenu *ps3_mm_init(struct ps3_cui *ps3_cui) } m->hot_key = ps3_hot_key; + m->on_open = cui_on_open; + +#if defined(DEBUG) + m->scr.frame.title = talloc_strdup(m, + "Petitboot PS3 (" PACKAGE_VERSION ")"); +#else m->scr.frame.title = talloc_strdup(m, "Petitboot PS3"); +#endif m->scr.frame.help = talloc_strdup(m, - "ESC=exit, Enter=accept, E,e=edit"); + "ESC=exit, Enter=accept, e=edit, o=open"); m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); - i = pmenu_item_init(m, 0, "Boot GameOS", - "Reboot the PS3 into the GameOS"); + i = pmenu_item_init(m, 0, "Boot GameOS"); i->on_execute = cui_run_cmd; i->data = (void *)bgo; - i = pmenu_item_init(m, 1, "Set Video Mode", - "Display a video mode selection menu"); + i = pmenu_item_init(m, 1, "Set Video Mode"); i->on_execute = ps3_mm_to_svm_cb; - i = pmenu_item_init(m, 2, "Exit to Shell", - "Exit petitboot and return to a shell prompt"); + i = pmenu_item_init(m, 2, "Exit to Shell"); i->on_execute = pmenu_exit_cb; result = pmenu_setup(m); @@ -380,53 +494,51 @@ static struct pmenu *ps3_svm_init(struct ps3_cui *ps3_cui) m->scr.frame.title = talloc_strdup(m, "Select PS3 Video Mode"); m->scr.frame.help = talloc_strdup(m, "ESC=exit, Enter=accept"); - i = pmenu_item_init(m, 0, "auto detect", - "Auto detect the best HDMI video mode"); + i = pmenu_item_init(m, 0, "auto detect"); i->on_execute = ps3_svm_cb; i->data = (void *)0; - i = pmenu_item_init(m, 1, "480i (576 x 384)", NULL); + i = pmenu_item_init(m, 1, "480i (576 x 384)"); i->on_execute = ps3_svm_cb; i->data = (void *)1; - i = pmenu_item_init(m, 2, "480p (576 x 384)", NULL); + i = pmenu_item_init(m, 2, "480p (576 x 384)"); i->on_execute = ps3_svm_cb; i->data = (void *)2; - i = pmenu_item_init(m, 3, "576i (576 x 460)", NULL); + i = pmenu_item_init(m, 3, "576i (576 x 460)"); i->on_execute = ps3_svm_cb; i->data = (void *)6; - i = pmenu_item_init(m, 4, "576p (576 x 460)", NULL); + i = pmenu_item_init(m, 4, "576p (576 x 460)"); i->on_execute = ps3_svm_cb; i->data = (void *)7; - i = pmenu_item_init(m, 5, "720p (1124 x 644)", NULL); + i = pmenu_item_init(m, 5, "720p (1124 x 644)"); i->on_execute = ps3_svm_cb; i->data = (void *)3; - i = pmenu_item_init(m, 6, "1080i (1688 x 964)", NULL); + i = pmenu_item_init(m, 6, "1080i (1688 x 964)"); i->on_execute = ps3_svm_cb; i->data = (void *)4; - i = pmenu_item_init(m, 7, "1080p (1688 x 964)", NULL); + i = pmenu_item_init(m, 7, "1080p (1688 x 964)"); i->on_execute = ps3_svm_cb; i->data = (void *)5; - i = pmenu_item_init(m, 8, "wxga (1280 x 768)", NULL); + i = pmenu_item_init(m, 8, "wxga (1280 x 768)"); i->on_execute = ps3_svm_cb; i->data = (void *)11; - i = pmenu_item_init(m, 9, "sxga (1280 x 1024)", NULL); + i = pmenu_item_init(m, 9, "sxga (1280 x 1024)"); i->on_execute = ps3_svm_cb; i->data = (void *)12; - i = pmenu_item_init(m, 10, "wuxga (1920 x 1200)", NULL); + i = pmenu_item_init(m, 10, "wuxga (1920 x 1200)"); i->on_execute = ps3_svm_cb; i->data = (void *)13; - i = pmenu_item_init(m, 11, "Return", - "Return to the main menu"); + i = pmenu_item_init(m, 11, "Return"); i->on_execute = ps3_svm_to_mm_cb; result = pmenu_setup(m); @@ -543,7 +655,7 @@ int main(int argc, char *argv[]) if (!result && (ps3.values.video_mode != (uint16_t)mode)) ps3_set_video_mode(ps3.values.video_mode); - ps3.cui = cui_init(&ps3, ps3_kexec_cb); + ps3.cui = cui_init(&ps3, ps3_kexec_cb, ps3_sixaxis_map); if (!ps3.cui) return EXIT_FAILURE; @@ -551,7 +663,8 @@ int main(int argc, char *argv[]) ps3.mm = ps3_mm_init(&ps3); ps3.svm = ps3_svm_init(&ps3); - if (ps3.values.timeout == ps3_timeout_forever) + if (opts.use_timeout != opt_yes + || ps3.values.timeout == ps3_timeout_forever) ui_timer_disable(&ps3.cui->timer); else { ps3.cui->timer.update_display = ps3_timer_update;