2011-01-02 10:23:44 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <ogc/pad.h>
|
|
|
|
|
|
|
|
#include "sys.h"
|
|
|
|
#include "wpad.h"
|
|
|
|
|
|
|
|
/* Constants */
|
2011-07-26 00:28:22 +02:00
|
|
|
#define MAX_WIIMOTES 4
|
2011-01-02 10:23:44 +01:00
|
|
|
|
|
|
|
extern u8 shutdown;
|
|
|
|
|
|
|
|
void __Wpad_PowerCallback(s32 chan)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Poweroff console */
|
|
|
|
shutdown = 1;
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 Wpad_Init(void)
|
|
|
|
{
|
2015-01-04 21:22:06 +01:00
|
|
|
WUPC_Init();
|
2011-07-26 00:28:22 +02:00
|
|
|
s32 ret;
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Initialize Wiimote subsystem */
|
|
|
|
ret = WPAD_Init();
|
|
|
|
if (ret < 0) return ret;
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Set POWER button callback */
|
|
|
|
WPAD_SetPowerButtonCallback(__Wpad_PowerCallback);
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return ret;
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wpad_Disconnect(void)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
u32 cnt;
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Disconnect Wiimotes */
|
|
|
|
for (cnt = 0; cnt < MAX_WIIMOTES; cnt++)
|
|
|
|
WPAD_Disconnect(cnt);
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
/* Shutdown Wiimote subsystem */
|
2015-01-04 21:22:06 +01:00
|
|
|
WUPC_Shutdown();
|
2011-07-26 00:28:22 +02:00
|
|
|
WPAD_Shutdown();
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsWpadConnected()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
int i = 0;
|
|
|
|
u32 test = 0;
|
|
|
|
int notconnected = 0;
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
if (WPAD_Probe(i, &test) == WPAD_ERR_NO_CONTROLLER)
|
|
|
|
{
|
|
|
|
notconnected++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (notconnected < 4)
|
|
|
|
return true;
|
|
|
|
else return false;
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 ButtonsHold(void)
|
|
|
|
{
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
int i;
|
|
|
|
u32 buttons = 0;
|
2015-01-04 21:22:06 +01:00
|
|
|
WUPC_UpdateButtonStats();
|
2011-07-26 00:28:22 +02:00
|
|
|
WPAD_ScanPads();
|
|
|
|
PAD_ScanPads();
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
for (i = 3; i >= 0; i--)
|
|
|
|
{
|
2015-01-04 21:22:06 +01:00
|
|
|
buttons |= WUPC_ButtonsHeld(i);
|
2011-07-26 00:28:22 +02:00
|
|
|
buttons |= PAD_ButtonsHeld(i);
|
|
|
|
buttons |= WPAD_ButtonsHeld(i);
|
|
|
|
}
|
|
|
|
return buttons;
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 ButtonsPressed(void)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
int i;
|
|
|
|
u32 buttons = 0;
|
2015-01-04 21:22:06 +01:00
|
|
|
WUPC_UpdateButtonStats();
|
2011-07-26 00:28:22 +02:00
|
|
|
WPAD_ScanPads();
|
|
|
|
PAD_ScanPads();
|
|
|
|
|
|
|
|
for (i = 3; i >= 0; i--)
|
|
|
|
{
|
2015-01-04 21:22:06 +01:00
|
|
|
buttons |= WUPC_ButtonsDown(i);
|
2011-07-26 00:28:22 +02:00
|
|
|
buttons |= PAD_ButtonsDown(i);
|
|
|
|
buttons |= WPAD_ButtonsDown(i);
|
|
|
|
}
|
|
|
|
return buttons;
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|