首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用wiiuse库及其事件的问题

使用wiiuse库及其事件的问题
EN

Stack Overflow用户
提问于 2011-01-29 12:24:40
回答 1查看 1.3K关注 0票数 21

我最近下载了wiiuse库,并且在使用它时遇到了问题。我写了一个小代码,但是遥控器在连接之后断开了连接。即使出现在作者网站中的代码也不能工作;当我尝试该代码时也会发生同样的情况。我尝试了我在库中获得的演示应用程序,但效果很好。

我使用Windows SP3和MinGW ( gcc 4.5.0 )编译代码。

编辑1

我在Linux上也尝试过同样的方法。在那里,它不受断开问题的影响,但它在正确事件的选择上有问题。不管我做什么,它只会发出/捕捉WIIUSE_NONEWIIUSE_EVENT从未被发出/捕获。

这是我的密码:

代码语言:javascript
复制
#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);
    }
}

没人能做点什么吗?我真的需要尽早解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2012-03-06 22:40:13

切换到CWild

(注:这个答案是基于海报上他已经做过的事情,这样就可以从最上面的未回答列表中删除)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4836833

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档