使用 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);
}
}
任何人都不能做任何事情吗?我确实需要尽早解决这个问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
切换到 CWild
(注意 - 这个答案是基于发布者对他已经完成的事情的 cpmment,以便可以将其从顶部未答复列表中删除)
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)