From: notaz Date: Thu, 27 Oct 2011 23:31:57 +0000 (+0300) Subject: frontend: add touchscreen-as-buttons input code X-Git-Tag: r11~14 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faf2b2aae80c811f778f7cfa9a320dd7ade01dac;p=pcsx_rearmed.git frontend: add touchscreen-as-buttons input code intended for Caanoo/Wiz --- diff --git a/Makefile b/Makefile index 32e54011..22f6652c 100644 --- a/Makefile +++ b/Makefile @@ -131,7 +131,7 @@ OBJS += frontend/plat_omap.o OBJS += frontend/plat_pandora.o else ifeq "$(PLATFORM)" "caanoo" -OBJS += frontend/plat_pollux.o frontend/blit320.o +OBJS += frontend/plat_pollux.o frontend/in_tsbutton.o frontend/blit320.o OBJS += frontend/warm/warm.o else OBJS += frontend/plat_dummy.o diff --git a/frontend/in_tsbutton.c b/frontend/in_tsbutton.c new file mode 100644 index 00000000..4e2cef02 --- /dev/null +++ b/frontend/in_tsbutton.c @@ -0,0 +1,147 @@ +/* + * (C) Gražvydas "notaz" Ignotas, 2011 + * + * This work is licensed under the terms of any of these licenses + * (at your option): + * - GNU GPL, version 2 or later. + * - GNU LGPL, version 2.1 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include + +#include "common/input.h" +#include "in_tsbutton.h" + +#define IN_TSBUTTON_PREFIX "tsbutton:" +#define IN_TSBUTTON_COUNT 4 +static int tsbutton_down_id; +static int last_tsbutton_id; + +#define TS_WIDTH 320 +#define TS_HEIGHT 240 + +// HACK: stealing this from plugin_lib +extern void *tsdev; +extern int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr); +extern int (*pts_fd)(struct tsdev *dev); + +static const char * const in_tsbutton_keys[IN_TSBUTTON_COUNT] = { + "TS1", "TS2", "TS3", "TS4", +}; + +static void in_tsbutton_probe(void) +{ + struct tsdev *dev = tsdev; + if (dev == NULL) { + fprintf(stderr, "in_tsbutton_probe: missing tsdev\n"); + return; + } + + in_register(IN_TSBUTTON_PREFIX "touchscreen as buttons", + pts_fd(dev), NULL, IN_TSBUTTON_COUNT, in_tsbutton_keys, 0); +} + +static const char * const * +in_tsbutton_get_key_names(int *count) +{ + *count = IN_TSBUTTON_COUNT; + return in_tsbutton_keys; +} + +static int update_button(void) +{ + struct tsdev *dev = tsdev; + struct ts_sample sample; + int sx = 0, sy = 0, sp = 0, updated = 0; + + if (dev == NULL) + return -1; + + while (pts_read(dev, &sample, 1) > 0) { + sx = sample.x; + sy = sample.y; + sp = sample.pressure; + updated = 1; + } + + if (updated) { + if (sp == 0) + tsbutton_down_id = -1; + else { + // 0 1 + // 2 3 + tsbutton_down_id = 0; + if (sx > TS_WIDTH / 2) + tsbutton_down_id++; + if (sy > TS_HEIGHT / 2) + tsbutton_down_id += 2; + } + } + + return 0; +} + +static int in_tsbutton_update(void *drv_data, const int *binds, int *result) +{ + int ret, t; + + ret = update_button(); + if (ret != 0) + return ret; + + if (tsbutton_down_id >= 0) + for (t = 0; t < IN_BINDTYPE_COUNT; t++) + result[t] |= binds[IN_BIND_OFFS(tsbutton_down_id, t)]; + + return 0; +} + +static int in_tsbutton_update_keycode(void *data, int *is_down) +{ + int ret, ret_kc = -1, ret_down = 0; + + ret = update_button(); + if (ret != 0) + return ret; + + if (tsbutton_down_id == last_tsbutton_id) + return -1; + + if (tsbutton_down_id >= 0) { + if (last_tsbutton_id >= 0) { + ret_kc = last_tsbutton_id; + last_tsbutton_id = -1; + } + else { + ret_down = 1; + ret_kc = tsbutton_down_id; + last_tsbutton_id = tsbutton_down_id; + } + } + else { + ret_kc = last_tsbutton_id; + last_tsbutton_id = -1; + } + + if (is_down != NULL) + *is_down = ret_down; + + return ret_kc; +} + +static const in_drv_t in_tsbutton_drv = { + .prefix = IN_TSBUTTON_PREFIX, + .probe = in_tsbutton_probe, + .get_key_names = in_tsbutton_get_key_names, + .update = in_tsbutton_update, + .update_keycode = in_tsbutton_update_keycode, +}; + +void in_tsbutton_init(void) +{ + tsbutton_down_id = last_tsbutton_id = -1; + in_register_driver(&in_tsbutton_drv); +} + diff --git a/frontend/in_tsbutton.h b/frontend/in_tsbutton.h new file mode 100644 index 00000000..82fab29c --- /dev/null +++ b/frontend/in_tsbutton.h @@ -0,0 +1 @@ +void in_tsbutton_init(void); diff --git a/frontend/main.c b/frontend/main.c index 70355dd2..bf5f35fd 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -319,6 +319,7 @@ int main(int argc, char *argv[]) plat_init(); menu_init(); // loads config pl_init(); + plat_rescan_inputs(); if (psxout) Config.PsxOut = 1; diff --git a/frontend/pl_gun_ts.c b/frontend/pl_gun_ts.c index fbf25e36..2c022513 100644 --- a/frontend/pl_gun_ts.c +++ b/frontend/pl_gun_ts.c @@ -19,7 +19,8 @@ static int gun_x, gun_y, gun_in; static int ts_multiplier_x, ts_multiplier_y, ts_offs_x, ts_offs_y; -static int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr); +int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr); +int (*pts_fd)(struct tsdev *dev); #define limit(v, min, max) \ if (v < min) v = min; \ @@ -77,9 +78,9 @@ struct tsdev *pl_gun_ts_init(void) tsdevname = "/dev/input/touchscreen0"; // avoid hard dep on tslib - ltsh = dlopen("/usr/lib/libts-1.0.so.0", RTLD_LAZY); + ltsh = dlopen("/usr/lib/libts-1.0.so.0", RTLD_NOW|RTLD_GLOBAL); if (ltsh == NULL) - ltsh = dlopen("/usr/lib/libts-0.0.so.0", RTLD_LAZY); + ltsh = dlopen("/usr/lib/libts-0.0.so.0", RTLD_NOW|RTLD_GLOBAL); if (ltsh == NULL) { fprintf(stderr, "%s\n", dlerror()); goto fail; @@ -88,8 +89,10 @@ struct tsdev *pl_gun_ts_init(void) pts_open = dlsym(ltsh, "ts_open"); pts_config = dlsym(ltsh, "ts_config"); pts_read = dlsym(ltsh, "ts_read"); + pts_fd = dlsym(ltsh, "ts_fd"); pts_close = dlsym(ltsh, "ts_close"); - if (pts_open == NULL || pts_config == NULL || pts_read == NULL || pts_close == NULL) { + if (pts_open == NULL || pts_config == NULL || pts_read == NULL + || pts_fd == NULL || pts_close == NULL) { fprintf(stderr, "%s\n", dlerror()); goto fail_dlsym; } diff --git a/frontend/plat_omap.c b/frontend/plat_omap.c index 65478cb3..c9f576b6 100644 --- a/frontend/plat_omap.c +++ b/frontend/plat_omap.c @@ -173,9 +173,6 @@ void plat_init(void) } g_menubg_ptr = temp_frame; - // hmh - plat_rescan_inputs(); - return; fail1: diff --git a/frontend/plat_pollux.c b/frontend/plat_pollux.c index 21e06f07..b237110a 100644 --- a/frontend/plat_pollux.c +++ b/frontend/plat_pollux.c @@ -22,6 +22,7 @@ #include "plugin_lib.h" #include "cspace.h" #include "blit320.h" +#include "in_tsbutton.h" #include "main.h" #include "menu.h" #include "plat.h" @@ -555,9 +556,6 @@ void plat_init(void) if (battdev < 0) perror("Warning: could't open pollux_batt"); - // hmh - plat_rescan_inputs(); - pl_rearmed_cbs.pl_vout_flip = pl_vout_flip; pl_rearmed_cbs.pl_vout_raw_flip = have_warm ? raw_flip_dma : raw_flip_soft; pl_rearmed_cbs.pl_vout_set_mode = pl_vout_set_mode; @@ -566,6 +564,8 @@ void plat_init(void) psx_width = 320; psx_height = 240; psx_bpp = 16; + + in_tsbutton_init(); } void plat_finish(void) diff --git a/frontend/plugin_lib.c b/frontend/plugin_lib.c index 084ff1e2..0e697439 100644 --- a/frontend/plugin_lib.c +++ b/frontend/plugin_lib.c @@ -33,7 +33,7 @@ int in_type1, in_type2; int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 }; int in_keystate, in_state_gun; int pl_flip_cnt; -static void *ts; +void *tsdev; void *pl_vout_buf; static int pl_vout_w, pl_vout_h, pl_vout_bpp; static int vsync_cnt, flips_per_sec, tick_per_sec; @@ -248,8 +248,8 @@ static void update_input(void) void pl_update_gun(int *xn, int *xres, int *y, int *in) { - if (ts) - pl_gun_ts_update(ts, xn, y, in); + if (tsdev) + pl_gun_ts_update(tsdev, xn, y, in); *xres = pl_vout_w; *y = *y * pl_vout_h >> 10; @@ -473,5 +473,5 @@ void pl_init(void) pl_vout_w = pl_vout_h = 256; pl_vout_bpp = 16; - ts = pl_gun_ts_init(); + tsdev = pl_gun_ts_init(); }