From: notaz Date: Tue, 30 Dec 2008 22:25:38 +0000 (+0000) Subject: more input wip X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=595491c49949ad41ffe2c343f1484ae913b6de5f;p=libpicofe.git more input wip git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@624 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/common/input.c b/common/input.c index 77d9f3a..48e3c0a 100644 --- a/common/input.c +++ b/common/input.c @@ -23,8 +23,11 @@ static int in_dev_count = 0; static int in_bind_count(int drv_id) { int count = 0; - if (drv_id == IN_DRVID_EVDEV) + switch (drv_id) { + case IN_DRVID_EVDEV: count = in_evdev_bind_count(); + break; + } if (count <= 0) printf("input: failed to get bind count for drv %d\n", drv_id); @@ -48,8 +51,11 @@ static int *in_alloc_binds(int drv_id) static void in_free(in_dev_t *dev) { if (dev->probed) { - if (dev->drv_id == IN_DRVID_EVDEV) + switch (dev->drv_id) { + case IN_DRVID_EVDEV: in_evdev_free(dev->drv_data); + break; + } } dev->probed = 0; dev->drv_data = NULL; @@ -157,37 +163,73 @@ int in_update(void) for (i = 0; i < in_dev_count; i++) { if (in_devices[i].probed && in_devices[i].binds != NULL) { - if (in_devices[i].drv_id == IN_DRVID_EVDEV) + switch (in_devices[i].drv_id) { + case IN_DRVID_EVDEV: result |= in_evdev_update(in_devices[i].drv_data, in_devices[i].binds); + break; + } } } return result; } +static void **in_collect_drvdata(int drv_id, int *count) +{ + static void *data[IN_MAX_DEVS]; + int i; + + for (*count = i = 0; i < in_dev_count; i++) { + if (in_devices[i].drv_id == drv_id && in_devices[i].probed) + data[(*count)++] = in_devices[i].drv_data; + } + + return data; +} + +void in_set_blocking(int is_blocking) +{ + int i; + + for (i = 0; i < in_dev_count; i++) { + if (in_devices[i].probed) { + switch (in_devices[i].drv_id) { + case IN_DRVID_EVDEV: + in_evdev_set_blocking(in_devices[i].drv_data, is_blocking); + break; + } + } + } +} + /* - * update with wait for a press, return bitfield of BTN_* + * update with wait for a press, return keycode * only can use 1 drv here.. */ -int in_update_menu(void) +int in_update_keycode(int *dev_id, int *is_down) { int result = 0; #ifdef IN_EVDEV - void *data[IN_MAX_DEVS]; - int i, count = 0; - - for (i = 0; i < in_dev_count; i++) { - if (in_devices[i].probed) - data[count++] = in_devices[i].drv_data; - } + void **data; + int i, id = 0, count = 0; + data = in_collect_drvdata(IN_DRVID_EVDEV, &count); if (count == 0) { /* don't deadlock, fail */ printf("input: failed to find devices to read\n"); exit(1); } - result = in_evdev_update_menu(data, count); + result = in_evdev_update_keycode(data, count, &id, is_down); + + if (dev_id != NULL) { + for (i = id; i < in_dev_count; i++) { + if (in_devices[i].drv_data == data[id]) { + *dev_id = i; + break; + } + } + } #else #error no menu read handlers #endif @@ -195,6 +237,47 @@ int in_update_menu(void) return result; } +/* + * same as above, only return bitfield of BTN_* + */ +int in_update_menu(void) +{ + static int keys_active = 0; + int keys_old = keys_active; + + while (1) + { + int code, is_down = 0; + code = in_update_keycode(NULL, &is_down); +#ifdef IN_EVDEV + code = in_evdev_menu_translate(code); +#endif + if (code == 0) continue; + + if (is_down) + keys_active |= code; + else + keys_active &= ~code; + + if (keys_old != keys_active) + break; + } + + return keys_active; +} + +const char *in_get_key_name(int dev_id, int keycode) +{ + if (dev_id < 0 || dev_id >= IN_MAX_DEVS) + return "Unkn0"; + switch (in_devices[dev_id].drv_id) { + case IN_DRVID_EVDEV: + return in_evdev_get_key_name(keycode); + } + + return "Unkn1"; +} + void in_init(void) { memset(in_devices, 0, sizeof(in_devices)); @@ -208,11 +291,20 @@ int main(void) in_init(); in_probe(); + in_set_blocking(1); + +#if 1 + while (1) { + int dev = 0, down; + ret = in_update_keycode(&dev, &down); + printf("#%i: %i %i (%s)\n", dev, down, ret, in_get_key_name(dev, ret)); + } +#else while (1) { ret = in_update_menu(); printf("%08x\n", ret); - sleep(1); } +#endif return 0; } diff --git a/common/input.h b/common/input.h index 0110e98..5f0fa17 100644 --- a/common/input.h +++ b/common/input.h @@ -8,3 +8,7 @@ void in_register(const char *nname, int drv_id, void *drv_data); void in_init(void); void in_probe(void); int in_update(void); +void in_set_blocking(int is_blocking); +int in_update_keycode(int *dev_id, int *is_down); +int in_update_menu(void); +const char *in_get_key_name(int dev_id, int keycode); diff --git a/linux/in_evdev.c b/linux/in_evdev.c index 9f0e231..fe4a886 100644 --- a/linux/in_evdev.c +++ b/linux/in_evdev.c @@ -15,6 +15,93 @@ #define BIT(x) (keybits[(x)/sizeof(keybits[0])/8] & \ (1 << ((x) & (sizeof(keybits[0])*8-1)))) +static const char *in_evdev_keys[KEY_MAX + 1] = { + [0 ... KEY_MAX] = NULL, + [KEY_RESERVED] = "Reserved", [KEY_ESC] = "Esc", + [KEY_1] = "1", [KEY_2] = "2", + [KEY_3] = "3", [KEY_4] = "4", + [KEY_5] = "5", [KEY_6] = "6", + [KEY_7] = "7", [KEY_8] = "8", + [KEY_9] = "9", [KEY_0] = "0", + [KEY_MINUS] = "Minus", [KEY_EQUAL] = "Equal", + [KEY_BACKSPACE] = "Backspace", [KEY_TAB] = "Tab", + [KEY_Q] = "Q", [KEY_W] = "W", + [KEY_E] = "E", [KEY_R] = "R", + [KEY_T] = "T", [KEY_Y] = "Y", + [KEY_U] = "U", [KEY_I] = "I", + [KEY_O] = "O", [KEY_P] = "P", + [KEY_LEFTBRACE] = "LeftBrace", [KEY_RIGHTBRACE] = "RightBrace", + [KEY_ENTER] = "Enter", [KEY_LEFTCTRL] = "LeftControl", + [KEY_A] = "A", [KEY_S] = "S", + [KEY_D] = "D", [KEY_F] = "F", + [KEY_G] = "G", [KEY_H] = "H", + [KEY_J] = "J", [KEY_K] = "K", + [KEY_L] = "L", [KEY_SEMICOLON] = "Semicolon", + [KEY_APOSTROPHE] = "Apostrophe", [KEY_GRAVE] = "Grave", + [KEY_LEFTSHIFT] = "LeftShift", [KEY_BACKSLASH] = "BackSlash", + [KEY_Z] = "Z", [KEY_X] = "X", + [KEY_C] = "C", [KEY_V] = "V", + [KEY_B] = "B", [KEY_N] = "N", + [KEY_M] = "M", [KEY_COMMA] = "Comma", + [KEY_DOT] = "Dot", [KEY_SLASH] = "Slash", + [KEY_RIGHTSHIFT] = "RightShift", [KEY_KPASTERISK] = "KPAsterisk", + [KEY_LEFTALT] = "LeftAlt", [KEY_SPACE] = "Space", + [KEY_CAPSLOCK] = "CapsLock", [KEY_F1] = "F1", + [KEY_F2] = "F2", [KEY_F3] = "F3", + [KEY_F4] = "F4", [KEY_F5] = "F5", + [KEY_F6] = "F6", [KEY_F7] = "F7", + [KEY_F8] = "F8", [KEY_F9] = "F9", + [KEY_F10] = "F10", [KEY_NUMLOCK] = "NumLock", + [KEY_SCROLLLOCK] = "ScrollLock", [KEY_KP7] = "KP7", + [KEY_KP8] = "KP8", [KEY_KP9] = "KP9", + [KEY_KPMINUS] = "KPMinus", [KEY_KP4] = "KP4", + [KEY_KP5] = "KP5", [KEY_KP6] = "KP6", + [KEY_KPPLUS] = "KPPlus", [KEY_KP1] = "KP1", + [KEY_KP2] = "KP2", [KEY_KP3] = "KP3", + [KEY_KP0] = "KP0", [KEY_KPDOT] = "KPDot", + [KEY_ZENKAKUHANKAKU] = "Zenkaku/Hankaku", [KEY_102ND] = "102nd", + [KEY_F11] = "F11", [KEY_F12] = "F12", + [KEY_KPJPCOMMA] = "KPJpComma", [KEY_KPENTER] = "KPEnter", + [KEY_RIGHTCTRL] = "RightCtrl", [KEY_KPSLASH] = "KPSlash", + [KEY_SYSRQ] = "SysRq", [KEY_RIGHTALT] = "RightAlt", + [KEY_LINEFEED] = "LineFeed", [KEY_HOME] = "Home", + [KEY_UP] = "Up", [KEY_PAGEUP] = "PageUp", + [KEY_LEFT] = "Left", [KEY_RIGHT] = "Right", + [KEY_END] = "End", [KEY_DOWN] = "Down", + [KEY_PAGEDOWN] = "PageDown", [KEY_INSERT] = "Insert", + [KEY_DELETE] = "Delete", [KEY_MACRO] = "Macro", + [KEY_HELP] = "Help", [KEY_MENU] = "Menu", + [KEY_COFFEE] = "Coffee", [KEY_DIRECTION] = "Direction", + [BTN_0] = "Btn0", [BTN_1] = "Btn1", + [BTN_2] = "Btn2", [BTN_3] = "Btn3", + [BTN_4] = "Btn4", [BTN_5] = "Btn5", + [BTN_6] = "Btn6", [BTN_7] = "Btn7", + [BTN_8] = "Btn8", [BTN_9] = "Btn9", + [BTN_LEFT] = "LeftBtn", [BTN_RIGHT] = "RightBtn", + [BTN_MIDDLE] = "MiddleBtn", [BTN_SIDE] = "SideBtn", + [BTN_EXTRA] = "ExtraBtn", [BTN_FORWARD] = "ForwardBtn", + [BTN_BACK] = "BackBtn", [BTN_TASK] = "TaskBtn", + [BTN_TRIGGER] = "Trigger", [BTN_THUMB] = "ThumbBtn", + [BTN_THUMB2] = "ThumbBtn2", [BTN_TOP] = "TopBtn", + [BTN_TOP2] = "TopBtn2", [BTN_PINKIE] = "PinkieBtn", + [BTN_BASE] = "BaseBtn", [BTN_BASE2] = "BaseBtn2", + [BTN_BASE3] = "BaseBtn3", [BTN_BASE4] = "BaseBtn4", + [BTN_BASE5] = "BaseBtn5", [BTN_BASE6] = "BaseBtn6", + [BTN_DEAD] = "BtnDead", [BTN_A] = "BtnA", + [BTN_B] = "BtnB", [BTN_C] = "BtnC", + [BTN_X] = "BtnX", [BTN_Y] = "BtnY", + [BTN_Z] = "BtnZ", [BTN_TL] = "BtnTL", + [BTN_TR] = "BtnTR", [BTN_TL2] = "BtnTL2", + [BTN_TR2] = "BtnTR2", [BTN_SELECT] = "BtnSelect", + [BTN_START] = "BtnStart", [BTN_MODE] = "BtnMode", + [BTN_THUMBL] = "BtnThumbL", [BTN_THUMBR] = "BtnThumbR", + [BTN_TOUCH] = "Touch", [BTN_STYLUS] = "Stylus", + [BTN_STYLUS2] = "Stylus2", [BTN_TOOL_DOUBLETAP] = "Tool Doubletap", + [BTN_TOOL_TRIPLETAP] = "Tool Tripletap", [BTN_GEAR_DOWN] = "WheelBtn", + [BTN_GEAR_UP] = "Gear up", [KEY_OK] = "Ok", +}; + + int in_evdev_probe(void) { int i; @@ -120,37 +207,41 @@ int in_evdev_update(void *drv_data, int *binds) return result; } -int in_evdev_update_menu(void **data, int count) +void in_evdev_set_blocking(void *data, int y) { - const int *fds = (const int *)data; - static int result = 0; - int i, ret, fdmax = -1; - int oldresult = result; long flags; + int ret; - /* switch to blocking mode */ - for (i = 0; i < count; i++) { - if (fds[i] > fdmax) fdmax = fds[i]; - - flags = (long)fcntl(fds[i], F_GETFL); - if ((int)flags == -1) { - perror("in_evdev: F_GETFL fcntl failed"); - continue; - } - flags &= ~O_NONBLOCK; - ret = fcntl(fds[i], F_SETFL, flags); - if (ret == -1) - perror("in_evdev: F_SETFL fcntl failed"); + flags = (long)fcntl((int)data, F_GETFL); + if ((int)flags == -1) { + perror("in_evdev: F_GETFL fcntl failed"); + return; } + if (y) + flags &= ~O_NONBLOCK; + else + flags |= O_NONBLOCK; + ret = fcntl((int)data, F_SETFL, flags); + if (ret == -1) + perror("in_evdev: F_SETFL fcntl failed"); +} + +int in_evdev_update_keycode(void **data, int dcount, int *which, int *is_down) +{ + const int *fds = (const int *)data; + int i, fdmax = -1; + + for (i = 0; i < dcount; i++) + if (fds[i] > fdmax) fdmax = fds[i]; while (1) { struct input_event ev[64]; - int fd, rd; + int ret, fd = -1, rd; fd_set fdset; FD_ZERO(&fdset); - for (i = 0; i < count; i++) + for (i = 0; i < dcount; i++) FD_SET(fds[i], &fdset); ret = select(fdmax + 1, &fdset, NULL, NULL, NULL); @@ -161,9 +252,9 @@ int in_evdev_update_menu(void **data, int count) return 0; } - for (i = 0; i < count; i++) + for (i = 0; i < dcount; i++) if (FD_ISSET(fds[i], &fdset)) - fd = fds[i]; + *which = i, fd = fds[i]; rd = read(fd, ev, sizeof(ev[0]) * 64); if (rd < (int) sizeof(ev[0])) { @@ -172,46 +263,40 @@ int in_evdev_update_menu(void **data, int count) return 0; } - #define mapkey(o,k) \ - case o: \ - if (ev[i].value) result |= k; \ - else result &= ~k; \ - break for (i = 0; i < rd / sizeof(ev[0]); i++) { if (ev[i].type != EV_KEY || ev[i].value < 0 || ev[i].value > 1) continue; - switch (ev[i].code) { - /* keyboards */ - mapkey(KEY_UP, PBTN_UP); - mapkey(KEY_DOWN, PBTN_DOWN); - mapkey(KEY_LEFT, PBTN_LEFT); - mapkey(KEY_RIGHT, PBTN_RIGHT); - mapkey(KEY_ENTER, PBTN_EAST); - mapkey(KEY_ESC, PBTN_SOUTH); - } + if (is_down) + *is_down = ev[i].value; + return ev[i].code; } - #undef mapkey - - if (oldresult != result) break; } +} - /* switch back to non-blocking mode */ - for (i = 0; i < count; i++) { - if (fds[i] > fdmax) fdmax = fds[i]; - - flags = (long)fcntl(fds[i], F_GETFL); - if ((int)flags == -1) { - perror("in_evdev: F_GETFL fcntl failed"); - continue; - } - flags |= O_NONBLOCK; - ret = fcntl(fds[i], F_SETFL, flags); - if (ret == -1) - perror("in_evdev: F_SETFL fcntl failed"); +int in_evdev_menu_translate(int keycode) +{ + switch (keycode) { + /* keyboards */ + case KEY_UP: return PBTN_UP; + case KEY_DOWN: return PBTN_DOWN; + case KEY_LEFT: return PBTN_LEFT; + case KEY_RIGHT: return PBTN_RIGHT; + case KEY_ENTER: return PBTN_EAST; + case KEY_ESC: return PBTN_SOUTH; + default: return 0; } +} - return result; +const char *in_evdev_get_key_name(int keycode) +{ + const char *name = NULL; + if (keycode >= 0 && keycode < KEY_MAX) + name = in_evdev_keys[keycode]; + if (name == NULL) + name = "Unkn"; + + return name; } diff --git a/linux/in_evdev.h b/linux/in_evdev.h index 8bd1b99..a7a7925 100644 --- a/linux/in_evdev.h +++ b/linux/in_evdev.h @@ -5,6 +5,9 @@ int in_evdev_probe(void); void in_evdev_free(void *drv_data); int in_evdev_bind_count(void); int in_evdev_update(void *drv_data, int *binds); +void in_evdev_set_blocking(void *data, int y); +int in_evdev_menu_translate(int keycode); +const char *in_evdev_get_key_name(int keycode); #else @@ -12,8 +15,11 @@ int in_evdev_update(void *drv_data, int *binds); #define in_evdev_free(x) #define in_evdev_bind_count() 0 #define in_evdev_update(x,y) 0 +#define in_evdev_set_blocking(x,y) +#define in_evdev_menu_translate 0 +#define in_evdev_get_key_name "Unkn" #endif -int in_evdev_update_menu(void **data, int count); +int in_evdev_update_keycode(void **data, int count, int *which, int *is_down); diff --git a/pandora/emu.c b/pandora/emu.c index f12bac6..0b55405 100644 --- a/pandora/emu.c +++ b/pandora/emu.c @@ -102,18 +102,6 @@ void emu_Init(void) } -static void scaling_update(void) -{ - PicoOpt &= ~0x4100; - switch (currentConfig.scaling) { - default: break; // off - case 1: // hw hor - case 2: PicoOpt |= 0x0100; break; // hw hor+vert - case 3: PicoOpt |= 0x4000; break; // sw hor - } -} - - void emu_Deinit(void) { // save SRAM @@ -814,7 +802,6 @@ void emu_Loop(void) // make sure we are in correct mode vidResetMode(); - scaling_update(); Pico.m.dirtyPal = 1; oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc; emu_findKeyBindCombos();