From 3a40ff141abca7d9c5a1e3f47e41c26d9bc3b3ff Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 1 Mar 2012 23:34:16 +0200 Subject: [PATCH] improve vibration support for Caanoo ..maybe, not tested much. --- Makefile.caanoo | 3 +- frontend/320240/{haptic.txt => haptic_s.cfg} | 0 frontend/320240/haptic_w.cfg | 3 ++ frontend/plat_dummy.c | 2 +- frontend/plat_omap.c | 2 +- frontend/plat_pollux.c | 37 ++++++++++++++------ maemo/hildon.c | 2 +- plugins/dfinput/main.h | 2 +- plugins/dfinput/pad.c | 24 ++++++++++--- 9 files changed, 54 insertions(+), 21 deletions(-) rename frontend/320240/{haptic.txt => haptic_s.cfg} (100%) create mode 100644 frontend/320240/haptic_w.cfg diff --git a/Makefile.caanoo b/Makefile.caanoo index a937f19b..290ca9c4 100644 --- a/Makefile.caanoo +++ b/Makefile.caanoo @@ -18,7 +18,8 @@ rel_caanoo: pcsx $(PLUGINS) \ frontend/320240/caanoo.gpe frontend/320240/pcsx26.png \ frontend/320240/pcsxb.png frontend/320240/skin \ frontend/warm/bin/warm_2.6.24.ko frontend/320240/pollux_set \ - frontend/320240/pcsx_rearmed.ini frontend/320240/haptic.txt \ + frontend/320240/pcsx_rearmed.ini frontend/320240/haptic_w.cfg \ + frontend/320240/haptic_s.cfg \ readme.txt COPYING rm -rf out mkdir -p out/pcsx_rearmed/plugins diff --git a/frontend/320240/haptic.txt b/frontend/320240/haptic_s.cfg similarity index 100% rename from frontend/320240/haptic.txt rename to frontend/320240/haptic_s.cfg diff --git a/frontend/320240/haptic_w.cfg b/frontend/320240/haptic_w.cfg new file mode 100644 index 00000000..3585a719 --- /dev/null +++ b/frontend/320240/haptic_w.cfg @@ -0,0 +1,3 @@ +0 54 +100 -126 +105 0 diff --git a/frontend/plat_dummy.c b/frontend/plat_dummy.c index 7929015c..6249df5f 100644 --- a/frontend/plat_dummy.c +++ b/frontend/plat_dummy.c @@ -68,7 +68,7 @@ void plat_step_volume(int is_up) { } -void plat_trigger_vibrate(void) +void plat_trigger_vibrate(int is_strong) { } diff --git a/frontend/plat_omap.c b/frontend/plat_omap.c index 998e1dfa..3a6a9489 100644 --- a/frontend/plat_omap.c +++ b/frontend/plat_omap.c @@ -132,7 +132,7 @@ void plat_step_volume(int is_up) { } -void plat_trigger_vibrate(void) +void plat_trigger_vibrate(int is_strong) { } diff --git a/frontend/plat_pollux.c b/frontend/plat_pollux.c index d402e848..c03173ea 100644 --- a/frontend/plat_pollux.c +++ b/frontend/plat_pollux.c @@ -689,21 +689,22 @@ struct haptic_data { #define HAPTIC_SET_VIB_LEVEL _IOW(HAPTIC_IOCTL_MAGIC, 9, unsigned int) static int hapticdev = -1; -static struct haptic_data haptic_seq; +static struct haptic_data haptic_seq[2]; -static int haptic_init(void) +static int haptic_read(const char *fname, struct haptic_data *data) { int i, ret, v1, v2; char buf[128], *p; FILE *f; - f = fopen("haptic.txt", "r"); + f = fopen(fname, "r"); if (f == NULL) { - perror("fopen(haptic.txt)"); + fprintf("fopen(%s)", fname); + perror(""); return -1; } - for (i = 0; i < sizeof(haptic_seq.actions) / sizeof(haptic_seq.actions[0]); ) { + for (i = 0; i < sizeof(data->actions) / sizeof(data->actions[0]); ) { p = fgets(buf, sizeof(buf), f); if (p == NULL) break; @@ -718,17 +719,31 @@ static int haptic_init(void) continue; } - haptic_seq.actions[i].time = v1; - haptic_seq.actions[i].strength = v2; + data->actions[i].time = v1; + data->actions[i].strength = v2; i++; } fclose(f); if (i == 0) { - fprintf(stderr, "bad haptic.txt\n"); + fprintf(stderr, "bad haptic file: %s\n", fname); return -1; } - haptic_seq.count = i; + data->count = i; + + return 0; +} + +static int haptic_init(void) +{ + int ret, i; + + ret = haptic_read("haptic_w.cfg", &haptic_seq[0]); + if (ret != 0) + return -1; + ret = haptic_read("haptic_s.cfg", &haptic_seq[1]); + if (ret != 0) + return -1; hapticdev = open("/dev/isa1200", O_RDWR | O_NONBLOCK); if (hapticdev == -1) { @@ -750,7 +765,7 @@ static int haptic_init(void) return 0; } -void plat_trigger_vibrate(void) +void plat_trigger_vibrate(int is_strong) { int ret; @@ -764,7 +779,7 @@ void plat_trigger_vibrate(void) } } - ioctl(hapticdev, HAPTIC_PLAY_PATTERN, &haptic_seq); + ioctl(hapticdev, HAPTIC_PLAY_PATTERN, &haptic_seq[!!is_strong]); } /* Wiz stuff */ diff --git a/maemo/hildon.c b/maemo/hildon.c index 03999096..08949ffa 100644 --- a/maemo/hildon.c +++ b/maemo/hildon.c @@ -262,7 +262,7 @@ void plat_step_volume(int is_up) { } -void plat_trigger_vibrate(void) +void plat_trigger_vibrate(int is_strong) { } diff --git a/plugins/dfinput/main.h b/plugins/dfinput/main.h index 34921704..8e2d5aed 100644 --- a/plugins/dfinput/main.h +++ b/plugins/dfinput/main.h @@ -27,4 +27,4 @@ extern void pl_update_gun(int *xn, int *xres, int *y, int *in); /* vibration trigger to frontend */ extern int in_enable_vibration; -extern void plat_trigger_vibrate(void); +extern void plat_trigger_vibrate(int is_strong); diff --git a/plugins/dfinput/pad.c b/plugins/dfinput/pad.c index ab55db0f..a8019b94 100644 --- a/plugins/dfinput/pad.c +++ b/plugins/dfinput/pad.c @@ -206,11 +206,21 @@ static void do_cmd2(unsigned char value) case CMD_READ_DATA_AND_VIBRATE: if (value == 1 && CurPad == 0 && in_enable_vibration) - plat_trigger_vibrate(); + plat_trigger_vibrate(0); break; } } +static void do_cmd3(unsigned char value) +{ + if (in_enable_vibration && CurCmd == CMD_READ_DATA_AND_VIBRATE && CurPad == 0) { + if (value >= 0xf0) + plat_trigger_vibrate(1); + else if (value > 0x40) + plat_trigger_vibrate(0); + } +} + #if 0 #include unsigned char PADpoll_(unsigned char value); @@ -224,7 +234,8 @@ unsigned char PADpoll(unsigned char value) { unsigned char PADpoll_pad(unsigned char value) { - if (CurByte == 0) { + switch (CurByte) { + case 0: CurCmd = value; CurByte++; @@ -233,10 +244,13 @@ unsigned char PADpoll_pad(unsigned char value) { CurCmd = CMD_READ_DATA_AND_VIBRATE; return do_cmd(); - } - - if (CurByte == 2) + case 2: do_cmd2(value); + break; + case 3: + do_cmd3(value); + break; + } if (CurByte >= CmdLen) return 0xff; // verified -- 2.39.5