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
|
|
|
*/
|
|
|
|
|
2015-10-14 11:11:09 +00:00
|
|
|
#pragma once
|
2016-10-16 19:39:56 +00:00
|
|
|
#include <string.h> // for memset
|
2011-06-12 14:48:36 +00:00
|
|
|
#define MAX_KEYS 24
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2017-05-02 20:29:45 +00:00
|
|
|
extern void set_keyboard_key(int pad, int keysym, int index);
|
2011-06-12 14:48:36 +00:00
|
|
|
extern int get_keyboard_key(int pad, int keysym);
|
|
|
|
extern bool IsAnalogKey(int index);
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2015-10-14 11:11:09 +00:00
|
|
|
class PADconf
|
2009-07-10 06:07:32 +00:00
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
u32 ff_intensity;
|
|
|
|
u32 sensibility;
|
|
|
|
|
|
|
|
public:
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u16 forcefeedback : 1;
|
|
|
|
u16 reverse_lx : 1;
|
|
|
|
u16 reverse_ly : 1;
|
|
|
|
u16 reverse_rx : 1;
|
|
|
|
u16 reverse_ry : 1;
|
|
|
|
u16 mouse_l : 1;
|
|
|
|
u16 mouse_r : 1;
|
2017-04-11 16:48:56 +00:00
|
|
|
u16 _free : 9; // The 9 remaining bits are unused, do what you wish with them ;)
|
2016-10-16 19:39:56 +00:00
|
|
|
} pad_options[GAMEPAD_NUMBER]; // One for each pads
|
|
|
|
u32 packed_options; // Only first 8 bits of each 16 bits series are really used, rest is padding
|
2016-09-04 12:10:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
u32 log;
|
2017-07-14 15:04:40 +00:00
|
|
|
u32 ftw;
|
2017-05-23 01:02:04 +00:00
|
|
|
std::map<u32, u32> keysym_map[GAMEPAD_NUMBER];
|
2017-04-16 15:49:05 +00:00
|
|
|
std::array<size_t, GAMEPAD_NUMBER> unique_id;
|
onepad: allow to save/reload SDL2 mapping from OnePAD2.ini file
SDL_GAMECONTROLLERCONFIG is nice but limited to a single entry. (Note it can still be used)
Option name is SDL2. Here an example
SDL2 = 03000000a306000020f6000011010000,PS2700 Rumble Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a4,start:b9,x:b0,y:b3,platform:Linux,
2017-05-03 09:47:16 +00:00
|
|
|
std::vector<std::string> sdl2_mapping;
|
2016-09-04 12:10:02 +00:00
|
|
|
|
|
|
|
PADconf() { init(); }
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
2017-07-14 15:04:40 +00:00
|
|
|
log = 0;
|
|
|
|
ftw = 1;
|
|
|
|
packed_options = 0;
|
2016-10-16 19:39:56 +00:00
|
|
|
ff_intensity = 0x7FFF; // set it at max value by default
|
2016-09-04 12:10:02 +00:00
|
|
|
sensibility = 500;
|
|
|
|
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
|
|
|
|
keysym_map[pad].clear();
|
|
|
|
}
|
2017-04-16 15:49:05 +00:00
|
|
|
unique_id.fill(0);
|
onepad: allow to save/reload SDL2 mapping from OnePAD2.ini file
SDL_GAMECONTROLLERCONFIG is nice but limited to a single entry. (Note it can still be used)
Option name is SDL2. Here an example
SDL2 = 03000000a306000020f6000011010000,PS2700 Rumble Pad,a:b1,b:b2,back:b8,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,guide:b12,leftshoulder:b4,leftstick:b10,lefttrigger:b6,leftx:a0,lefty:a1,rightshoulder:b5,rightstick:b11,righttrigger:b7,rightx:a2,righty:a4,start:b9,x:b0,y:b3,platform:Linux,
2017-05-03 09:47:16 +00:00
|
|
|
sdl2_mapping.clear();
|
2016-09-04 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-16 15:49:05 +00:00
|
|
|
void set_joy_uid(u32 pad, size_t uid)
|
2016-09-04 12:10:02 +00:00
|
|
|
{
|
2017-04-16 15:49:05 +00:00
|
|
|
if (pad < GAMEPAD_NUMBER)
|
|
|
|
unique_id[pad] = uid;
|
2016-09-04 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-16 15:49:05 +00:00
|
|
|
size_t get_joy_uid(u32 pad)
|
2016-09-04 12:10:02 +00:00
|
|
|
{
|
2017-04-16 15:49:05 +00:00
|
|
|
if (pad < GAMEPAD_NUMBER)
|
|
|
|
return unique_id[pad];
|
|
|
|
else
|
|
|
|
return 0;
|
2016-09-04 12:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-14 11:11:09 +00:00
|
|
|
* Return (a copy of) private memner ff_instensity
|
|
|
|
**/
|
2016-09-04 12:10:02 +00:00
|
|
|
u32 get_ff_intensity()
|
|
|
|
{
|
|
|
|
return ff_intensity;
|
|
|
|
}
|
2015-10-14 11:11:09 +00:00
|
|
|
|
2016-09-04 12:10:02 +00:00
|
|
|
/**
|
2015-10-14 11:11:09 +00:00
|
|
|
* Set intensity while checking that the new value is within
|
|
|
|
* valid range, more than 0x7FFF will cause pad not to rumble(and less than 0 is obviously bad)
|
|
|
|
**/
|
2016-09-04 12:10:02 +00:00
|
|
|
void set_ff_intensity(u32 new_intensity)
|
|
|
|
{
|
|
|
|
if (new_intensity <= 0x7FFF) {
|
|
|
|
ff_intensity = new_intensity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-14 11:11:09 +00:00
|
|
|
* Set sensibility value, sensibility is not yet implemented(and will probably be after evdev)
|
|
|
|
* However, there will be an upper range too, less than 0 is an obvious wrong
|
|
|
|
* Anyway, we are doing object oriented code, members are definitely not supposed to be public
|
|
|
|
**/
|
2016-09-04 12:10:02 +00:00
|
|
|
void set_sensibility(u32 new_sensibility)
|
|
|
|
{
|
|
|
|
if (sensibility > 0) {
|
|
|
|
sensibility = new_sensibility;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 get_sensibility()
|
|
|
|
{
|
|
|
|
return sensibility;
|
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
};
|
2017-05-03 09:59:58 +00:00
|
|
|
extern PADconf g_conf;
|