2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* libwiigui Template
|
|
|
|
* Tantric 2009
|
|
|
|
*
|
|
|
|
* input.cpp
|
|
|
|
* Wii/GameCube controller management
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
|
|
|
|
#include "menu.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "libwiigui/gui.h"
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
int rumbleRequest[4] = { 0, 0, 0, 0 };
|
2009-10-01 01:10:58 +02:00
|
|
|
GuiTrigger userInput[4];
|
2010-09-24 02:48:03 +02:00
|
|
|
static int rumbleCount[4] = { 0, 0, 0, 0 };
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-17 19:48:16 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* UpdatePads
|
|
|
|
*
|
|
|
|
* called by postRetraceCallback in InitGCVideo - scans gcpad and wpad
|
|
|
|
***************************************************************************/
|
|
|
|
void UpdatePads()
|
|
|
|
{
|
|
|
|
WPAD_ScanPads();
|
|
|
|
PAD_ScanPads();
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 3; i >= 0; i--)
|
2010-09-17 19:48:16 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData));
|
2010-09-17 19:48:16 +02:00
|
|
|
userInput[i].chan = i;
|
2010-09-24 02:48:03 +02:00
|
|
|
userInput[i].pad.btns_d = PAD_ButtonsDown(i);
|
|
|
|
userInput[i].pad.btns_u = PAD_ButtonsUp(i);
|
|
|
|
userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
|
|
|
|
userInput[i].pad.stickX = PAD_StickX(i);
|
|
|
|
userInput[i].pad.stickY = PAD_StickY(i);
|
|
|
|
userInput[i].pad.substickX = PAD_SubStickX(i);
|
|
|
|
userInput[i].pad.substickY = PAD_SubStickY(i);
|
|
|
|
userInput[i].pad.triggerL = PAD_TriggerL(i);
|
|
|
|
userInput[i].pad.triggerR = PAD_TriggerR(i);
|
|
|
|
|
2010-10-27 16:45:27 +02:00
|
|
|
if (Settings.rumble == ON) DoRumble(i);
|
2010-09-17 19:48:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* SetupPads
|
|
|
|
*
|
|
|
|
* Sets up userInput triggers for use
|
|
|
|
***************************************************************************/
|
|
|
|
void SetupPads()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
PAD_Init();
|
|
|
|
WPAD_Init();
|
2010-09-17 19:48:16 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// read wiimote accelerometer and IR data
|
2010-09-24 02:48:03 +02:00
|
|
|
WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
|
|
|
|
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
2010-09-17 19:48:16 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < 4; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
userInput[i].chan = i;
|
|
|
|
}
|
2010-09-17 19:48:16 +02:00
|
|
|
}
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* ShutoffRumble
|
|
|
|
***************************************************************************/
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void ShutoffRumble()
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
for (int i = 0; i < 4; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
WPAD_Rumble(i, 0);
|
2009-10-01 01:10:58 +02:00
|
|
|
rumbleCount[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* DoRumble
|
|
|
|
***************************************************************************/
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
void DoRumble(int i)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (rumbleRequest[i] && rumbleCount[i] < 3)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
WPAD_Rumble(i, 1); // rumble on
|
2009-10-01 01:10:58 +02:00
|
|
|
rumbleCount[i]++;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
else if (rumbleRequest[i])
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
rumbleCount[i] = 20;
|
|
|
|
rumbleRequest[i] = 0;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (rumbleCount[i]) rumbleCount[i]--;
|
|
|
|
WPAD_Rumble(i, 0); // rumble off
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* WPAD_Stick
|
|
|
|
*
|
|
|
|
* Get X/Y value from Wii Joystick (classic, nunchuk) input
|
|
|
|
***************************************************************************/
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s8 WPAD_Stick(u8 chan, u8 right, int axis)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
float mag = 0.0;
|
|
|
|
float ang = 0.0;
|
2010-09-24 02:48:03 +02:00
|
|
|
WPADData *data = WPAD_Data(chan);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
switch (data->exp.type)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
case WPAD_EXP_NUNCHUK:
|
|
|
|
case WPAD_EXP_GUITARHERO3:
|
2010-09-24 02:48:03 +02:00
|
|
|
if (right == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
mag = data->exp.nunchuk.js.mag;
|
|
|
|
ang = data->exp.nunchuk.js.ang;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WPAD_EXP_CLASSIC:
|
2010-09-24 02:48:03 +02:00
|
|
|
if (right == 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
mag = data->exp.classic.ljs.mag;
|
|
|
|
ang = data->exp.classic.ljs.ang;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mag = data->exp.classic.rjs.mag;
|
|
|
|
ang = data->exp.classic.rjs.ang;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate x/y value (angle need to be converted into radian) */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (mag > 1.0)
|
|
|
|
mag = 1.0;
|
|
|
|
else if (mag < -1.0) mag = -1.0;
|
2009-10-01 01:10:58 +02:00
|
|
|
double val;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (axis == 0) // x-axis
|
|
|
|
val = mag * sin((PI * ang) / 180.0f);
|
2009-10-01 01:10:58 +02:00
|
|
|
else // y-axis
|
2010-09-24 02:48:03 +02:00
|
|
|
val = mag * cos((PI * ang) / 180.0f);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
return (s8) (val * 128.0f);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|