From a406686f4a7e28c86d1b3c7287312ea3597f0439 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sun, 19 May 2019 02:44:28 +0800 Subject: [PATCH] Wiimote calibration (F10 in OSD). --- input.cpp | 53 +++++++++++++++++++++++++++++++++++++- input.h | 3 +++ menu.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ menu.h | 2 ++ 4 files changed, 133 insertions(+), 1 deletion(-) diff --git a/input.cpp b/input.cpp index 5ee2083..0f1d7d0 100644 --- a/input.cpp +++ b/input.cpp @@ -998,6 +998,8 @@ typedef struct uint8_t has_kbdmap; uint8_t kbdmap[256]; + uint16_t guncal[4]; + int accx, accy; int quirk; @@ -1242,6 +1244,24 @@ void finish_map_setting(int dismiss) } } +void input_lightgun_cal(uint16_t *cal) +{ + FileSaveConfig("wiimote_cal.cfg", cal, 4 * sizeof(uint16_t)); + for (int i = 0; i < NUMDEV; i++) + { + if (input[i].quirk == QUIRK_WIIMOTE) memcpy(input[i].guncal, cal, sizeof(input[i].guncal)); + } +} + +int input_has_lightgun() +{ + for (int i = 0; i < NUMDEV; i++) + { + if (input[i].quirk == QUIRK_WIIMOTE) return 1; + } + return 0; +} + uint16_t get_map_vid() { return (mapping && mapping_dev >= 0) ? input[mapping_dev].vid : 0; @@ -2330,6 +2350,11 @@ int input_test(int getchar) else { input[n].quirk = QUIRK_WIIMOTE; + input[n].guncal[0] = 0; + input[n].guncal[1] = 767; + input[n].guncal[2] = 1; + input[n].guncal[3] = 1023; + FileLoadConfig("wiimote_cal.cfg", input[n].guncal, 4 * sizeof(uint16_t)); } } @@ -2465,7 +2490,6 @@ int input_test(int getchar) input[dev].lightgun = 0; if (absinfo.maximum == 1023 || absinfo.maximum == 767) { - if (user_io_osd_is_visible()) continue; if (ev.code == 16) { ev.value = absinfo.maximum - ev.value; @@ -2597,6 +2621,33 @@ int input_test(int getchar) } } + if (ev.type == EV_ABS && input[i].quirk == QUIRK_WIIMOTE && input[dev].lightgun) + { + menu_lightgun_cb(ev.type, ev.code, ev.value); + + // don't pass IR tracking to OSD + if (user_io_osd_is_visible()) continue; + + if (!ev.code) + { + absinfo.minimum = input[i].guncal[2]; + absinfo.maximum = input[i].guncal[3]; + } + else + { + absinfo.minimum = input[i].guncal[0]; + absinfo.maximum = input[i].guncal[1]; + } + } + + if (ev.type == EV_KEY && user_io_osd_is_visible()) + { + if (input[i].quirk == QUIRK_WIIMOTE) + { + if (menu_lightgun_cb(ev.type, ev.code, ev.value)) continue; + } + } + if(!noabs) input_cb(&ev, &absinfo, i); //sumulate digital directions from analog diff --git a/input.h b/input.h index b835f93..1c201db 100644 --- a/input.h +++ b/input.h @@ -52,4 +52,7 @@ uint32_t get_amiga_code(uint16_t key); uint32_t get_atari_code(uint16_t key); uint32_t get_archie_code(uint16_t key); +int input_has_lightgun(); +void input_lightgun_cal(uint16_t *cal); + #endif diff --git a/menu.cpp b/menu.cpp index d11e506..9682ec0 100644 --- a/menu.cpp +++ b/menu.cpp @@ -111,6 +111,9 @@ enum MENU MENU_BTPAIR, MENU_WMPAIR, MENU_WMPAIR1, + MENU_LGCAL, + MENU_LGCAL1, + MENU_LGCAL2, MENU_CHEATS1, MENU_CHEATS2, @@ -734,6 +737,12 @@ const char* get_rbf_name_bootcore(char *str) static int joymap_first = 0; +static int wm_x = 0; +static int wm_y = 0; +static int wm_ok = 0; +static int wm_side = 0; +static uint16_t wm_pos[4] = {}; + void HandleUI(void) { switch (user_io_core_type()) @@ -816,6 +825,10 @@ void HandleUI(void) { menustate = MENU_WMPAIR; } + else if(input_has_lightgun()) + { + menustate = MENU_LGCAL; + } break; // Within the menu the esc key acts as the menu key. problem: @@ -3816,6 +3829,49 @@ void HandleUI(void) if (CheckTimer(menu_timer)) menustate = MENU_NONE1; break; + case MENU_LGCAL: + helptext = 0; + OsdSetTitle("Wiimote Calibration", 0); + for (int i = 0; i < OsdGetSize(); i++) OsdWrite(i); + OsdWrite(9, " Point Wiimote to the edge"); + OsdWrite(10, " of screen and press"); + OsdWrite(11, " the button B to confirm"); + OsdWrite(OsdGetSize() - 1, " Cancel", menusub == 0, 0); + wm_ok = 0; + wm_side = 0; + memset(wm_pos, 0, sizeof(wm_pos)); + menustate = MENU_LGCAL1; + menusub = 0; + break; + + case MENU_LGCAL1: + if (wm_side < 4) wm_pos[wm_side] = (wm_side < 2) ? wm_y : wm_x; + sprintf(s, " %c%04d%c", (wm_side == 0) ? 17 : 32, (wm_side == 0) ? wm_y : wm_pos[0], (wm_side == 0) ? 16 : 32); + OsdWrite(0, s); + sprintf(s, "%c%04d%c %c%04d%c", (wm_side == 2) ? 17 : 32, (wm_side == 2) ? wm_x : wm_pos[2], (wm_side == 2) ? 16 : 32, + (wm_side == 3) ? 17 : 32, (wm_side == 3) ? wm_x : wm_pos[3], (wm_side == 3) ? 16 : 32); + OsdWrite(7, s); + sprintf(s, " %c%04d%c", (wm_side == 1) ? 17 : 32, (wm_side == 1) ? wm_y : wm_pos[1], (wm_side == 1) ? 16 : 32); + OsdWrite(13, s); + if (menu || select) menustate = MENU_NONE1; + + if (wm_ok == 1) + { + wm_ok = 0; + wm_side++; + } + + if (wm_ok == 2) + { + wm_ok = 0; + if (wm_side == 4) + { + input_lightgun_cal(wm_pos); + menustate = MENU_NONE1; + } + } + break; + case MENU_SCRIPTS_PRE: OsdSetTitle("Warning!!!", 0); helptext = 0; @@ -4378,3 +4434,23 @@ void menu_bt_pair() { menustate = MENU_BTPAIR; } + +int menu_lightgun_cb(uint16_t type, uint16_t code, int value) +{ + if (type == EV_ABS) + { + if (code == 0 && value) wm_x = value; + if (code == 1 && value != 1023) wm_y = value; + } + + if (type == EV_KEY) + { + if (code == 0x131 && menustate == MENU_LGCAL1) + { + if (value == 1) wm_ok = 1; + if (value == 0) wm_ok = 2; + return 1; + } + } + return 0; +} diff --git a/menu.h b/menu.h index 2b8f250..3cec841 100644 --- a/menu.h +++ b/menu.h @@ -30,4 +30,6 @@ extern int joy_bcount; void open_joystick_setup(); void menu_bt_pair(); +int menu_lightgun_cb(uint16_t type, uint16_t code, int value); + #endif