Problems using the wiiuse library and its events
Asked Answered
A

1

21

I recently downloaded the wiiuse library and am having problems using it. I wrote a small code but the remote disconnects just after the connection. Even the code present at the author's website doesn't work; the same happens when I try that code. I tried the demo application I got with the library but that works fine.

I'm using Windows XP SP3 and MinGW ( gcc 4.5.0 ) for compiling the codes.


EDIT 1

I've tried the same with Linux. There, it doesn't suffer with the disconnection problem but it has problems picking up the correct EVENTS. Whatever I do, it only emits/catches WIIUSE_NONE. The WIIUSE_EVENT is never emitted/caught.

Here's my code:

#include <stdio.h>
#include <stdlib.h>
#include "wiiuse.h"

#define NUMBER_OF_REMOTES 1
void handle_event(struct wiimote_t* rm){

    if(IS_PRESSED(rm, WIIMOTE_BUTTON_UP)){
        printf("\n - IR Activated - \n");
        wiiuse_set_ir(rm,1);
    }
    else if(IS_PRESSED(rm, WIIMOTE_BUTTON_DOWN)){
        printf("\n - IR Dectivated - \n");
        wiiuse_set_ir(rm,0);
    }

    if(WIIUSE_USING_IR(rm)){

        for(int i=0; i<4; i++){
            if(rm->ir.dot[i].visible){
                printf("IR source %i: (%u, %u)\n", i, rm->ir.dot[i].x, rm->ir.dot[i].y);
            }
            printf("IR cursor: (%u, %u)\n", rm->ir.x, rm->ir.y);
            printf("IR z distance: %f\n", rm->ir.z);

        }
    }
}

void handle_disconnect(struct wiimote_t* rm){
    printf("\n - DISCONNECTED - ID: %i\n\n", rm->unid);
}

int main()
{
    wiimote**  remote = wiiuse_init(NUMBER_OF_REMOTES);
    printf("Searching...");
    int found = wiiuse_find(remote, NUMBER_OF_REMOTES, 5000);
    printf("Found %d devices\n", found);
    int connected = wiiuse_connect(remote, found);

    if(!connected){
        printf("Failed to connect\n");
        return 0;
    }
    else{

        printf("Connected\n");
        wiiuse_rumble(remote[0],1);
        Sleep(250);
        wiiuse_rumble(remote[0],0);

        while(1){
            if (wiiuse_poll(remote, NUMBER_OF_REMOTES)) {
                for(int i=0;i<NUMBER_OF_REMOTES; i++){
                    switch(remote[i]->event){
                        case WIIUSE_EVENT:
                                   handle_event(remote[i]); break;

                        case WIIUSE_DISCONNECT:
                        case WIIUSE_UNEXPECTED_DISCONNECT:
                                   handle_disconnect(remote[i]); break;
                        default: break;
                    }
                }
            }
        }
        wiiuse_cleanup(remote,NUMBER_OF_REMOTES);
    }
}

Can't anyone do anything? I really need to fix the problem as early as possible.

An answered 29/1, 2011 at 12:24 Comment(8)
I've used the wiiuse library before on Linux without problemsBirdella
Are you using 1 or 2 remotes, as its waiting 5000s for both to appear?Birdella
No, I'm using a single remote. I changed that 5000 to 10 and it connects but it suffers from the same problem. Disconnects as soon as it connects. :(An
I've been able to get the library working in Linux but now there's another problem. It doesn't respond to any event. The remote generates only WIIUSE_NONE.Button presses, Motion, everything gives me only WIIUSE_NONE and not WIIUSE_EVENT. Any solution for that?An
you could try a opening a bounty. I'd gladly help but I dont have a wii or a wii mote :DKiushu
@hexa: I switched over to CWiid and got all my work done, long time back.An
I never used wiiuse either, I think. IIRC, the wiimote would get disconnected in a moment if nothing was keeping the connection going. Sounds like there's some real problem there if the demo code doesn't work.Timms
@SaurabhManchanda that case delete topic or create your own response and mark as solved. This is top topic in C questions and it's been (kinda) solved or needs no further solving.Platinocyanide
M
1

Switch to CWild

(Note - this answer is based on the poster's cpmment of what he's already done so that this can be taken off the top unanswered list)

Martica answered 6/3, 2012 at 22:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.