I'm new to Wii programming and @Mr_Reaper found an interesting bug in my games:
If you press very shortly a direction button, it happens that WPAD_ButtonsHeld() reports that the button is held forever.
This sounds like a newbie problem (which I am), but I have a test case.
@Mr_Reaper found out what I did wrong: I did not call WPAD_SetDataFormat().
It surprised me, that I saw so many examples without it. My conclusion is, that it works as long as you call WPAD_ButtonsHeld() very often.
My game logic consumes 44 millis, which is too long. I could also reproduce it with 20 millis.
And I also wonder if there are other games in the wild with this bug.
Without @Mr_Reaper I would probably think my WiiMote is dead or something. Thanks a lot!
Hopefully this will help other programmers...
You can find my games here:
VVVV4K
MEG4kMAN
If you press very shortly a direction button, it happens that WPAD_ButtonsHeld() reports that the button is held forever.
This sounds like a newbie problem (which I am), but I have a test case.
@Mr_Reaper found out what I did wrong: I did not call WPAD_SetDataFormat().
It surprised me, that I saw so many examples without it. My conclusion is, that it works as long as you call WPAD_ButtonsHeld() very often.
My game logic consumes 44 millis, which is too long. I could also reproduce it with 20 millis.
And I also wonder if there are other games in the wild with this bug.
Without @Mr_Reaper I would probably think my WiiMote is dead or something. Thanks a lot!
Hopefully this will help other programmers...
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ogcsys.h>
#include <gccore.h>
#include <sys/time.h>
#include <sys/unistd.h>
#include <wiiuse/wpad.h>
static u32 *xfb;
static GXRModeObj *rmode;
void Initialise() {
VIDEO_Init();
WPAD_Init();
// This line fixes the stuck button problem (by Mr_Reaper)
//WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
rmode = VIDEO_GetPreferredMode(NULL);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
}
int main() {
Initialise();
printf("\n\nTest stuck button...\n\n");
printf("Press a direction button on your Wiimote for a very short moment...\n");
printf("And held is fired forever...\n\n");
while (true)
{
WPAD_ScanPads();
u16 buttonsDown = WPAD_ButtonsDown(0);
u16 buttonsHeld = WPAD_ButtonsHeld(0);
u16 buttonsUp = WPAD_ButtonsUp(0);
printf("down=%04d held=%04d up=%04d\r", buttonsDown, buttonsHeld, buttonsUp);
// reproducible with 44 millis
usleep(1000 * 44);
if (buttonsDown & WPAD_BUTTON_HOME)
{
exit(0);
}
}
return 0;
}
You can find my games here:
VVVV4K
MEG4kMAN