X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=frontend%2Fpl_gun_ts.c;h=315c70c108cba870ca68a21aa527ccef7a87c3e2;hp=2c022513c812f46774066b934731e6da08f4bfc4;hb=215ff9e69c0b845f24e7a3aa9faeef06d9276145;hpb=faf2b2aae80c811f778f7cfa9a320dd7ade01dac diff --git a/frontend/pl_gun_ts.c b/frontend/pl_gun_ts.c index 2c022513..315c70c1 100644 --- a/frontend/pl_gun_ts.c +++ b/frontend/pl_gun_ts.c @@ -15,18 +15,26 @@ #include "plugin_lib.h" #include "pl_gun_ts.h" #include "menu.h" +#include "../plugins/dfinput/externals.h" #include "../plugins/dfinput/main.h" +#ifdef MAEMO +#define N900_TSMAX_X 4096 +#define N900_TSOFFSET_X 0 +#define N900_TSMAX_Y 4096 +#define N900_TSOFFSET_Y 0 +#endif + static int gun_x, gun_y, gun_in; static int ts_multiplier_x, ts_multiplier_y, ts_offs_x, ts_offs_y; -int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr); -int (*pts_fd)(struct tsdev *dev); +static int (*pts_read)(struct tsdev *dev, struct ts_sample *sample, int nr); +static int (*pts_fd)(struct tsdev *dev); #define limit(v, min, max) \ if (v < min) v = min; \ else if (v > max) v = max -void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in) +int pl_gun_ts_update_raw(struct tsdev *ts, int *x, int *y, int *p) { struct ts_sample sample; int sx = 0, sy = 0, sp = 0, updated = 0; @@ -34,7 +42,11 @@ void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in) if (ts != NULL) { while (pts_read(ts, &sample, 1) > 0) { sx = sample.x; +#ifdef MAEMO + sy = N900_TSMAX_Y - sample.y; +#else sy = sample.y; +#endif sp = sample.pressure; updated = 1; } @@ -51,6 +63,21 @@ void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in) } } + if (updated) { + if (x) *x = sx; + if (y) *y = sy; + if (p) *p = sp; + return 1; + } + + return 0; +} + +/* returns x, y in range 0..1023 (normalized to visible layer) */ +void pl_gun_ts_update(struct tsdev *ts, int *x, int *y, int *in) +{ + pl_gun_ts_update_raw(ts, NULL, NULL, NULL); + *x = gun_x; *y = gun_y; *in = gun_in | in_state_gun; @@ -64,6 +91,14 @@ void pl_set_gun_rect(int x, int y, int w, int h) ts_multiplier_y = (1<<20) / h; } +int pl_gun_ts_get_fd(struct tsdev *ts) +{ + if (ts != NULL && pts_fd != NULL) + return pts_fd(ts); + + return -1; +} + struct tsdev *pl_gun_ts_init(void) { struct tsdev *(*pts_open)(const char *dev_name, int nonblock) = NULL; @@ -73,14 +108,20 @@ struct tsdev *pl_gun_ts_init(void) struct tsdev *ts; void *ltsh; +#ifdef MAEMO + tsdevname = "/dev/input/ts"; +#else tsdevname = getenv("TSLIB_TSDEVICE"); if (tsdevname == NULL) tsdevname = "/dev/input/touchscreen0"; +#endif // avoid hard dep on tslib 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_NOW|RTLD_GLOBAL); + if (ltsh == NULL) + ltsh = dlopen("/lib/libts-0.0.so.0", RTLD_NOW|RTLD_GLOBAL); if (ltsh == NULL) { fprintf(stderr, "%s\n", dlerror()); goto fail; @@ -98,18 +139,27 @@ struct tsdev *pl_gun_ts_init(void) } ts = pts_open(tsdevname, 1); - if (ts == NULL) + if (ts == NULL){ + printf("Failed pts_open, check permission on %s\n", tsdevname); goto fail_open; - if (pts_config(ts) != 0) + } + if (pts_config(ts) != 0){ + printf("Failed pts_config\n"); goto fail_config; + } // FIXME: we should be able to get this somewhere // the problem is this doesn't always match resolution due to different display modes +#ifdef MAEMO + pl_set_gun_rect(N900_TSOFFSET_X, N900_TSOFFSET_Y, N900_TSMAX_X, N900_TSMAX_Y); +#else #ifdef __ARM_ARCH_7A__ pl_set_gun_rect(0, 0, 800, 480); #else pl_set_gun_rect(0, 0, 320, 240); #endif +#endif + printf("Touchscreen configured, device=%s\n", tsdevname); return ts; fail_config: