使用wiiuse库及其事件的问题

Sau*_*nda 21 c linux events wiimote wiiuse

我最近下载了wiiuse库,但在使用它时遇到了问题.我写了一个小代码,但是在连接之后远程断开连接.即使是作者网站上的代码也不起作用; 当我尝试该代码时也会发生同样的情况.我尝试了我在库中使用的演示应用程序但是工作正常.

我正在使用Windows XP SP3和MinGW(gcc 4.5.0)来编译代码.


编辑1

我在Linux上也尝试过相同的功能.在那里,它没有受到断开问题的困扰,但它在拾取正确的事件时遇到了问题.无论我做什么,它只会发出/捕获WIIUSE_NONE.将WIIUSE_EVENT永远不会发出/捕获.

这是我的代码:

#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);
    }
}
Run Code Online (Sandbox Code Playgroud)

谁也不能做任何事情?我真的需要尽早解决问题.

Dav*_*ill 1

切换到 CWild

(注意 - 这个答案是基于发帖者对他已经做过的事情的评价,因此可以将其从未答复的顶部列表中删除)