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.

Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345
Saurabh Manchanda
  • 1,115
  • 1
  • 9
  • 21
  • 1
    I've used the wiiuse library before on Linux without problems – Twig Jan 29 '11 at 15:54
  • Are you using 1 or 2 remotes, as its waiting 5000s for both to appear? – Twig Jan 29 '11 at 15:58
  • 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. :( – Saurabh Manchanda Jan 29 '11 at 17:04
  • 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? – Saurabh Manchanda Jan 30 '11 at 14:39
  • you could try a opening a bounty. I'd gladly help but I dont have a wii or a wii mote :D – Vinicius Kamakura Jun 21 '11 at 00:24
  • 1
    @hexa: I switched over to CWiid and got all my work done, long time back. – Saurabh Manchanda Jul 21 '11 at 05:21
  • 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. – XTL Feb 21 '12 at 08:00
  • 1
    @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. – Tomas Pruzina Mar 06 '12 at 11:28

1 Answers1

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)

David Oneill
  • 12,502
  • 16
  • 58
  • 70