2009-07-10 06:07:32 +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-10 06:07:32 +00:00
|
|
|
*/
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-05 11:03:12 +00:00
|
|
|
#include <string.h>
|
2009-07-10 06:07:32 +00:00
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
#include "GamePad.h"
|
2011-06-12 14:48:36 +00:00
|
|
|
#include "keyboard.h"
|
2009-07-10 06:07:32 +00:00
|
|
|
#include "onepad.h"
|
|
|
|
|
2010-05-22 02:52:47 +00:00
|
|
|
extern std::string s_strIniPath;
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
void DefaultKeyboardValues()
|
2009-07-10 06:07:32 +00:00
|
|
|
{
|
2017-05-02 20:29:45 +00:00
|
|
|
set_keyboard_key(0, XK_a, PAD_L2);
|
|
|
|
set_keyboard_key(0, XK_semicolon, PAD_R2);
|
|
|
|
set_keyboard_key(0, XK_w, PAD_L1);
|
|
|
|
set_keyboard_key(0, XK_p, PAD_R1);
|
|
|
|
set_keyboard_key(0, XK_i, PAD_TRIANGLE);
|
|
|
|
set_keyboard_key(0, XK_l, PAD_CIRCLE);
|
|
|
|
set_keyboard_key(0, XK_k, PAD_CROSS);
|
|
|
|
set_keyboard_key(0, XK_j, PAD_SQUARE);
|
|
|
|
set_keyboard_key(0, XK_v, PAD_SELECT);
|
|
|
|
set_keyboard_key(0, XK_n, PAD_START);
|
|
|
|
set_keyboard_key(0, XK_e, PAD_UP);
|
|
|
|
set_keyboard_key(0, XK_f, PAD_RIGHT);
|
|
|
|
set_keyboard_key(0, XK_d, PAD_DOWN);
|
|
|
|
set_keyboard_key(0, XK_s, PAD_LEFT);
|
2009-07-10 06:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SaveConfig()
|
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
FILE *f;
|
|
|
|
|
2017-04-15 12:57:00 +00:00
|
|
|
const std::string iniFile(s_strIniPath + "OnePAD2.ini");
|
2016-09-04 12:10:02 +00:00
|
|
|
f = fopen(iniFile.c_str(), "w");
|
|
|
|
if (f == NULL) {
|
|
|
|
printf("OnePAD: failed to save ini %s\n", iniFile.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-14 15:04:40 +00:00
|
|
|
fprintf(f, "first_time_wizard = %d\n", g_conf.ftw);
|
2017-05-03 09:59:58 +00:00
|
|
|
fprintf(f, "log = %d\n", g_conf.log);
|
|
|
|
fprintf(f, "options = %d\n", g_conf.packed_options);
|
|
|
|
fprintf(f, "mouse_sensibility = %d\n", g_conf.get_sensibility());
|
|
|
|
fprintf(f, "ff_intensity = %d\n", g_conf.get_ff_intensity());
|
|
|
|
fprintf(f, "uid[0] = %zu\n", g_conf.get_joy_uid(0));
|
|
|
|
fprintf(f, "uid[1] = %zu\n", g_conf.get_joy_uid(1));
|
2016-09-04 12:10:02 +00:00
|
|
|
|
|
|
|
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
|
2017-05-03 09:59:58 +00:00
|
|
|
for (auto const &it : g_conf.keysym_map[pad])
|
2017-04-14 20:10:08 +00:00
|
|
|
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it.first, it.second);
|
2016-09-04 12:10:02 +00:00
|
|
|
|
2017-05-03 09:59:58 +00:00
|
|
|
for (auto const &it : g_conf.sdl2_mapping)
|
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
|
|
|
fprintf(f, "SDL2 = %s\n", it.c_str());
|
|
|
|
|
2016-09-04 12:10:02 +00:00
|
|
|
fclose(f);
|
2009-07-10 06:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadConfig()
|
|
|
|
{
|
2016-09-04 12:10:02 +00:00
|
|
|
FILE *f;
|
|
|
|
bool have_user_setting = false;
|
|
|
|
|
2017-05-03 09:59:58 +00:00
|
|
|
g_conf.init();
|
2016-09-04 12:10:02 +00:00
|
|
|
|
2017-04-15 12:57:00 +00:00
|
|
|
const std::string iniFile(s_strIniPath + "OnePAD2.ini");
|
2016-09-04 12:10:02 +00:00
|
|
|
f = fopen(iniFile.c_str(), "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
|
2016-10-16 19:39:56 +00:00
|
|
|
SaveConfig(); //save and return
|
2016-09-04 12:10:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 value;
|
2017-07-14 15:04:40 +00:00
|
|
|
|
|
|
|
if (fscanf(f, "first_time_wizard = %u\n", &value) == 1)
|
|
|
|
g_conf.ftw = value;
|
|
|
|
|
2017-05-03 09:44:47 +00:00
|
|
|
if (fscanf(f, "log = %u\n", &value) == 1)
|
2017-05-03 09:59:58 +00:00
|
|
|
g_conf.log = value;
|
2017-05-03 09:44:47 +00:00
|
|
|
|
|
|
|
if (fscanf(f, "options = %u\n", &value) == 1)
|
2017-05-03 09:59:58 +00:00
|
|
|
g_conf.packed_options = value;
|
2017-05-03 09:44:47 +00:00
|
|
|
|
|
|
|
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 1)
|
2017-05-03 09:59:58 +00:00
|
|
|
g_conf.set_sensibility(value);
|
2017-05-03 09:44:47 +00:00
|
|
|
|
|
|
|
if (fscanf(f, "ff_intensity = %u\n", &value) == 1)
|
2017-05-03 09:59:58 +00:00
|
|
|
g_conf.set_ff_intensity(value);
|
2016-09-04 12:10:02 +00:00
|
|
|
|
2017-04-16 15:49:05 +00:00
|
|
|
size_t uid;
|
|
|
|
if (fscanf(f, "uid[0] = %zu\n", &uid) == 1)
|
2017-05-03 09:59:58 +00:00
|
|
|
g_conf.set_joy_uid(0, uid);
|
2017-04-16 15:49:05 +00:00
|
|
|
if (fscanf(f, "uid[1] = %zu\n", &uid) == 1)
|
2017-05-03 09:59:58 +00:00
|
|
|
g_conf.set_joy_uid(1, uid);
|
2016-09-04 12:10:02 +00:00
|
|
|
|
|
|
|
u32 pad;
|
|
|
|
u32 keysym;
|
|
|
|
u32 index;
|
2017-04-16 11:58:22 +00:00
|
|
|
while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) == 3) {
|
2017-05-02 20:29:45 +00:00
|
|
|
set_keyboard_key(pad & 1, keysym, index);
|
2016-09-04 12:10:02 +00:00
|
|
|
if (pad == 0)
|
|
|
|
have_user_setting = true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
char sdl2[512];
|
|
|
|
while (fscanf(f, "SDL2 = %511[^\n]\n", sdl2) == 1)
|
2017-05-03 09:59:58 +00:00
|
|
|
g_conf.sdl2_mapping.push_back(std::string(sdl2));
|
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
|
|
|
|
2016-09-04 12:10:02 +00:00
|
|
|
if (!have_user_setting)
|
|
|
|
DefaultKeyboardValues();
|
2015-09-10 12:21:27 +00:00
|
|
|
|
2016-09-04 12:10:02 +00:00
|
|
|
fclose(f);
|
2010-04-25 00:31:27 +00:00
|
|
|
}
|