2009-05-07 23:37:57 +00:00
|
|
|
/* 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-08 16:34:39 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2009-05-07 23:37:57 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-29 08:39:32 +00:00
|
|
|
#ifndef __JOYSTICK_H__
|
|
|
|
#define __JOYSTICK_H__
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2009-05-29 08:39:32 +00:00
|
|
|
#ifdef __LINUX__
|
2009-05-07 23:37:57 +00:00
|
|
|
#include <SDL/SDL.h>
|
2009-05-29 08:39:32 +00:00
|
|
|
#else
|
|
|
|
#include <SDL.h>
|
|
|
|
#endif
|
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
#include "zeropad.h"
|
|
|
|
|
|
|
|
// holds all joystick info
|
|
|
|
class JoystickInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
JoystickInfo();
|
|
|
|
~JoystickInfo()
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
// opens handles to all possible joysticks
|
|
|
|
static void EnumerateJoysticks(vector<JoystickInfo*>& vjoysticks);
|
|
|
|
|
|
|
|
bool Init(int id, bool bStartThread = true); // opens a handle and gets information
|
|
|
|
void Assign(int pad); // assigns a joystick to a pad
|
|
|
|
|
|
|
|
void TestForce();
|
|
|
|
|
2009-05-25 01:59:17 +00:00
|
|
|
bool PollButtons(int &jbutton, u32 &pkey);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-25 01:59:17 +00:00
|
|
|
bool PollAxes(bool pov, int &jbutton, bool &negative, u32 &pkey);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-25 01:59:17 +00:00
|
|
|
bool PollHats(int &jbutton, int &dir, u32 &pkey);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
const string& GetName()
|
|
|
|
{
|
|
|
|
return devname;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
int GetNumButtons()
|
|
|
|
{
|
|
|
|
return numbuttons;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
int GetNumAxes()
|
|
|
|
{
|
|
|
|
return numaxes;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-25 01:59:17 +00:00
|
|
|
int GetNumHats()
|
2009-05-07 23:37:57 +00:00
|
|
|
{
|
2009-05-25 01:59:17 +00:00
|
|
|
return numhats;
|
2009-05-07 23:37:57 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
int GetId()
|
|
|
|
{
|
|
|
|
return _id;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
int GetPAD()
|
|
|
|
{
|
|
|
|
return pad;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
int GetDeadzone(int axis)
|
|
|
|
{
|
|
|
|
return deadzone;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SaveState();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
int GetButtonState(int i)
|
|
|
|
{
|
2009-05-25 01:59:17 +00:00
|
|
|
return vbuttonstate[i];
|
2009-05-07 23:37:57 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
int GetAxisState(int i)
|
|
|
|
{
|
|
|
|
return vaxisstate[i];
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-25 01:59:17 +00:00
|
|
|
int GetHatState(int i)
|
2009-05-07 23:37:57 +00:00
|
|
|
{
|
2009-05-09 22:44:06 +00:00
|
|
|
//PAD_LOG("Getting POV State of %d.\n", i);
|
2009-05-25 01:59:17 +00:00
|
|
|
return vhatstate[i];
|
2009-05-09 20:06:57 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
void SetButtonState(int i, int state)
|
|
|
|
{
|
2009-05-25 01:59:17 +00:00
|
|
|
vbuttonstate[i] = state;
|
2009-05-07 23:37:57 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
void SetAxisState(int i, int value)
|
|
|
|
{
|
|
|
|
vaxisstate[i] = value;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-25 01:59:17 +00:00
|
|
|
void SetHatState(int i, int value)
|
2009-05-07 23:37:57 +00:00
|
|
|
{
|
2009-05-09 22:44:06 +00:00
|
|
|
//PAD_LOG("We should set %d to %d.\n", i, value);
|
2009-05-25 01:59:17 +00:00
|
|
|
vhatstate[i] = value;
|
2009-05-09 20:06:57 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-05-07 23:37:57 +00:00
|
|
|
SDL_Joystick* GetJoy()
|
|
|
|
{
|
|
|
|
return joy;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
string devname; // pretty device name
|
|
|
|
int _id;
|
2009-05-25 01:59:17 +00:00
|
|
|
int numbuttons, numaxes, numhats;
|
2009-05-07 23:37:57 +00:00
|
|
|
int axisrange, deadzone;
|
|
|
|
int pad;
|
|
|
|
|
2009-05-25 01:59:17 +00:00
|
|
|
vector<int> vbuttonstate, vaxisstate, vhatstate;
|
2009-05-07 23:37:57 +00:00
|
|
|
|
|
|
|
SDL_Joystick* joy;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern int s_selectedpad;
|
|
|
|
extern vector<JoystickInfo*> s_vjoysticks;
|
2009-05-25 01:59:17 +00:00
|
|
|
extern void UpdateJoysticks();
|
|
|
|
extern const char *HatName(int value);
|
2009-05-29 06:33:56 +00:00
|
|
|
extern bool JoystickIdWithinBounds(int joyid);
|
2009-05-10 05:57:57 +00:00
|
|
|
#endif
|