From 7fcc325d8cc5b246467735304e76f3f786104959 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sat, 7 Mar 2020 05:35:19 +0800 Subject: [PATCH] Long press of USER button in Menu core launches the joystick button definition. Short press of USER button skips the button in definition. --- file_io.cpp | 31 +++++++--------- file_io.h | 5 +-- input.cpp | 51 +++++++++++++++++++++++-- input.h | 1 + menu.cpp | 105 ++++++++++++++++++++++++++++++++++++++++------------ user_io.cpp | 1 + 6 files changed, 148 insertions(+), 46 deletions(-) diff --git a/file_io.cpp b/file_io.cpp index 81456aa..851a54f 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -633,19 +633,12 @@ int FileSave(const char *name, void *pBuffer, int size) return ret; } -int FileSaveConfig(const char *name, void *pBuffer, int size) +int FileDelete(const char *name) { - char path[256] = { CONFIG_DIR"/" }; - strcat(path, name); - return FileSave(path, pBuffer, size); -} + if (name[0] != '/') sprintf(full_path, "%s/%s", getRootDir(), name); + else strcpy(full_path, name); -int FileSaveJoymap(const char *name, void *pBuffer, int size) -{ - char path[256] = { CONFIG_DIR"/inputs/" }; - FileCreatePath(path); - strcat(path, name); - return FileSave(path, pBuffer, size); + return !unlink(name); } int FileLoad(const char *name, void *pBuffer, int size) @@ -667,14 +660,18 @@ int FileLoadConfig(const char *name, void *pBuffer, int size) return FileLoad(path, pBuffer, size); } -int FileLoadJoymap(const char *name, void *pBuffer, int size) +int FileSaveConfig(const char *name, void *pBuffer, int size) { - char path[256] = { CONFIG_DIR"/inputs/" }; + char path[256] = { CONFIG_DIR"/" }; strcat(path, name); - int ret = FileLoad(path, pBuffer, size); - if (!ret) - return FileLoadConfig(name, pBuffer, size); - return ret; + return FileSave(path, pBuffer, size); +} + +int FileDeleteConfig(const char *name) +{ + char path[256] = { CONFIG_DIR"/" }; + strcat(path, name); + return FileDelete(path); } int FileExists(const char *name) diff --git a/file_io.h b/file_io.h index 853d036..997ad78 100644 --- a/file_io.h +++ b/file_io.h @@ -91,14 +91,13 @@ void FileGenerateScreenshotName(const char *name, char *out_name, int buflen); int FileSave(const char *name, void *pBuffer, int size); int FileLoad(const char *name, void *pBuffer, int size); // supply pBuffer = 0 to get the file size without loading +int FileDelete(const char *name); //save/load from config dir #define CONFIG_DIR "config" int FileSaveConfig(const char *name, void *pBuffer, int size); int FileLoadConfig(const char *name, void *pBuffer, int size); // supply pBuffer = 0 to get the file size without loading -int FileSaveJoymap(const char *name, void *pBuffer, int size); -int FileLoadJoymap(const char *name, void *pBuffer, int size); // supply pBuffer = 0 to get the file size without loading - +int FileDeleteConfig(const char *name); void AdjustDirectory(char *path); int ScanDirectory(char* path, int mode, const char *extension, int options, const char *prefix = NULL); diff --git a/input.cpp b/input.cpp index 2280e7b..b262034 100644 --- a/input.cpp +++ b/input.cpp @@ -1177,6 +1177,35 @@ int toggle_kbdled(int mask) return state; } +#define JOYMAP_DIR CONFIG_DIR"/inputs/" + +static int load_map(const char *name, void *pBuffer, int size) +{ + char path[256] = { JOYMAP_DIR }; + strcat(path, name); + int ret = FileLoad(path, pBuffer, size); + if (!ret) return FileLoadConfig(name, pBuffer, size); + return ret; +} + +static void delete_map(const char *name) +{ + char path[256] = { JOYMAP_DIR }; + FileCreatePath(path); + strcat(path, name); + FileDelete(name); + FileDelete(path); +} + +static int save_map(const char *name, void *pBuffer, int size) +{ + char path[256] = { JOYMAP_DIR }; + FileCreatePath(path); + strcat(path, name); + FileDelete(name); + return FileSave(path, pBuffer, size); +} + static int mapping = 0; static int mapping_button; static int mapping_dev = -1; @@ -1255,6 +1284,7 @@ void finish_map_setting(int dismiss) if (mapping_type == 2) { if (dismiss) input[mapping_dev].has_kbdmap = 0; + else if (dismiss == 2) FileDeleteConfig(get_kbdmap_name(mapping_dev)); else FileSaveConfig(get_kbdmap_name(mapping_dev), &input[mapping_dev].kbdmap, sizeof(input[mapping_dev].kbdmap)); } else if (mapping_type == 3) @@ -1265,7 +1295,8 @@ void finish_map_setting(int dismiss) { for (int i = 0; i < NUMDEV; i++) input[i].has_map = 0; - if (!dismiss) FileSaveJoymap(get_map_name(mapping_dev, 0), &input[mapping_dev].map, sizeof(input[mapping_dev].map)); + if (!dismiss) save_map(get_map_name(mapping_dev, 0), &input[mapping_dev].map, sizeof(input[mapping_dev].map)); + if (dismiss == 2) delete_map(get_map_name(mapping_dev, 0)); if (is_menu_core()) input[mapping_dev].has_mmap = 0; } } @@ -1774,7 +1805,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int { if (input[dev].quirk != QUIRK_PDSP) { - if (!FileLoadJoymap(get_map_name(dev, 1), &input[dev].mmap, sizeof(input[dev].mmap))) + if (!load_map(get_map_name(dev, 1), &input[dev].mmap, sizeof(input[dev].mmap))) { memset(input[dev].mmap, 0, sizeof(input[dev].mmap)); input[dev].has_mmap++; @@ -1791,7 +1822,7 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int memset(input[dev].map, 0, sizeof(input[dev].map)); input[dev].map[SYS_BTN_A] = 0x120; } - else if (!FileLoadJoymap(get_map_name(dev, 0), &input[dev].map, sizeof(input[dev].map))) + else if (!load_map(get_map_name(dev, 0), &input[dev].map, sizeof(input[dev].map))) { memset(input[dev].map, 0, sizeof(input[dev].map)); if (!is_menu_core()) @@ -2605,6 +2636,20 @@ static void input_cb(struct input_event *ev, struct input_absinfo *absinfo, int } } +void send_map_cmd(int key) +{ + if (mapping && mapping_dev >= 0) + { + input_event ev; + ev.type = EV_KEY; + ev.code = key; + ev.value = 1; + input_cb(&ev, 0, mapping_dev); + ev.value = 0; + input_cb(&ev, 0, mapping_dev); + } +} + #define CMD_FIFO "/dev/MiSTer_cmd" #define LED_MONITOR "/sys/class/leds/hps_led0/brightness_hw_changed" diff --git a/input.h b/input.h index f4fb6f9..bb94f9c 100644 --- a/input.h +++ b/input.h @@ -88,6 +88,7 @@ void finish_map_setting(int dismiss); uint16_t get_map_vid(); uint16_t get_map_pid(); int has_default_map(); +void send_map_cmd(int key); uint32_t get_key_mod(); uint32_t get_ps2_code(uint16_t key); diff --git a/menu.cpp b/menu.cpp index 09a6597..5f5d579 100644 --- a/menu.cpp +++ b/menu.cpp @@ -103,11 +103,14 @@ enum MENU MENU_CORE_FILE_CANCELED, MENU_ERROR, MENU_INFO, + MENU_JOYSYSMAP, MENU_JOYDIGMAP, MENU_JOYDIGMAP1, MENU_JOYDIGMAP2, MENU_JOYDIGMAP3, MENU_JOYDIGMAP4, + MENU_JOYRESET, + MENU_JOYRESET1, MENU_JOYKBDMAP, MENU_JOYKBDMAP1, MENU_KBDMAP, @@ -512,6 +515,42 @@ static uint32_t menu_key_get(void) if (!but) longpress_consumed = 0; last_but = but; } + + if (!c) + { + static unsigned long longpress = 0, longpress_consumed = 0; + static unsigned char last_but = 0; + unsigned char but = user_io_user_button(); + + if (user_io_osd_is_visible()) + { + if (but && !last_but) longpress = GetTimer(1500); + if (but && CheckTimer(longpress) && !longpress_consumed) + { + longpress_consumed = 1; + if (is_menu_core()) + { + if (menustate == MENU_SYSTEM2 || menustate == MENU_FILE_SELECT2) menustate = MENU_JOYSYSMAP; + } + else if (get_map_vid() || get_map_pid()) + { + menustate = MENU_JOYRESET; + } + } + + if (!but && last_but && !longpress_consumed) + { + if (get_map_vid() || get_map_pid()) + { + send_map_cmd(KEY_SPACE); + } + } + } + + if (!but) longpress_consumed = 0; + last_but = but; + } + return(c); } @@ -2331,6 +2370,22 @@ void HandleUI(void) } break; + case MENU_JOYRESET: + OsdWrite(3); + OsdWrite(4, " Reset to default"); + OsdWrite(5); + menustate = MENU_JOYRESET1; + break; + + case MENU_JOYRESET1: + if (!user_io_user_button()) + { + finish_map_setting(2); + menustate = MENU_8BIT_SYSTEM1; + menusub = 1; + } + break; + case MENU_JOYDIGMAP: helptext = 0; menumask = 1; @@ -4418,29 +4473,7 @@ void HandleUI(void) menusub = 0; break; case 2: - strcpy(joy_bnames[SYS_BTN_A - DPAD_NAMES], "A"); - strcpy(joy_bnames[SYS_BTN_B - DPAD_NAMES], "B"); - strcpy(joy_bnames[SYS_BTN_X - DPAD_NAMES], "X"); - strcpy(joy_bnames[SYS_BTN_Y - DPAD_NAMES], "Y"); - strcpy(joy_bnames[SYS_BTN_L - DPAD_NAMES], "L"); - strcpy(joy_bnames[SYS_BTN_R - DPAD_NAMES], "R"); - strcpy(joy_bnames[SYS_BTN_SELECT - DPAD_NAMES], "Select"); - strcpy(joy_bnames[SYS_BTN_START - DPAD_NAMES], "Start"); - strcpy(joy_bnames[SYS_MS_RIGHT - DPAD_NAMES], "Mouse Move RIGHT"); - strcpy(joy_bnames[SYS_MS_LEFT - DPAD_NAMES], "Mouse Move LEFT"); - strcpy(joy_bnames[SYS_MS_DOWN - DPAD_NAMES], "Mouse Move DOWN"); - strcpy(joy_bnames[SYS_MS_UP - DPAD_NAMES], "Mouse Move UP"); - strcpy(joy_bnames[SYS_MS_BTN_L - DPAD_NAMES], "Mouse Btn Left"); - strcpy(joy_bnames[SYS_MS_BTN_R - DPAD_NAMES], "Mouse Btn Right"); - strcpy(joy_bnames[SYS_MS_BTN_M - DPAD_NAMES], "Mouse Btn Middle"); - strcpy(joy_bnames[SYS_MS_BTN_EMU - DPAD_NAMES], "Mouse Emu/Sniper"); - strcpy(joy_bnames[SYS_BTN_OSD_KTGL - DPAD_NAMES], "Menu"); - strcpy(joy_bnames[SYS_BTN_CNT_OK - DPAD_NAMES], "Menu: OK"); - strcpy(joy_bnames[SYS_BTN_CNT_ESC - DPAD_NAMES], "Menu: Back"); - joy_bcount = 20+1; //buttons + OSD/KTGL button - start_map_setting(joy_bcount + 6); // + dpad + Analog X/Y - menustate = MENU_JOYDIGMAP; - menusub = 0; + menustate = MENU_JOYSYSMAP; break; case 3: { @@ -4473,6 +4506,32 @@ void HandleUI(void) printSysInfo(); break; + case MENU_JOYSYSMAP: + strcpy(joy_bnames[SYS_BTN_A - DPAD_NAMES], "A"); + strcpy(joy_bnames[SYS_BTN_B - DPAD_NAMES], "B"); + strcpy(joy_bnames[SYS_BTN_X - DPAD_NAMES], "X"); + strcpy(joy_bnames[SYS_BTN_Y - DPAD_NAMES], "Y"); + strcpy(joy_bnames[SYS_BTN_L - DPAD_NAMES], "L"); + strcpy(joy_bnames[SYS_BTN_R - DPAD_NAMES], "R"); + strcpy(joy_bnames[SYS_BTN_SELECT - DPAD_NAMES], "Select"); + strcpy(joy_bnames[SYS_BTN_START - DPAD_NAMES], "Start"); + strcpy(joy_bnames[SYS_MS_RIGHT - DPAD_NAMES], "Mouse Move RIGHT"); + strcpy(joy_bnames[SYS_MS_LEFT - DPAD_NAMES], "Mouse Move LEFT"); + strcpy(joy_bnames[SYS_MS_DOWN - DPAD_NAMES], "Mouse Move DOWN"); + strcpy(joy_bnames[SYS_MS_UP - DPAD_NAMES], "Mouse Move UP"); + strcpy(joy_bnames[SYS_MS_BTN_L - DPAD_NAMES], "Mouse Btn Left"); + strcpy(joy_bnames[SYS_MS_BTN_R - DPAD_NAMES], "Mouse Btn Right"); + strcpy(joy_bnames[SYS_MS_BTN_M - DPAD_NAMES], "Mouse Btn Middle"); + strcpy(joy_bnames[SYS_MS_BTN_EMU - DPAD_NAMES], "Mouse Emu/Sniper"); + strcpy(joy_bnames[SYS_BTN_OSD_KTGL - DPAD_NAMES], "Menu"); + strcpy(joy_bnames[SYS_BTN_CNT_OK - DPAD_NAMES], "Menu: OK"); + strcpy(joy_bnames[SYS_BTN_CNT_ESC - DPAD_NAMES], "Menu: Back"); + joy_bcount = 20 + 1; //buttons + OSD/KTGL button + start_map_setting(joy_bcount + 6); // + dpad + Analog X/Y + menustate = MENU_JOYDIGMAP; + menusub = 0; + break; + case MENU_WMPAIR: { OsdSetTitle("Wiimote", 0); diff --git a/user_io.cpp b/user_io.cpp index bbce09e..7590bf2 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -2065,6 +2065,7 @@ void user_io_send_buttons(char force) } key_map = map; + if (user_io_osd_is_visible()) map &= ~BUTTON2; spi_uio_cmd16(UIO_BUT_SW, map); printf("sending keymap: %X\n", map); if ((key_map & BUTTON2) && is_x86_core()) x86_init();