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"
|
2011-06-14 19:53:19 +02:00
|
|
|
#include "GUI/gui.h"
|
2010-12-31 17:18:48 +01:00
|
|
|
#include "sys.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
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()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
WPAD_ScanPads();
|
|
|
|
PAD_ScanPads();
|
|
|
|
|
|
|
|
for (int i = 3; i >= 0; i--)
|
|
|
|
{
|
|
|
|
memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData));
|
|
|
|
userInput[i].chan = i;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (Settings.rumble == ON) DoRumble(i);
|
|
|
|
|
|
|
|
if(userInput[i].wpad.exp.type == WPAD_EXP_NUNCHUK)
|
|
|
|
{
|
|
|
|
if((userInput[i].wpad.btns_h & WPAD_NUNCHUK_BUTTON_Z) && (userInput[i].wpad.btns_d & WPAD_NUNCHUK_BUTTON_C))
|
* Improved GameCube controller functions (patch by Dynamit)
R+Z=Screenshot, X=Gameinfo window, Y=Covers download
* Added Classic Controller and GameCube Controller support
in GameInfo window:
Right stick=3D Cover movement, X=Flip 3DCover 180°, L/R=Zoom
* Added Wifi6 and wifi10 pictures for GameInfo window.
(Thanks OriginalHamster)
* Added device priority selection for GameCube listing
in global Loader settings (SD->USB, or USB->SD)
* Added a "Use global" language setting for Gamecube games.
* Added support for USB devices with modified MBR's signature
to prevent WiiU's format message.
* Prevent Rockband cursor display on GameCube and WiiWare
games with "band" in the title (Crach bandicoot, Beach
Bandits, etc.)
* Added Dol's Video mode patcher in Loader/Game settings,
for games which couldn't be forced. (MadWorld, MotoGP08,
Mario Party 8, etc.)
♦ Region patch = Patches the dol's known video modes
to the region selected in "Video mode" setting,
but keep interlace/progressive references.
♦ ON = Patch all dol's known video modes to the one
selected in "Video mode" setting.
♦ ALL = Patch all dol's found video mode patterns
(even unknown video modes) to the one selected
in "Video mode" setting.
* DML: Updated DM(L) version detection up to v2.10
* DML: Automatically enable PADHook if Screenshot setting
is enabled
* DML: Fixed a bug where multiple video modes could be set
at the same time
* DEVO: Added a prompt if trying to launch a game from a
non FAT32 partition.
* DEVO: Added Direct Mapping Buttons setting (Devo r200+)
* DEVO: Added support for Language setting
* Language files updated: Chinese, French
2013-08-18 16:30:39 +02:00
|
|
|
ScreenShot();
|
2010-12-31 17:18:48 +01:00
|
|
|
}
|
* Improved GameCube controller functions (patch by Dynamit)
R+Z=Screenshot, X=Gameinfo window, Y=Covers download
* Added Classic Controller and GameCube Controller support
in GameInfo window:
Right stick=3D Cover movement, X=Flip 3DCover 180°, L/R=Zoom
* Added Wifi6 and wifi10 pictures for GameInfo window.
(Thanks OriginalHamster)
* Added device priority selection for GameCube listing
in global Loader settings (SD->USB, or USB->SD)
* Added a "Use global" language setting for Gamecube games.
* Added support for USB devices with modified MBR's signature
to prevent WiiU's format message.
* Prevent Rockband cursor display on GameCube and WiiWare
games with "band" in the title (Crach bandicoot, Beach
Bandits, etc.)
* Added Dol's Video mode patcher in Loader/Game settings,
for games which couldn't be forced. (MadWorld, MotoGP08,
Mario Party 8, etc.)
♦ Region patch = Patches the dol's known video modes
to the region selected in "Video mode" setting,
but keep interlace/progressive references.
♦ ON = Patch all dol's known video modes to the one
selected in "Video mode" setting.
♦ ALL = Patch all dol's found video mode patterns
(even unknown video modes) to the one selected
in "Video mode" setting.
* DML: Updated DM(L) version detection up to v2.10
* DML: Automatically enable PADHook if Screenshot setting
is enabled
* DML: Fixed a bug where multiple video modes could be set
at the same time
* DEVO: Added a prompt if trying to launch a game from a
non FAT32 partition.
* DEVO: Added Direct Mapping Buttons setting (Devo r200+)
* DEVO: Added support for Language setting
* Language files updated: Chinese, French
2013-08-18 16:30:39 +02:00
|
|
|
if((userInput[i].pad.btns_h & PAD_TRIGGER_R) && (userInput[i].pad.btns_d & PAD_TRIGGER_Z))
|
|
|
|
ScreenShot();
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
2010-09-17 19:48:16 +02:00
|
|
|
}
|
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
/****************************************************************************
|
2011-12-28 17:27:30 +01:00
|
|
|
* ScreensaverTime
|
2011-01-02 10:23:44 +01:00
|
|
|
***************************************************************************/
|
2011-12-28 17:27:30 +01:00
|
|
|
static inline u32 ScreensaverTime(int setting)
|
2011-01-02 10:23:44 +01:00
|
|
|
{
|
2011-12-28 17:27:30 +01:00
|
|
|
switch (setting)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
case 0:
|
2011-12-28 17:27:30 +01:00
|
|
|
return 0xFFFFFF;
|
2011-07-26 00:28:22 +02:00
|
|
|
case 1:
|
2011-12-28 17:27:30 +01:00
|
|
|
return 180;
|
2011-07-26 00:28:22 +02:00
|
|
|
case 2:
|
2011-12-28 17:27:30 +01:00
|
|
|
return 300;
|
2011-07-26 00:28:22 +02:00
|
|
|
case 3:
|
2011-12-28 17:27:30 +01:00
|
|
|
return 600;
|
2011-07-26 00:28:22 +02:00
|
|
|
case 4:
|
2011-12-28 17:27:30 +01:00
|
|
|
return 1200;
|
2011-07-26 00:28:22 +02:00
|
|
|
case 5:
|
2011-12-28 17:27:30 +01:00
|
|
|
return 1800;
|
2011-07-26 00:28:22 +02:00
|
|
|
case 6:
|
2011-12-28 17:27:30 +01:00
|
|
|
return 3600;
|
2011-07-26 00:28:22 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-12-28 17:27:30 +01:00
|
|
|
|
|
|
|
return 0xFFFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* SetWPADTimeout
|
|
|
|
***************************************************************************/
|
|
|
|
void SetWPADTimeout()
|
|
|
|
{
|
|
|
|
WPAD_SetIdleTimeout(ScreensaverTime(Settings.screensaver));
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* ControlActivityTimeOut
|
|
|
|
***************************************************************************/
|
|
|
|
bool ControlActivityTimeout(void)
|
|
|
|
{
|
|
|
|
u32 minTime = 0xFFFFFF;
|
|
|
|
for(int i = 0; i < 3; ++i)
|
|
|
|
if(pointer[i]->getLastActivCounter() < minTime)
|
|
|
|
minTime = pointer[i]->getLastActivCounter();
|
|
|
|
|
|
|
|
// not very accurate but it's not required here
|
2012-05-06 12:59:58 +02:00
|
|
|
return (minTime/(Settings.PAL50 ? 50 : 60) > ScreensaverTime(Settings.screensaver));
|
2011-12-28 17:27:30 +01:00
|
|
|
}
|
2010-09-17 19:48:16 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* SetupPads
|
|
|
|
*
|
|
|
|
* Sets up userInput triggers for use
|
|
|
|
***************************************************************************/
|
|
|
|
void SetupPads()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
PAD_Init();
|
|
|
|
WPAD_Init();
|
2010-09-17 19:48:16 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
// read wiimote accelerometer and IR data
|
|
|
|
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
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
userInput[i].chan = i;
|
|
|
|
}
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
SetWPADTimeout();
|
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()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
WPAD_Rumble(i, 0);
|
|
|
|
rumbleCount[i] = 0;
|
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* DoRumble
|
|
|
|
***************************************************************************/
|
2010-09-24 02:48:03 +02:00
|
|
|
void DoRumble(int i)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if (rumbleRequest[i] && rumbleCount[i] < 3)
|
|
|
|
{
|
|
|
|
WPAD_Rumble(i, 1); // rumble on
|
|
|
|
rumbleCount[i]++;
|
|
|
|
}
|
|
|
|
else if (rumbleRequest[i])
|
|
|
|
{
|
|
|
|
rumbleCount[i] = 20;
|
|
|
|
rumbleRequest[i] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (rumbleCount[i]) rumbleCount[i]--;
|
|
|
|
WPAD_Rumble(i, 0); // rumble off
|
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|