Page 1 of 1

issue with input from the second controller

Posted: Fri Jun 20, 2008 12:26 pm
by kouky
I'd like to add a 2 players feature in my project, but can't succesfully receive data from the second controler.

I init my pads with this:

Code: Select all

    int port = 0; // 0 -> Connector 1, 1 -> Connector 2
    int slot = 0; // Always zero if not using multitap
    if((ret = padPortOpen(port, slot, padBuf)) == 0) {
        scr_printf("padOpenPort failed: %d\n", ret);
        SleepThread();
    }
    else{scr_printf("ok-");}

    if(!initializePad(port, slot)) {
        scr_printf("pad initalization failed!\n");
        SleepThread();
    }
    else{scr_printf("ok-");}

    port = 1; // 0 -> Connector 1, 1 -> Connector 2
    slot = 0; // Always zero if not using multitap
    if((ret = padPortOpen(port, slot, padBuf)) == 0) {
        scr_printf("padOpenPort failed: %d\n", ret);
        SleepThread();
    }
    else{scr_printf("ok-");}

    if(!initializePad(port, slot)) {
        scr_printf("pad initalization failed!\n");
        SleepThread();
    }
    else{scr_printf("ok-");}
and 4 "ok" are printed, fine!

but how can I receive data from the second one?

i tried

Code: Select all

struct padButtonStatus buttons[2];
int port =1;
int slot=0;
int ret 
ret = padRead(port, slot, &buttons[port]); // port, slot, buttons

    if (ret != 0) {
        paddata[port] = 0xffff ^ buttons[port].btns;

        new_pad[port] = paddata[port] & ~old_pad[port];
        old_pad[port] = paddata[port];

        i=new_pad[port];
    }

    paddata[port] = 0xffff ^ buttons[port].btns;
    i=paddata[port];
but then

Code: Select all

    if (i&PAD_TRIANGLE) { ... }
just never works...

Posted: Fri Jun 20, 2008 3:59 pm
by Lukasz
From a quick glance at your description and code I can't spot the problem. I suggest you try the 3 different pad samples in ps2sdk (rpc/pad, rpc/padx, rpc/mtap) and go from there.

Posted: Sat Jun 21, 2008 12:45 am
by kouky
Thanks, Lukasz,
I've found my error in those examples:
You need to have 2 padBuf, so the code has to be:

Code: Select all

static char *padBuf[2];
    padBuf[0] = memalign(64, 256);
    padBuf[1] = memalign(64, 256);


...



    int port = 0; // 0 -> Connector 1, 1 -> Connector 2
    int slot = 0; // Always zero if not using multitap
    if((ret = padPortOpen(port, slot, padBuf[0])) == 0) {
        scr_printf("padOpenPort failed: %d\n", ret);
        SleepThread();
    }

    if(!initializePad(port, slot)) {
        scr_printf("pad initalization failed!\n");
        SleepThread();
    }

    port = 1; // 0 -> Connector 1, 1 -> Connector 2
    slot = 0; // Always zero if not using multitap
    if((ret = padPortOpen(port, slot, padBuf[1])) == 0) {
        scr_printf("padOpenPort failed: %d\n", ret);
        SleepThread();
    }

    if(!initializePad(port, slot)) {
        scr_printf("pad initalization failed!\n");
        SleepThread();
    }
now it works :)

Posted: Sat Jun 21, 2008 1:48 am
by J.F.
Thanks for letting us know what it was that worked. Too often you see people post that they worked out the problem, but not what the solution was, and that doesn't help anyone.