2009-07-03 11:45:47 +00:00
|
|
|
/* OnePAD - author: arcum42(@gmail.com)
|
|
|
|
* Copyright (C) 2009
|
|
|
|
*
|
|
|
|
* Based on ZeroPAD, author zerofrog@gmail.com
|
|
|
|
* Copyright (C) 2006-2007
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2009-07-03 11:45:47 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
#ifndef __JOYSTICK_H__
|
|
|
|
#define __JOYSTICK_H__
|
2009-12-22 03:17:35 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
#if SDL_VERSION_ATLEAST(1,3,0)
|
|
|
|
#include "SDL_haptic.h"
|
2009-07-03 11:45:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "onepad.h"
|
2009-07-10 06:07:32 +00:00
|
|
|
#include "controller.h"
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
// holds all joystick info
|
|
|
|
class JoystickInfo
|
|
|
|
{
|
|
|
|
public:
|
2011-04-10 00:09:17 +00:00
|
|
|
JoystickInfo() : devname(""), _id(-1), numbuttons(0), numaxes(0), numhats(0), axisrange(0x7fff),
|
2011-06-17 20:44:46 +00:00
|
|
|
deadzone(1500), pad(-1), joy(NULL) {
|
2011-06-12 14:48:36 +00:00
|
|
|
vbuttonstate.clear();
|
|
|
|
vaxisstate.clear();
|
|
|
|
vhatstate.clear();
|
|
|
|
#if SDL_VERSION_ATLEAST(1,3,0)
|
|
|
|
haptic = NULL;
|
|
|
|
for (int i = 0 ; i < 2 ; i++)
|
|
|
|
haptic_effect_id[i] = -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
~JoystickInfo()
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
2011-04-10 00:09:17 +00:00
|
|
|
JoystickInfo(const JoystickInfo&); // copy constructor
|
|
|
|
JoystickInfo& operator=(const JoystickInfo&); // assignment
|
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
void Destroy();
|
|
|
|
// opens handles to all possible joysticks
|
|
|
|
static void EnumerateJoysticks(vector<JoystickInfo*>& vjoysticks);
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
void InitHapticEffect();
|
|
|
|
static void DoHapticEffect(int type, int pad, int force);
|
|
|
|
|
2011-04-10 00:09:17 +00:00
|
|
|
bool Init(int id); // opens a handle and gets information
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
void TestForce();
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
bool PollButtons(u32 &pkey);
|
|
|
|
bool PollAxes(u32 &pkey);
|
|
|
|
bool PollHats(u32 &pkey);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
const string& GetName()
|
|
|
|
{
|
|
|
|
return devname;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
int GetNumButtons()
|
|
|
|
{
|
|
|
|
return numbuttons;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
int GetNumAxes()
|
|
|
|
{
|
|
|
|
return numaxes;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
int GetNumHats()
|
|
|
|
{
|
|
|
|
return numhats;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
int GetPAD()
|
|
|
|
{
|
|
|
|
return pad;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-06-17 20:44:46 +00:00
|
|
|
int GetDeadzone()
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
return deadzone;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveState();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
int GetButtonState(int i)
|
|
|
|
{
|
|
|
|
return vbuttonstate[i];
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
int GetAxisState(int i)
|
|
|
|
{
|
|
|
|
return vaxisstate[i];
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
int GetHatState(int i)
|
|
|
|
{
|
|
|
|
//PAD_LOG("Getting POV State of %d.\n", i);
|
2009-07-10 06:07:32 +00:00
|
|
|
set_hat_pins(vhatstate[i]);
|
2009-07-03 11:45:47 +00:00
|
|
|
return vhatstate[i];
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
void SetButtonState(int i, int state)
|
|
|
|
{
|
|
|
|
vbuttonstate[i] = state;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
void SetAxisState(int i, int value)
|
|
|
|
{
|
|
|
|
vaxisstate[i] = value;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
void SetHatState(int i, int value)
|
|
|
|
{
|
|
|
|
//PAD_LOG("We should set %d to %d.\n", i, value);
|
2009-07-10 06:07:32 +00:00
|
|
|
set_hat_pins(i);
|
2009-07-03 11:45:47 +00:00
|
|
|
vhatstate[i] = value;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
SDL_Joystick* GetJoy()
|
|
|
|
{
|
|
|
|
return joy;
|
|
|
|
}
|
2011-06-19 16:13:41 +00:00
|
|
|
|
2010-06-05 11:03:12 +00:00
|
|
|
int GetAxisFromKey(int pad, int index);
|
2011-06-19 16:13:41 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
private:
|
|
|
|
string devname; // pretty device name
|
|
|
|
int _id;
|
|
|
|
int numbuttons, numaxes, numhats;
|
|
|
|
int axisrange, deadzone;
|
|
|
|
int pad;
|
|
|
|
|
|
|
|
vector<int> vbuttonstate, vaxisstate, vhatstate;
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
SDL_Joystick* joy;
|
|
|
|
#if SDL_VERSION_ATLEAST(1,3,0)
|
|
|
|
SDL_Haptic* haptic;
|
|
|
|
SDL_HapticEffect haptic_effect_data[2];
|
|
|
|
int haptic_effect_id[2];
|
|
|
|
#endif
|
2009-07-03 11:45:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern int s_selectedpad;
|
|
|
|
extern vector<JoystickInfo*> s_vjoysticks;
|
|
|
|
extern void UpdateJoysticks();
|
|
|
|
extern const char *HatName(int value);
|
|
|
|
extern bool JoystickIdWithinBounds(int joyid);
|
|
|
|
#endif
|