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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With