mirror of
https://github.com/modmii/YAWM-ModMii-Edition.git
synced 2024-11-14 12:25:15 +01:00
105 lines
1.5 KiB
C
105 lines
1.5 KiB
C
#include <stdio.h>
|
|
#include <ogcsys.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
|
|
#include "sys.h"
|
|
#include "wpad.h"
|
|
//#include "wkb.h"
|
|
|
|
/* Constants */
|
|
#define MAX_WIIMOTES 4
|
|
|
|
int start;
|
|
|
|
void __Wpad_PowerCallback(s32 chan)
|
|
{
|
|
/* Poweroff console */
|
|
Sys_Shutdown();
|
|
}
|
|
|
|
|
|
s32 Wpad_Init(void)
|
|
{
|
|
s32 ret;
|
|
|
|
/* Initialize Wiimote subsystem */
|
|
ret = WPAD_Init();
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
/* Set POWER button callback */
|
|
WPAD_SetPowerButtonCallback(__Wpad_PowerCallback);
|
|
|
|
return ret;
|
|
}
|
|
|
|
void Wpad_Disconnect(void)
|
|
{
|
|
u32 cnt;
|
|
|
|
/* Disconnect Wiimotes */
|
|
for (cnt = 0; cnt < MAX_WIIMOTES; cnt++)
|
|
WPAD_Disconnect(cnt);
|
|
|
|
/* Shutdown Wiimote subsystem */
|
|
WPAD_Shutdown();
|
|
}
|
|
|
|
u32 Wpad_GetButtons(void)
|
|
{
|
|
u32 buttons = 0, cnt;
|
|
|
|
/* Scan pads */
|
|
WPAD_ScanPads();
|
|
|
|
/* Get pressed buttons */
|
|
for (cnt = 0; cnt < MAX_WIIMOTES; cnt++)
|
|
buttons |= WPAD_ButtonsDown(cnt);
|
|
|
|
return buttons;
|
|
}
|
|
|
|
u32 Wpad_WaitButtons(void)
|
|
{
|
|
u32 buttons = 0;
|
|
/* Wait for button pressing */
|
|
while (!buttons) {
|
|
buttons = Wpad_GetButtons();
|
|
VIDEO_WaitVSync();
|
|
}
|
|
|
|
return buttons;
|
|
}
|
|
|
|
u32 Wpad_HeldButtons(void)
|
|
{
|
|
u32 buttons = 0, cnt;
|
|
|
|
/* Scan pads */
|
|
WPAD_ScanPads();
|
|
|
|
/* Get pressed buttons */
|
|
for (cnt = 0; cnt < MAX_WIIMOTES; cnt++)
|
|
buttons |= WPAD_ButtonsHeld(cnt);
|
|
|
|
return buttons;
|
|
}
|
|
|
|
bool Wpad_TimeButton(void)
|
|
{
|
|
u32 buttons = 1;
|
|
|
|
time_t start,end;
|
|
time (&start);
|
|
int dif;
|
|
/* Wait for button pressing */
|
|
while (buttons) {
|
|
buttons = Wpad_HeldButtons();
|
|
VIDEO_WaitVSync();
|
|
time (&end);
|
|
dif = difftime (end,start);
|
|
if(dif>=2) return true;
|
|
}
|
|
return false;
|
|
} |