reformat onepad

This commit is contained in:
Clang Format 2016-09-04 14:10:02 +02:00 committed by Gregory Hainaut
parent 0abf686406
commit f06f44c30a
25 changed files with 2226 additions and 2291 deletions

View File

@ -1,12 +1,12 @@
#include "GamePad.h" #include "GamePad.h"
#ifdef SDL_BUILD #ifdef SDL_BUILD
#include "SDL/joystick.h" #include "SDL/joystick.h"
#endif #endif
vector<GamePad*> s_vgamePad; vector<GamePad *> s_vgamePad;
bool GamePadIdWithinBounds(int GamePadId) bool GamePadIdWithinBounds(int GamePadId)
{ {
return ((GamePadId >= 0) && (GamePadId < (int)s_vgamePad.size())); return ((GamePadId >= 0) && (GamePadId < (int)s_vgamePad.size()));
} }
/** /**
@ -17,17 +17,17 @@ bool GamePadIdWithinBounds(int GamePadId)
/** /**
* Find every interesting devices and create right structure for them(depend on backend) * Find every interesting devices and create right structure for them(depend on backend)
**/ **/
void GamePad::EnumerateGamePads(vector<GamePad*>& vgamePad) void GamePad::EnumerateGamePads(vector<GamePad *> &vgamePad)
{ {
#ifdef SDL_BUILD #ifdef SDL_BUILD
JoystickInfo::EnumerateJoysticks(vgamePad); JoystickInfo::EnumerateJoysticks(vgamePad);
#endif #endif
} }
void GamePad::UpdateReleaseState() void GamePad::UpdateReleaseState()
{ {
#ifdef SDL_BUILD #ifdef SDL_BUILD
JoystickInfo::UpdateReleaseState(); JoystickInfo::UpdateReleaseState();
#endif #endif
} }
@ -36,12 +36,12 @@ void GamePad::UpdateReleaseState()
**/ **/
void GamePad::DoRumble(int type, int pad) void GamePad::DoRumble(int type, int pad)
{ {
u32 id = conf->get_joyid(pad); u32 id = conf->get_joyid(pad);
if (GamePadIdWithinBounds(id)) { if (GamePadIdWithinBounds(id)) {
GamePad* gamePad = s_vgamePad[id]; GamePad *gamePad = s_vgamePad[id];
if (gamePad) if (gamePad)
gamePad->Rumble(type, pad); gamePad->Rumble(type, pad);
} }
} }
/** /**
@ -49,9 +49,7 @@ void GamePad::DoRumble(int type, int pad)
**/ **/
void GamePad::UpdateGamePadState() void GamePad::UpdateGamePadState()
{ {
#ifdef SDL_BUILD #ifdef SDL_BUILD
SDL_JoystickUpdate(); // No need to make yet another function call for that SDL_JoystickUpdate(); // No need to make yet another function call for that
#endif #endif
} }

View File

@ -2,7 +2,7 @@
#include "onepad.h" #include "onepad.h"
#include "controller.h" #include "controller.h"
#ifdef SDL_BUILD #ifdef SDL_BUILD
#include <SDL.h> #include <SDL.h>
#define HAT_UP SDL_HAT_UP #define HAT_UP SDL_HAT_UP
#define HAT_DOWN SDL_HAT_DOWN #define HAT_DOWN SDL_HAT_DOWN
@ -12,137 +12,144 @@
class GamePad class GamePad
{ {
public: public:
GamePad() : devname(""), _id(-1), numbuttons(0), numaxes(0), numhats(0), GamePad()
deadzone(1500), pad(-1) { : devname("")
vbuttonstate.clear(); , _id(-1)
vaxisstate.clear(); , numbuttons(0)
vhatstate.clear(); , numaxes(0)
} , numhats(0)
, deadzone(1500)
, pad(-1)
{
vbuttonstate.clear();
vaxisstate.clear();
vhatstate.clear();
}
virtual ~GamePad() virtual ~GamePad()
{ {
return; return;
} }
GamePad(const GamePad&); // copy constructor GamePad(const GamePad &); // copy constructor
GamePad& operator=(const GamePad&); // assignment GamePad &operator=(const GamePad &); // assignment
/** /**
* Find every interesting devices and create right structure for them(depend on backend) * Find every interesting devices and create right structure for them(depend on backend)
**/ **/
static void EnumerateGamePads(vector<GamePad*>& vgamePad); static void EnumerateGamePads(vector<GamePad *> &vgamePad);
static void UpdateReleaseState(); static void UpdateReleaseState();
/** /**
* Update state of every attached devices * Update state of every attached devices
**/ **/
static void UpdateGamePadState(); static void UpdateGamePadState();
/** /**
* Causes devices to rumble * Causes devices to rumble
* Rumble will differ according to type which is either 0(small motor) or 1(big motor) * Rumble will differ according to type which is either 0(small motor) or 1(big motor)
**/ **/
virtual void Rumble(int type,int pad){return;} virtual void Rumble(int type, int pad) { return; }
/** /**
* Safely dispatch to the Rumble method above * Safely dispatch to the Rumble method above
**/ **/
static void DoRumble(int type, int pad); static void DoRumble(int type, int pad);
virtual bool Init(int id){return false;} // opens a handle and gets information virtual bool Init(int id) { return false; } // opens a handle and gets information
/** /**
* Used for GUI checkbox to give feedback to the user * Used for GUI checkbox to give feedback to the user
**/ **/
virtual bool TestForce(float strength = 0.6){return false;} virtual bool TestForce(float strength = 0.6) { return false; }
virtual bool PollButtons(u32 &pkey){return false;} virtual bool PollButtons(u32 &pkey) { return false; }
virtual bool PollAxes(u32 &pkey){return false;} virtual bool PollAxes(u32 &pkey) { return false; }
virtual bool PollHats(u32 &pkey){return false;} virtual bool PollHats(u32 &pkey) { return false; }
virtual int GetHat(int key_to_axis) virtual int GetHat(int key_to_axis)
{ {
return 0; return 0;
} }
virtual int GetButton(int key_to_button) virtual int GetButton(int key_to_button)
{ {
return 0; return 0;
} }
const string& GetName() const string &GetName()
{ {
return devname; return devname;
} }
int GetPAD() int GetPAD()
{ {
return pad; return pad;
} }
int GetNumButtons() int GetNumButtons()
{ {
return numbuttons; return numbuttons;
} }
int GetNumAxes() int GetNumAxes()
{ {
return numaxes; return numaxes;
} }
int GetNumHats() int GetNumHats()
{ {
return numhats; return numhats;
} }
virtual int GetDeadzone() virtual int GetDeadzone()
{ {
return deadzone; return deadzone;
} }
virtual void SaveState() {} virtual void SaveState() {}
int GetButtonState(int i) int GetButtonState(int i)
{ {
return vbuttonstate[i]; return vbuttonstate[i];
} }
int GetAxisState(int i) int GetAxisState(int i)
{ {
return vaxisstate[i]; return vaxisstate[i];
} }
int GetHatState(int i) int GetHatState(int i)
{ {
//PAD_LOG("Getting POV State of %d.\n", i); //PAD_LOG("Getting POV State of %d.\n", i);
return vhatstate[i]; return vhatstate[i];
} }
void SetButtonState(int i, int state) void SetButtonState(int i, int state)
{ {
vbuttonstate[i] = state; vbuttonstate[i] = state;
} }
void SetAxisState(int i, int value) void SetAxisState(int i, int value)
{ {
vaxisstate[i] = value; vaxisstate[i] = value;
} }
void SetHatState(int i, int value) void SetHatState(int i, int value)
{ {
//PAD_LOG("We should set %d to %d.\n", i, value); //PAD_LOG("We should set %d to %d.\n", i, value);
vhatstate[i] = value; vhatstate[i] = value;
} }
virtual int GetAxisFromKey(int pad, int index){return 0;} virtual int GetAxisFromKey(int pad, int index) { return 0; }
// These fields need to be inherited by child classes // These fields need to be inherited by child classes
protected: protected:
string devname; // pretty device name string devname; // pretty device name
int _id; int _id;
int numbuttons, numaxes, numhats; int numbuttons, numaxes, numhats;
int deadzone; int deadzone;
int pad; int pad;
vector<int> vbuttonstate, vaxisstate, vhatstate; vector<int> vbuttonstate, vaxisstate, vhatstate;
}; };
extern vector<GamePad*> s_vgamePad; extern vector<GamePad *> s_vgamePad;
extern bool GamePadIdWithinBounds(int joyid); extern bool GamePadIdWithinBounds(int joyid);

View File

@ -23,164 +23,176 @@
void KeyStatus::Init() void KeyStatus::Init()
{ {
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
m_button[pad] = 0xFFFF; m_button[pad] = 0xFFFF;
m_internal_button_kbd[pad] = 0xFFFF; m_internal_button_kbd[pad] = 0xFFFF;
m_internal_button_joy[pad] = 0xFFFF; m_internal_button_joy[pad] = 0xFFFF;
m_state_acces[pad] = false; m_state_acces[pad] = false;
for (int index = 0; index < MAX_KEYS; index++) { for (int index = 0; index < MAX_KEYS; index++) {
m_button_pressure[pad][index] = 0xFF; m_button_pressure[pad][index] = 0xFF;
m_internal_button_pressure[pad][index] = 0xFF; m_internal_button_pressure[pad][index] = 0xFF;
} }
m_analog[pad].lx = m_analog_released_val; m_analog[pad].lx = m_analog_released_val;
m_analog[pad].ly = m_analog_released_val; m_analog[pad].ly = m_analog_released_val;
m_analog[pad].rx = m_analog_released_val; m_analog[pad].rx = m_analog_released_val;
m_analog[pad].ry = m_analog_released_val; m_analog[pad].ry = m_analog_released_val;
m_internal_analog_kbd[pad].lx = m_analog_released_val; m_internal_analog_kbd[pad].lx = m_analog_released_val;
m_internal_analog_kbd[pad].ly = m_analog_released_val; m_internal_analog_kbd[pad].ly = m_analog_released_val;
m_internal_analog_kbd[pad].rx = m_analog_released_val; m_internal_analog_kbd[pad].rx = m_analog_released_val;
m_internal_analog_kbd[pad].ry = m_analog_released_val; m_internal_analog_kbd[pad].ry = m_analog_released_val;
m_internal_analog_joy[pad].lx = m_analog_released_val; m_internal_analog_joy[pad].lx = m_analog_released_val;
m_internal_analog_joy[pad].ly = m_analog_released_val; m_internal_analog_joy[pad].ly = m_analog_released_val;
m_internal_analog_joy[pad].rx = m_analog_released_val; m_internal_analog_joy[pad].rx = m_analog_released_val;
m_internal_analog_joy[pad].ry = m_analog_released_val; m_internal_analog_joy[pad].ry = m_analog_released_val;
} }
} }
void KeyStatus::press(u32 pad, u32 index, s32 value) void KeyStatus::press(u32 pad, u32 index, s32 value)
{ {
if (!IsAnalogKey(index)) { if (!IsAnalogKey(index)) {
m_internal_button_pressure[pad][index] = value; m_internal_button_pressure[pad][index] = value;
if (m_state_acces[pad]) if (m_state_acces[pad])
clear_bit(m_internal_button_kbd[pad], index); clear_bit(m_internal_button_kbd[pad], index);
else else
clear_bit(m_internal_button_joy[pad], index); clear_bit(m_internal_button_joy[pad], index);
} else { } else {
// clamp value // clamp value
if (value > MAX_ANALOG_VALUE) if (value > MAX_ANALOG_VALUE)
value = MAX_ANALOG_VALUE; value = MAX_ANALOG_VALUE;
else if (value < -MAX_ANALOG_VALUE) else if (value < -MAX_ANALOG_VALUE)
value = -MAX_ANALOG_VALUE; value = -MAX_ANALOG_VALUE;
// Left -> -- -> Right // Left -> -- -> Right
// Value range : FFFF8002 -> 0 -> 7FFE // Value range : FFFF8002 -> 0 -> 7FFE
// Force range : 80 -> 0 -> 7F // Force range : 80 -> 0 -> 7F
// Normal mode : expect value 0 -> 80 -> FF // Normal mode : expect value 0 -> 80 -> FF
// Reverse mode: expect value FF -> 7F -> 0 // Reverse mode: expect value FF -> 7F -> 0
u8 force = (value / 256); u8 force = (value / 256);
if (analog_is_reversed(pad,index)) if (analog_is_reversed(pad, index))
analog_set(pad, index, m_analog_released_val - force); analog_set(pad, index, m_analog_released_val - force);
else else
analog_set(pad, index, m_analog_released_val + force); analog_set(pad, index, m_analog_released_val + force);
} }
} }
void KeyStatus::release(u32 pad, u32 index) void KeyStatus::release(u32 pad, u32 index)
{ {
if (!IsAnalogKey(index)) { if (!IsAnalogKey(index)) {
if (m_state_acces[pad]) if (m_state_acces[pad])
set_bit(m_internal_button_kbd[pad], index); set_bit(m_internal_button_kbd[pad], index);
else else
set_bit(m_internal_button_joy[pad], index); set_bit(m_internal_button_joy[pad], index);
} else { } else {
analog_set(pad, index, m_analog_released_val); analog_set(pad, index, m_analog_released_val);
} }
} }
u16 KeyStatus::get(u32 pad) u16 KeyStatus::get(u32 pad)
{ {
return m_button[pad]; return m_button[pad];
} }
void KeyStatus::analog_set(u32 pad, u32 index, u8 value) void KeyStatus::analog_set(u32 pad, u32 index, u8 value)
{ {
PADAnalog* m_internal_analog_ref; PADAnalog *m_internal_analog_ref;
if (m_state_acces[pad]) if (m_state_acces[pad])
m_internal_analog_ref = &m_internal_analog_kbd[pad]; m_internal_analog_ref = &m_internal_analog_kbd[pad];
else else
m_internal_analog_ref = &m_internal_analog_joy[pad]; m_internal_analog_ref = &m_internal_analog_joy[pad];
switch (index) switch (index) {
{ case PAD_R_LEFT:
case PAD_R_LEFT: case PAD_R_RIGHT:
case PAD_R_RIGHT: m_internal_analog_ref->rx = value; break; m_internal_analog_ref->rx = value;
break;
case PAD_R_DOWN: case PAD_R_DOWN:
case PAD_R_UP: m_internal_analog_ref->ry = value; break; case PAD_R_UP:
m_internal_analog_ref->ry = value;
break;
case PAD_L_LEFT: case PAD_L_LEFT:
case PAD_L_RIGHT: m_internal_analog_ref->lx = value; break; case PAD_L_RIGHT:
m_internal_analog_ref->lx = value;
break;
case PAD_L_DOWN: case PAD_L_DOWN:
case PAD_L_UP: m_internal_analog_ref->ly = value; break; case PAD_L_UP:
m_internal_analog_ref->ly = value;
break;
default: break; default:
} break;
}
} }
bool KeyStatus::analog_is_reversed(u32 pad, u32 index) bool KeyStatus::analog_is_reversed(u32 pad, u32 index)
{ {
switch (index) switch (index) {
{ case PAD_L_RIGHT:
case PAD_L_RIGHT: case PAD_L_LEFT:
case PAD_L_LEFT: return (conf->pad_options[pad].reverse_lx);
return (conf->pad_options[pad].reverse_lx);
case PAD_R_LEFT: case PAD_R_LEFT:
case PAD_R_RIGHT: case PAD_R_RIGHT:
return (conf->pad_options[pad].reverse_rx); return (conf->pad_options[pad].reverse_rx);
case PAD_L_UP: case PAD_L_UP:
case PAD_L_DOWN: case PAD_L_DOWN:
return (conf->pad_options[pad].reverse_ly); return (conf->pad_options[pad].reverse_ly);
case PAD_R_DOWN: case PAD_R_DOWN:
case PAD_R_UP: case PAD_R_UP:
return (conf->pad_options[pad].reverse_ry); return (conf->pad_options[pad].reverse_ry);
default: return false; default:
} return false;
}
} }
u8 KeyStatus::get(u32 pad, u32 index) u8 KeyStatus::get(u32 pad, u32 index)
{ {
switch (index) switch (index) {
{ case PAD_R_LEFT:
case PAD_R_LEFT: case PAD_R_RIGHT:
case PAD_R_RIGHT: return m_analog[pad].rx; return m_analog[pad].rx;
case PAD_R_DOWN: case PAD_R_DOWN:
case PAD_R_UP: return m_analog[pad].ry; case PAD_R_UP:
return m_analog[pad].ry;
case PAD_L_LEFT: case PAD_L_LEFT:
case PAD_L_RIGHT: return m_analog[pad].lx; case PAD_L_RIGHT:
return m_analog[pad].lx;
case PAD_L_DOWN: case PAD_L_DOWN:
case PAD_L_UP: return m_analog[pad].ly; case PAD_L_UP:
return m_analog[pad].ly;
default: return m_button_pressure[pad][index]; default:
} return m_button_pressure[pad][index];
}
} }
u8 KeyStatus::analog_merge(u8 kbd, u8 joy) u8 KeyStatus::analog_merge(u8 kbd, u8 joy)
{ {
if (kbd != m_analog_released_val) if (kbd != m_analog_released_val)
return kbd; return kbd;
else else
return joy; return joy;
} }
void KeyStatus::commit_status(u32 pad) void KeyStatus::commit_status(u32 pad)
{ {
m_button[pad] = m_internal_button_kbd[pad] & m_internal_button_joy[pad]; m_button[pad] = m_internal_button_kbd[pad] & m_internal_button_joy[pad];
for (int index = 0; index < MAX_KEYS; index++) for (int index = 0; index < MAX_KEYS; index++)
m_button_pressure[pad][index] = m_internal_button_pressure[pad][index]; m_button_pressure[pad][index] = m_internal_button_pressure[pad][index];
m_analog[pad].lx = analog_merge(m_internal_analog_kbd[pad].lx, m_internal_analog_joy[pad].lx); m_analog[pad].lx = analog_merge(m_internal_analog_kbd[pad].lx, m_internal_analog_joy[pad].lx);
m_analog[pad].ly = analog_merge(m_internal_analog_kbd[pad].ly, m_internal_analog_joy[pad].ly); m_analog[pad].ly = analog_merge(m_internal_analog_kbd[pad].ly, m_internal_analog_joy[pad].ly);
m_analog[pad].rx = analog_merge(m_internal_analog_kbd[pad].rx, m_internal_analog_joy[pad].rx); m_analog[pad].rx = analog_merge(m_internal_analog_kbd[pad].rx, m_internal_analog_joy[pad].rx);
m_analog[pad].ry = analog_merge(m_internal_analog_kbd[pad].ry, m_internal_analog_joy[pad].ry); m_analog[pad].ry = analog_merge(m_internal_analog_kbd[pad].ry, m_internal_analog_joy[pad].ry);
} }

View File

@ -26,51 +26,55 @@
typedef struct typedef struct
{ {
u8 lx, ly; u8 lx, ly;
u8 rx, ry; u8 rx, ry;
} PADAnalog; } PADAnalog;
#define MAX_ANALOG_VALUE 32766 #define MAX_ANALOG_VALUE 32766
class KeyStatus class KeyStatus
{ {
private: private:
const u8 m_analog_released_val; const u8 m_analog_released_val;
u16 m_button[GAMEPAD_NUMBER]; u16 m_button[GAMEPAD_NUMBER];
u16 m_internal_button_kbd[GAMEPAD_NUMBER]; u16 m_internal_button_kbd[GAMEPAD_NUMBER];
u16 m_internal_button_joy[GAMEPAD_NUMBER]; u16 m_internal_button_joy[GAMEPAD_NUMBER];
u8 m_button_pressure[GAMEPAD_NUMBER][MAX_KEYS]; u8 m_button_pressure[GAMEPAD_NUMBER][MAX_KEYS];
u8 m_internal_button_pressure[GAMEPAD_NUMBER][MAX_KEYS]; u8 m_internal_button_pressure[GAMEPAD_NUMBER][MAX_KEYS];
bool m_state_acces[GAMEPAD_NUMBER]; bool m_state_acces[GAMEPAD_NUMBER];
PADAnalog m_analog[GAMEPAD_NUMBER]; PADAnalog m_analog[GAMEPAD_NUMBER];
PADAnalog m_internal_analog_kbd[GAMEPAD_NUMBER]; PADAnalog m_internal_analog_kbd[GAMEPAD_NUMBER];
PADAnalog m_internal_analog_joy[GAMEPAD_NUMBER]; PADAnalog m_internal_analog_joy[GAMEPAD_NUMBER];
void analog_set(u32 pad, u32 index, u8 value); void analog_set(u32 pad, u32 index, u8 value);
bool analog_is_reversed(u32 pad, u32 index); bool analog_is_reversed(u32 pad, u32 index);
u8 analog_merge(u8 kbd, u8 joy); u8 analog_merge(u8 kbd, u8 joy);
public: public:
KeyStatus() : m_analog_released_val(0x7F) { Init(); } KeyStatus()
void Init(); : m_analog_released_val(0x7F)
{
Init();
}
void Init();
void keyboard_state_acces(u32 pad) { m_state_acces[pad] = true; } void keyboard_state_acces(u32 pad) { m_state_acces[pad] = true; }
void joystick_state_acces(u32 pad) { m_state_acces[pad] = false; } void joystick_state_acces(u32 pad) { m_state_acces[pad] = false; }
void press(u32 pad, u32 index, s32 value = 0xFF); void press(u32 pad, u32 index, s32 value = 0xFF);
void release(u32 pad, u32 index); void release(u32 pad, u32 index);
u16 get(u32 pad); u16 get(u32 pad);
u8 get(u32 pad, u32 index); u8 get(u32 pad, u32 index);
void commit_status(u32 pad); void commit_status(u32 pad);
}; };
extern KeyStatus* key_status; extern KeyStatus *key_status;
#endif #endif

View File

@ -20,101 +20,101 @@
#include "GamepadConfiguration.h" #include "GamepadConfiguration.h"
// Construtor of GamepadConfiguration // Construtor of GamepadConfiguration
GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxDialog( GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent)
parent, // Parent : wxDialog(
wxID_ANY, // ID parent, // Parent
_T("Gamepad configuration"), // Title wxID_ANY, // ID
wxDefaultPosition, // Position _T("Gamepad configuration"), // Title
wxSize(400, 230), // Width + Lenght wxDefaultPosition, // Position
// Style wxSize(400, 230), // Width + Lenght
wxSYSTEM_MENU | // Style
wxCAPTION | wxSYSTEM_MENU |
wxCLOSE_BOX | wxCAPTION |
wxCLIP_CHILDREN wxCLOSE_BOX |
) wxCLIP_CHILDREN)
{ {
m_pad_id = pad; m_pad_id = pad;
m_pan_gamepad_config = new wxPanel( m_pan_gamepad_config = new wxPanel(
this, // Parent this, // Parent
wxID_ANY, // ID wxID_ANY, // ID
wxDefaultPosition, // Prosition wxDefaultPosition, // Prosition
wxSize(300, 200) // Size wxSize(300, 200) // Size
); );
m_cb_rumble = new wxCheckBox( m_cb_rumble = new wxCheckBox(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Enable rumble"), // Label _T("&Enable rumble"), // Label
wxPoint(20, 20) // Position wxPoint(20, 20) // Position
); );
m_cb_hack_sixaxis_usb = new wxCheckBox( m_cb_hack_sixaxis_usb = new wxCheckBox(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Hack: Sixaxis/DS3 plugged in USB"), // Label _T("&Hack: Sixaxis/DS3 plugged in USB"), // Label
wxPoint(20, 40) // Position wxPoint(20, 40) // Position
); );
m_cb_hack_sixaxis_pressure = new wxCheckBox( m_cb_hack_sixaxis_pressure = new wxCheckBox(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Hack: Sixaxis/DS3 pressure"), // Label _T("&Hack: Sixaxis/DS3 pressure"), // Label
wxPoint(20, 60) // Position wxPoint(20, 60) // Position
); );
wxString txt_rumble = wxT("Rumble intensity"); wxString txt_rumble = wxT("Rumble intensity");
m_lbl_rumble_intensity = new wxStaticText( m_lbl_rumble_intensity = new wxStaticText(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
txt_rumble, // Text which must be displayed txt_rumble, // Text which must be displayed
wxPoint(20, 90), // Position wxPoint(20, 90), // Position
wxDefaultSize // Size wxDefaultSize // Size
); );
m_sl_rumble_intensity = new wxSlider( m_sl_rumble_intensity = new wxSlider(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
0, // value 0, // value
0, // min value 0x0000 0, // min value 0x0000
0x7FFF, // max value 0x7FFF 0x7FFF, // max value 0x7FFF
wxPoint(150, 83), // Position wxPoint(150, 83), // Position
wxSize(200, 30) // Size wxSize(200, 30) // Size
); );
wxString txt_joystick = wxT("Joystick sensibility"); wxString txt_joystick = wxT("Joystick sensibility");
m_lbl_rumble_intensity = new wxStaticText( m_lbl_rumble_intensity = new wxStaticText(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
txt_joystick, // Text which must be displayed txt_joystick, // Text which must be displayed
wxPoint(20, 120), // Position wxPoint(20, 120), // Position
wxDefaultSize // Size wxDefaultSize // Size
); );
m_sl_joystick_sensibility = new wxSlider( m_sl_joystick_sensibility = new wxSlider(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
0, // value 0, // value
0, // min value 0, // min value
100, // max value 100, // max value
wxPoint(150, 113), // Position wxPoint(150, 113), // Position
wxSize(200, 30) // Size wxSize(200, 30) // Size
); );
m_bt_ok = new wxButton( m_bt_ok = new wxButton(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&OK"), // Label _T("&OK"), // Label
wxPoint(250, 160), // Position wxPoint(250, 160), // Position
wxSize(60,25) // Size wxSize(60, 25) // Size
); );
m_bt_cancel = new wxButton( m_bt_cancel = new wxButton(
m_pan_gamepad_config, // Parent m_pan_gamepad_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Cancel"), // Label _T("&Cancel"), // Label
wxPoint(320, 160), // Position wxPoint(320, 160), // Position
wxSize(60,25) // Size wxSize(60, 25) // Size
); );
Bind(wxEVT_BUTTON, &GamepadConfiguration::OnButtonClicked, this); Bind(wxEVT_BUTTON, &GamepadConfiguration::OnButtonClicked, this);
Bind(wxEVT_SCROLL_THUMBRELEASE, &GamepadConfiguration::OnSliderReleased, this); Bind(wxEVT_SCROLL_THUMBRELEASE, &GamepadConfiguration::OnSliderReleased, this);
@ -130,34 +130,30 @@ GamepadConfiguration::GamepadConfiguration(int pad, wxWindow *parent) : wxDialog
*/ */
void GamepadConfiguration::InitGamepadConfiguration() void GamepadConfiguration::InitGamepadConfiguration()
{ {
repopulate(); // Set label and fit simulated key array repopulate(); // Set label and fit simulated key array
/* /*
* Check if there exist at least one pad available * Check if there exist at least one pad available
* if the pad id is 0, you need at least 1 gamepad connected, * if the pad id is 0, you need at least 1 gamepad connected,
* if the pad id is 1, you need at least 2 gamepad connected, * if the pad id is 1, you need at least 2 gamepad connected,
* Prevent to use a none initialized value on s_vgamePad (core dump) * Prevent to use a none initialized value on s_vgamePad (core dump)
*/ */
if(s_vgamePad.size() >= m_pad_id+1) if (s_vgamePad.size() >= m_pad_id + 1) {
{
/* /*
* Determine if the device can use rumble * Determine if the device can use rumble
* Use TestForce with a very low strength (can't be felt) * Use TestForce with a very low strength (can't be felt)
* May be better to create a new function in order to check only that * May be better to create a new function in order to check only that
*/ */
if(!s_vgamePad[m_pad_id]->TestForce(0.001f)) if (!s_vgamePad[m_pad_id]->TestForce(0.001f)) {
{
wxMessageBox(L"Rumble is not available for your device."); wxMessageBox(L"Rumble is not available for your device.");
m_cb_rumble->Disable(); // disable the rumble checkbox m_cb_rumble->Disable(); // disable the rumble checkbox
m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
} }
} } else {
else
{
wxMessageBox(L"No gamepad detected."); wxMessageBox(L"No gamepad detected.");
m_sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider m_sl_joystick_sensibility->Disable(); // disable the joystick sensibility slider
m_cb_rumble->Disable(); // disable the rumble checkbox m_cb_rumble->Disable(); // disable the rumble checkbox
m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider m_sl_rumble_intensity->Disable(); // disable the rumble intensity slider
} }
} }
@ -171,13 +167,13 @@ void GamepadConfiguration::InitGamepadConfiguration()
void GamepadConfiguration::OnButtonClicked(wxCommandEvent &event) void GamepadConfiguration::OnButtonClicked(wxCommandEvent &event)
{ {
// Affichage d'un message à chaque clic sur le bouton // Affichage d'un message à chaque clic sur le bouton
wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId(); // get the real ID int bt_id = bt_tmp->GetId(); // get the real ID
if(bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID
Close(); // Close the window Close(); // Close the window
} else if(bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID } else if (bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID
reset(); // reinitialize the value of each parameters reset(); // reinitialize the value of each parameters
Close(); // Close the window Close(); // Close the window
} }
} }
@ -188,12 +184,12 @@ void GamepadConfiguration::OnButtonClicked(wxCommandEvent &event)
*/ */
void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event) void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
{ {
wxSlider* sl_tmp = (wxSlider*)event.GetEventObject(); // get the slider object wxSlider *sl_tmp = (wxSlider *)event.GetEventObject(); // get the slider object
int sl_id = sl_tmp->GetId(); // slider id int sl_id = sl_tmp->GetId(); // slider id
if(sl_id == m_sl_rumble_intensity->GetId()) { // if this is the rumble intensity slider if (sl_id == m_sl_rumble_intensity->GetId()) { // if this is the rumble intensity slider
u32 intensity = m_sl_rumble_intensity->GetValue(); // get the new value u32 intensity = m_sl_rumble_intensity->GetValue(); // get the new value
conf->set_ff_intensity(intensity); // and set the force feedback intensity value with it conf->set_ff_intensity(intensity); // and set the force feedback intensity value with it
// get the rumble intensity // get the rumble intensity
float strength = m_sl_rumble_intensity->GetValue(); float strength = m_sl_rumble_intensity->GetValue();
/* /*
* convert in a float value between 0 and 1, and run rumble feedback * convert in a float value between 0 and 1, and run rumble feedback
@ -206,40 +202,32 @@ void GamepadConfiguration::OnSliderReleased(wxCommandEvent &event)
* 0x7FFF : maximum intensity * 0x7FFF : maximum intensity
* 1 : maximum value of the intensity for the sdl rumble test * 1 : maximum value of the intensity for the sdl rumble test
*/ */
s_vgamePad[m_pad_id]->TestForce(strength/0x7FFF); s_vgamePad[m_pad_id]->TestForce(strength / 0x7FFF);
} else if(sl_id == m_sl_joystick_sensibility->GetId()) { } else if (sl_id == m_sl_joystick_sensibility->GetId()) {
u32 sensibility = m_sl_joystick_sensibility->GetValue(); // get the new value u32 sensibility = m_sl_joystick_sensibility->GetValue(); // get the new value
conf->set_sensibility(sensibility); // and set the joystick sensibility conf->set_sensibility(sensibility); // and set the joystick sensibility
} }
} }
/** /**
* Checkbox event, called when the value of the checkbox change * Checkbox event, called when the value of the checkbox change
*/ */
void GamepadConfiguration::OnCheckboxChange(wxCommandEvent& event) void GamepadConfiguration::OnCheckboxChange(wxCommandEvent &event)
{ {
wxCheckBox* cb_tmp = (wxCheckBox*) event.GetEventObject(); // get the slider object wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId(); int cb_id = cb_tmp->GetId();
if(cb_id == m_cb_rumble->GetId()) if (cb_id == m_cb_rumble->GetId()) {
{ conf->pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue()) ? (u32)1 : (u32)0;
conf->pad_options[m_pad_id].forcefeedback = (m_cb_rumble->GetValue())?(u32)1:(u32)0; if (m_cb_rumble->GetValue()) {
if(m_cb_rumble->GetValue())
{
s_vgamePad[m_pad_id]->TestForce(); s_vgamePad[m_pad_id]->TestForce();
m_sl_rumble_intensity->Enable(); m_sl_rumble_intensity->Enable();
} } else {
else
{
m_sl_rumble_intensity->Disable(); m_sl_rumble_intensity->Disable();
} }
} } else if (cb_id == m_cb_hack_sixaxis_usb->GetId()) {
else if(cb_id == m_cb_hack_sixaxis_usb->GetId()) conf->pad_options[m_pad_id].sixaxis_usb = (m_cb_hack_sixaxis_usb->GetValue()) ? (u32)1 : (u32)0;
{ } else if (cb_id == m_cb_hack_sixaxis_pressure->GetId()) {
conf->pad_options[m_pad_id].sixaxis_usb = (m_cb_hack_sixaxis_usb->GetValue())?(u32)1:(u32)0; conf->pad_options[m_pad_id].sixaxis_pressure = (m_cb_hack_sixaxis_pressure->GetValue()) ? (u32)1 : (u32)0;
}
else if(cb_id == m_cb_hack_sixaxis_pressure->GetId())
{
conf->pad_options[m_pad_id].sixaxis_pressure = (m_cb_hack_sixaxis_pressure->GetValue())?(u32)1:(u32)0;
} }
} }
@ -277,8 +265,8 @@ void GamepadConfiguration::repopulate()
m_init_joystick_sensibility = tmp; m_init_joystick_sensibility = tmp;
// enable rumble intensity slider if the checkbox is checked // enable rumble intensity slider if the checkbox is checked
if(m_cb_rumble->GetValue()) if (m_cb_rumble->GetValue())
m_sl_rumble_intensity->Enable(); m_sl_rumble_intensity->Enable();
else // disable otherwise else // disable otherwise
m_sl_rumble_intensity->Disable(); m_sl_rumble_intensity->Disable();
} }

View File

@ -34,7 +34,7 @@
class GamepadConfiguration : public wxDialog class GamepadConfiguration : public wxDialog
{ {
wxPanel* m_pan_gamepad_config; wxPanel *m_pan_gamepad_config;
wxCheckBox *m_cb_rumble, *m_cb_hack_sixaxis_usb, *m_cb_hack_sixaxis_pressure; wxCheckBox *m_cb_rumble, *m_cb_hack_sixaxis_usb, *m_cb_hack_sixaxis_pressure;
wxSlider *m_sl_rumble_intensity, *m_sl_joystick_sensibility; wxSlider *m_sl_rumble_intensity, *m_sl_joystick_sensibility;
wxButton *m_bt_ok, *m_bt_cancel; wxButton *m_bt_ok, *m_bt_cancel;
@ -48,13 +48,13 @@ class GamepadConfiguration : public wxDialog
void repopulate(); void repopulate();
void reset(); void reset();
// Events // Events
void OnButtonClicked(wxCommandEvent&); void OnButtonClicked(wxCommandEvent &);
void OnSliderReleased(wxCommandEvent&); void OnSliderReleased(wxCommandEvent &);
void OnCheckboxChange(wxCommandEvent&); void OnCheckboxChange(wxCommandEvent &);
public: public:
GamepadConfiguration(int, wxWindow*); GamepadConfiguration(int, wxWindow *);
void InitGamepadConfiguration(); void InitGamepadConfiguration();
}; };
#endif // __GAMEPADCONFIGURATION_H__ #endif // __GAMEPADCONFIGURATION_H__

View File

@ -20,91 +20,88 @@
#include "JoystickConfiguration.h" #include "JoystickConfiguration.h"
// Construtor of JoystickConfiguration // Construtor of JoystickConfiguration
JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent) : wxDialog( JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *parent)
parent, // Parent : wxDialog(
wxID_ANY, // ID parent, // Parent
_T("Gamepad configuration"), // Title wxID_ANY, // ID
wxDefaultPosition, // Position _T("Gamepad configuration"), // Title
wxSize(400, 200), // Width + Lenght wxDefaultPosition, // Position
// Style wxSize(400, 200), // Width + Lenght
wxSYSTEM_MENU | // Style
wxCAPTION | wxSYSTEM_MENU |
wxCLOSE_BOX | wxCAPTION |
wxCLIP_CHILDREN wxCLOSE_BOX |
) wxCLIP_CHILDREN)
{ {
m_pad_id = pad; m_pad_id = pad;
m_isForLeftJoystick = left; m_isForLeftJoystick = left;
m_pan_joystick_config = new wxPanel( m_pan_joystick_config = new wxPanel(
this, // Parent this, // Parent
wxID_ANY, // ID wxID_ANY, // ID
wxDefaultPosition, // Prosition wxDefaultPosition, // Prosition
wxSize(300, 200) // Size wxSize(300, 200) // Size
);
if(m_isForLeftJoystick)
{
m_cb_reverse_Lx = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("Reverse Lx"), // Label
wxPoint(20, 20) // Position
); );
if (m_isForLeftJoystick) {
m_cb_reverse_Lx = new wxCheckBox(
m_pan_joystick_config, // Parent
wxID_ANY, // ID
_T("Reverse Lx"), // Label
wxPoint(20, 20) // Position
);
m_cb_reverse_Ly = new wxCheckBox( m_cb_reverse_Ly = new wxCheckBox(
m_pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Reverse Ly"), // Label _T("Reverse Ly"), // Label
wxPoint(20, 40) // Position wxPoint(20, 40) // Position
); );
m_cb_mouse_Ljoy = new wxCheckBox( m_cb_mouse_Ljoy = new wxCheckBox(
m_pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Use mouse for left analog joystick"), // Label _T("Use mouse for left analog joystick"), // Label
wxPoint(20, 60) // Position wxPoint(20, 60) // Position
); );
} } else {
else
{
m_cb_reverse_Rx = new wxCheckBox( m_cb_reverse_Rx = new wxCheckBox(
m_pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Reverse Rx"), // Label _T("Reverse Rx"), // Label
wxPoint(20, 20) // Position wxPoint(20, 20) // Position
); );
m_cb_reverse_Ry = new wxCheckBox( m_cb_reverse_Ry = new wxCheckBox(
m_pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Reverse Ry"), // Label _T("Reverse Ry"), // Label
wxPoint(20, 40) // Position wxPoint(20, 40) // Position
); );
m_cb_mouse_Rjoy = new wxCheckBox( m_cb_mouse_Rjoy = new wxCheckBox(
m_pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("Use mouse for right analog joystick"), // Label _T("Use mouse for right analog joystick"), // Label
wxPoint(20, 60) // Position wxPoint(20, 60) // Position
); );
} }
m_bt_ok = new wxButton( m_bt_ok = new wxButton(
m_pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&OK"), // Label _T("&OK"), // Label
wxPoint(250, 130), // Position wxPoint(250, 130), // Position
wxSize(60,25) // Size wxSize(60, 25) // Size
); );
m_bt_cancel = new wxButton( m_bt_cancel = new wxButton(
m_pan_joystick_config, // Parent m_pan_joystick_config, // Parent
wxID_ANY, // ID wxID_ANY, // ID
_T("&Cancel"), // Label _T("&Cancel"), // Label
wxPoint(320, 130), // Position wxPoint(320, 130), // Position
wxSize(60,25) // Size wxSize(60, 25) // Size
); );
Bind(wxEVT_BUTTON, &JoystickConfiguration::OnButtonClicked, this); Bind(wxEVT_BUTTON, &JoystickConfiguration::OnButtonClicked, this);
Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this); Bind(wxEVT_CHECKBOX, &JoystickConfiguration::OnCheckboxChange, this);
@ -116,24 +113,20 @@ JoystickConfiguration::JoystickConfiguration(int pad, bool left, wxWindow *paren
*/ */
void JoystickConfiguration::InitJoystickConfiguration() void JoystickConfiguration::InitJoystickConfiguration()
{ {
repopulate(); // Set label and fit simulated key array repopulate(); // Set label and fit simulated key array
/* /*
* Check if there exist at least one pad available * Check if there exist at least one pad available
* if the pad id is 0, you need at least 1 gamepad connected, * if the pad id is 0, you need at least 1 gamepad connected,
* if the pad id is 1, you need at least 2 gamepad connected, * if the pad id is 1, you need at least 2 gamepad connected,
* Prevent to use a none initialized value on s_vgamePad (core dump) * Prevent to use a none initialized value on s_vgamePad (core dump)
*/ */
if(s_vgamePad.size() < m_pad_id+1) if (s_vgamePad.size() < m_pad_id + 1) {
{
wxMessageBox(L"No gamepad detected."); wxMessageBox(L"No gamepad detected.");
// disable all checkbox // disable all checkbox
if(m_isForLeftJoystick) if (m_isForLeftJoystick) {
{
m_cb_reverse_Lx->Disable(); m_cb_reverse_Lx->Disable();
m_cb_reverse_Ly->Disable(); m_cb_reverse_Ly->Disable();
} } else {
else
{
m_cb_reverse_Rx->Disable(); m_cb_reverse_Rx->Disable();
m_cb_reverse_Ry->Disable(); m_cb_reverse_Ry->Disable();
} }
@ -150,56 +143,43 @@ void JoystickConfiguration::InitJoystickConfiguration()
void JoystickConfiguration::OnButtonClicked(wxCommandEvent &event) void JoystickConfiguration::OnButtonClicked(wxCommandEvent &event)
{ {
// Affichage d'un message à chaque clic sur le bouton // Affichage d'un message à chaque clic sur le bouton
wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId(); // get the real ID int bt_id = bt_tmp->GetId(); // get the real ID
if(bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID if (bt_id == m_bt_ok->GetId()) { // If the button ID is equals to the Ok button ID
Close(); // Close the window Close(); // Close the window
} else if(bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID } else if (bt_id == m_bt_cancel->GetId()) { // If the button ID is equals to the cancel button ID
reset(); // reinitialize the value of each parameters reset(); // reinitialize the value of each parameters
Close(); // Close the window Close(); // Close the window
} }
} }
/** /**
* Checkbox event, called when the value of the checkbox change * Checkbox event, called when the value of the checkbox change
*/ */
void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event) void JoystickConfiguration::OnCheckboxChange(wxCommandEvent &event)
{ {
wxCheckBox* cb_tmp = (wxCheckBox*) event.GetEventObject(); // get the slider object wxCheckBox *cb_tmp = (wxCheckBox *)event.GetEventObject(); // get the slider object
int cb_id = cb_tmp->GetId(); int cb_id = cb_tmp->GetId();
bool val; bool val;
if(m_isForLeftJoystick) if (m_isForLeftJoystick) {
{ if (cb_id == m_cb_reverse_Ly->GetId()) {
if(cb_id == m_cb_reverse_Ly->GetId())
{
val = m_cb_reverse_Ly->GetValue(); val = m_cb_reverse_Ly->GetValue();
conf->pad_options[m_pad_id].reverse_ly = val; conf->pad_options[m_pad_id].reverse_ly = val;
} } else if (cb_id == m_cb_reverse_Lx->GetId()) {
else if(cb_id == m_cb_reverse_Lx->GetId())
{
val = m_cb_reverse_Lx->GetValue(); val = m_cb_reverse_Lx->GetValue();
conf->pad_options[m_pad_id].reverse_lx = val; conf->pad_options[m_pad_id].reverse_lx = val;
} } else if (cb_id == m_cb_mouse_Ljoy->GetId()) {
else if(cb_id == m_cb_mouse_Ljoy->GetId())
{
val = m_cb_mouse_Ljoy->GetValue(); val = m_cb_mouse_Ljoy->GetValue();
conf->pad_options[m_pad_id].mouse_l = val; conf->pad_options[m_pad_id].mouse_l = val;
} }
} } else {
else if (cb_id == m_cb_reverse_Ry->GetId()) {
{
if(cb_id == m_cb_reverse_Ry->GetId())
{
val = m_cb_reverse_Ry->GetValue(); val = m_cb_reverse_Ry->GetValue();
conf->pad_options[m_pad_id].reverse_ry = val; conf->pad_options[m_pad_id].reverse_ry = val;
} } else if (cb_id == m_cb_reverse_Rx->GetId()) {
else if(cb_id == m_cb_reverse_Rx->GetId())
{
val = m_cb_reverse_Rx->GetValue(); val = m_cb_reverse_Rx->GetValue();
conf->pad_options[m_pad_id].reverse_rx = val; conf->pad_options[m_pad_id].reverse_rx = val;
} } else if (cb_id == m_cb_mouse_Rjoy->GetId()) {
else if(cb_id == m_cb_mouse_Rjoy->GetId())
{
val = m_cb_mouse_Rjoy->GetValue(); val = m_cb_mouse_Rjoy->GetValue();
conf->pad_options[m_pad_id].mouse_r = val; conf->pad_options[m_pad_id].mouse_r = val;
} }
@ -213,14 +193,11 @@ void JoystickConfiguration::OnCheckboxChange(wxCommandEvent& event)
// Reset checkbox and slider values // Reset checkbox and slider values
void JoystickConfiguration::reset() void JoystickConfiguration::reset()
{ {
if(m_isForLeftJoystick) if (m_isForLeftJoystick) {
{
m_cb_reverse_Lx->SetValue(m_init_reverse_Lx); m_cb_reverse_Lx->SetValue(m_init_reverse_Lx);
m_cb_reverse_Ly->SetValue(m_init_reverse_Ly); m_cb_reverse_Ly->SetValue(m_init_reverse_Ly);
m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy); m_cb_mouse_Ljoy->SetValue(m_init_mouse_Ljoy);
} } else {
else
{
m_cb_reverse_Rx->SetValue(m_init_reverse_Rx); m_cb_reverse_Rx->SetValue(m_init_reverse_Rx);
m_cb_reverse_Ry->SetValue(m_init_reverse_Ry); m_cb_reverse_Ry->SetValue(m_init_reverse_Ry);
m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy); m_cb_mouse_Rjoy->SetValue(m_init_mouse_Rjoy);
@ -231,8 +208,7 @@ void JoystickConfiguration::reset()
void JoystickConfiguration::repopulate() void JoystickConfiguration::repopulate()
{ {
bool val; bool val;
if(m_isForLeftJoystick) if (m_isForLeftJoystick) {
{
val = conf->pad_options[m_pad_id].reverse_lx; val = conf->pad_options[m_pad_id].reverse_lx;
m_init_reverse_Lx = val; m_init_reverse_Lx = val;
m_cb_reverse_Lx->SetValue(val); m_cb_reverse_Lx->SetValue(val);
@ -244,9 +220,7 @@ void JoystickConfiguration::repopulate()
val = conf->pad_options[m_pad_id].mouse_l; val = conf->pad_options[m_pad_id].mouse_l;
m_init_mouse_Ljoy = val; m_init_mouse_Ljoy = val;
m_cb_mouse_Ljoy->SetValue(val); m_cb_mouse_Ljoy->SetValue(val);
} } else {
else
{
val = conf->pad_options[m_pad_id].reverse_rx; val = conf->pad_options[m_pad_id].reverse_rx;
m_init_reverse_Rx = val; m_init_reverse_Rx = val;
m_cb_reverse_Rx->SetValue(val); m_cb_reverse_Rx->SetValue(val);

View File

@ -34,10 +34,10 @@
class JoystickConfiguration : public wxDialog class JoystickConfiguration : public wxDialog
{ {
wxPanel* m_pan_joystick_config; wxPanel *m_pan_joystick_config;
wxCheckBox *m_cb_reverse_Lx, *m_cb_reverse_Ly, *m_cb_reverse_Rx, *m_cb_reverse_Ry, wxCheckBox *m_cb_reverse_Lx, *m_cb_reverse_Ly, *m_cb_reverse_Rx, *m_cb_reverse_Ry,
*m_cb_mouse_Ljoy, // Use mouse for left joystick *m_cb_mouse_Ljoy, // Use mouse for left joystick
*m_cb_mouse_Rjoy; // Use mouse for right joystick *m_cb_mouse_Rjoy; // Use mouse for right joystick
wxButton *m_bt_ok, *m_bt_cancel; wxButton *m_bt_ok, *m_bt_cancel;
u32 m_pad_id; u32 m_pad_id;
@ -49,12 +49,12 @@ class JoystickConfiguration : public wxDialog
void repopulate(); void repopulate();
void reset(); void reset();
// Events // Events
void OnButtonClicked(wxCommandEvent&); void OnButtonClicked(wxCommandEvent &);
void OnCheckboxChange(wxCommandEvent&); void OnCheckboxChange(wxCommandEvent &);
public: public:
JoystickConfiguration(int, bool, wxWindow*); JoystickConfiguration(int, bool, wxWindow *);
void InitJoystickConfiguration(); void InitJoystickConfiguration();
}; };
#endif // __JOYSTICKCONFIGURATION_H__ #endif // __JOYSTICKCONFIGURATION_H__

View File

@ -20,17 +20,17 @@
#include "dialog.h" #include "dialog.h"
// Construtor of Dialog // Construtor of Dialog
Dialog::Dialog() : wxDialog( NULL, // Parent Dialog::Dialog()
wxID_ANY, // ID : wxDialog(NULL, // Parent
_T("OnePad configuration"), // Title wxID_ANY, // ID
wxDefaultPosition, // Position _T("OnePad configuration"), // Title
wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT), // Width + Lenght wxDefaultPosition, // Position
// Style wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT), // Width + Lenght
wxSYSTEM_MENU | // Style
wxCAPTION | wxSYSTEM_MENU |
wxCLOSE_BOX | wxCAPTION |
wxCLIP_CHILDREN wxCLOSE_BOX |
) wxCLIP_CHILDREN)
{ {
/* /*
@ -43,208 +43,206 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
int padding[BUTTONS_LENGHT][4]; int padding[BUTTONS_LENGHT][4];
// L1 // L1
padding[PAD_L1][0] = 218; // Width padding[PAD_L1][0] = 218; // Width
padding[PAD_L1][1] = 28; // Height padding[PAD_L1][1] = 28; // Height
padding[PAD_L1][2] = 50; // X padding[PAD_L1][2] = 50; // X
padding[PAD_L1][3] = 175; // Y padding[PAD_L1][3] = 175; // Y
// L2 // L2
padding[PAD_L2][0] = 218; // Width padding[PAD_L2][0] = 218; // Width
padding[PAD_L2][1] = 28; // Height padding[PAD_L2][1] = 28; // Height
padding[PAD_L2][2] = 50; // X padding[PAD_L2][2] = 50; // X
padding[PAD_L2][3] = 104; // Y padding[PAD_L2][3] = 104; // Y
// R1 // R1
padding[PAD_R1][0] = 218; // Width padding[PAD_R1][0] = 218; // Width
padding[PAD_R1][1] = 28; // Height padding[PAD_R1][1] = 28; // Height
padding[PAD_R1][2] = 726; // X padding[PAD_R1][2] = 726; // X
padding[PAD_R1][3] = 175; // Y padding[PAD_R1][3] = 175; // Y
// R2 // R2
padding[PAD_R2][0] = 218; // Width padding[PAD_R2][0] = 218; // Width
padding[PAD_R2][1] = 28; // Height padding[PAD_R2][1] = 28; // Height
padding[PAD_R2][2] = 726; // X padding[PAD_R2][2] = 726; // X
padding[PAD_R2][3] = 104; // Y padding[PAD_R2][3] = 104; // Y
// Triangle // Triangle
padding[PAD_TRIANGLE][0] = 218; // Width padding[PAD_TRIANGLE][0] = 218; // Width
padding[PAD_TRIANGLE][1] = 28; // Height padding[PAD_TRIANGLE][1] = 28; // Height
padding[PAD_TRIANGLE][2] = 726; // X padding[PAD_TRIANGLE][2] = 726; // X
padding[PAD_TRIANGLE][3] = 246; // Y padding[PAD_TRIANGLE][3] = 246; // Y
// Circle // Circle
padding[PAD_CIRCLE][0] = 218; // Width padding[PAD_CIRCLE][0] = 218; // Width
padding[PAD_CIRCLE][1] = 28; // Height padding[PAD_CIRCLE][1] = 28; // Height
padding[PAD_CIRCLE][2] = 726; // X padding[PAD_CIRCLE][2] = 726; // X
padding[PAD_CIRCLE][3] = 319; // Y padding[PAD_CIRCLE][3] = 319; // Y
// Cross // Cross
padding[PAD_CROSS][0] = 218; // Width padding[PAD_CROSS][0] = 218; // Width
padding[PAD_CROSS][1] = 28; // Height padding[PAD_CROSS][1] = 28; // Height
padding[PAD_CROSS][2] = 726; // X padding[PAD_CROSS][2] = 726; // X
padding[PAD_CROSS][3] = 391; // Y padding[PAD_CROSS][3] = 391; // Y
// Square // Square
padding[PAD_SQUARE][0] = 218; // Width padding[PAD_SQUARE][0] = 218; // Width
padding[PAD_SQUARE][1] = 28; // Height padding[PAD_SQUARE][1] = 28; // Height
padding[PAD_SQUARE][2] = 726; // X padding[PAD_SQUARE][2] = 726; // X
padding[PAD_SQUARE][3] = 463; // Y padding[PAD_SQUARE][3] = 463; // Y
// Directional pad up // Directional pad up
padding[PAD_UP][0] = 100; // Width padding[PAD_UP][0] = 100; // Width
padding[PAD_UP][1] = 25; // Height padding[PAD_UP][1] = 25; // Height
padding[PAD_UP][2] = 108; // X padding[PAD_UP][2] = 108; // X
padding[PAD_UP][3] = 290; // Y padding[PAD_UP][3] = 290; // Y
// Directional pad down // Directional pad down
padding[PAD_DOWN][0] = 100; // Width padding[PAD_DOWN][0] = 100; // Width
padding[PAD_DOWN][1] = 25; // Height padding[PAD_DOWN][1] = 25; // Height
padding[PAD_DOWN][2] = 108; // X padding[PAD_DOWN][2] = 108; // X
padding[PAD_DOWN][3] = 340; // Y padding[PAD_DOWN][3] = 340; // Y
// Directional pad right // Directional pad right
padding[PAD_RIGHT][0] = 109; // Width padding[PAD_RIGHT][0] = 109; // Width
padding[PAD_RIGHT][1] = 25; // Height padding[PAD_RIGHT][1] = 25; // Height
padding[PAD_RIGHT][2] = 159; // X padding[PAD_RIGHT][2] = 159; // X
padding[PAD_RIGHT][3] = 315; // Y padding[PAD_RIGHT][3] = 315; // Y
// Directional pad left // Directional pad left
padding[PAD_LEFT][0] = 109; // Width padding[PAD_LEFT][0] = 109; // Width
padding[PAD_LEFT][1] = 25; // Height padding[PAD_LEFT][1] = 25; // Height
padding[PAD_LEFT][2] = 50; // X padding[PAD_LEFT][2] = 50; // X
padding[PAD_LEFT][3] = 315; // Y padding[PAD_LEFT][3] = 315; // Y
// Left Joystick up // Left Joystick up
padding[PAD_L_UP][0] = 100; // Width padding[PAD_L_UP][0] = 100; // Width
padding[PAD_L_UP][1] = 25; // Height padding[PAD_L_UP][1] = 25; // Height
padding[PAD_L_UP][2] = 325; // X padding[PAD_L_UP][2] = 325; // X
padding[PAD_L_UP][3] = 527; // Y padding[PAD_L_UP][3] = 527; // Y
// Left Joystick down // Left Joystick down
padding[PAD_L_DOWN][0] = 100; // Width padding[PAD_L_DOWN][0] = 100; // Width
padding[PAD_L_DOWN][1] = 25; // Height padding[PAD_L_DOWN][1] = 25; // Height
padding[PAD_L_DOWN][2] = 325; // X padding[PAD_L_DOWN][2] = 325; // X
padding[PAD_L_DOWN][3] = 577; // Y padding[PAD_L_DOWN][3] = 577; // Y
// Left Joystick right // Left Joystick right
padding[PAD_L_RIGHT][0] = 109; // Width padding[PAD_L_RIGHT][0] = 109; // Width
padding[PAD_L_RIGHT][1] = 25; // Height padding[PAD_L_RIGHT][1] = 25; // Height
padding[PAD_L_RIGHT][2] = 377; // X padding[PAD_L_RIGHT][2] = 377; // X
padding[PAD_L_RIGHT][3] = 552; // Y padding[PAD_L_RIGHT][3] = 552; // Y
// Left Joystick left // Left Joystick left
padding[PAD_L_LEFT][0] = 109; // Width padding[PAD_L_LEFT][0] = 109; // Width
padding[PAD_L_LEFT][1] = 25; // Height padding[PAD_L_LEFT][1] = 25; // Height
padding[PAD_L_LEFT][2] = 268; // X padding[PAD_L_LEFT][2] = 268; // X
padding[PAD_L_LEFT][3] = 552; // Y padding[PAD_L_LEFT][3] = 552; // Y
// L3 // L3
padding[PAD_L3][0] = 218; // Width padding[PAD_L3][0] = 218; // Width
padding[PAD_L3][1] = 28; // Height padding[PAD_L3][1] = 28; // Height
padding[PAD_L3][2] = 268; // X padding[PAD_L3][2] = 268; // X
padding[PAD_L3][3] = 641; // Y padding[PAD_L3][3] = 641; // Y
// Right Joystick up // Right Joystick up
padding[PAD_R_UP][0] = 100; // Width padding[PAD_R_UP][0] = 100; // Width
padding[PAD_R_UP][1] = 25; // Height padding[PAD_R_UP][1] = 25; // Height
padding[PAD_R_UP][2] = 555; // X padding[PAD_R_UP][2] = 555; // X
padding[PAD_R_UP][3] = 527; // Y padding[PAD_R_UP][3] = 527; // Y
// Right Joystick down // Right Joystick down
padding[PAD_R_DOWN][0] = 100; // Width padding[PAD_R_DOWN][0] = 100; // Width
padding[PAD_R_DOWN][1] = 25; // Height padding[PAD_R_DOWN][1] = 25; // Height
padding[PAD_R_DOWN][2] = 555; // X padding[PAD_R_DOWN][2] = 555; // X
padding[PAD_R_DOWN][3] = 577; // Y padding[PAD_R_DOWN][3] = 577; // Y
// Right Joystick right // Right Joystick right
padding[PAD_R_RIGHT][0] = 109; // Width padding[PAD_R_RIGHT][0] = 109; // Width
padding[PAD_R_RIGHT][1] = 25; // Height padding[PAD_R_RIGHT][1] = 25; // Height
padding[PAD_R_RIGHT][2] = 607; // X padding[PAD_R_RIGHT][2] = 607; // X
padding[PAD_R_RIGHT][3] = 552; // Y padding[PAD_R_RIGHT][3] = 552; // Y
// Right Joystick left // Right Joystick left
padding[PAD_R_LEFT][0] = 109; // Width padding[PAD_R_LEFT][0] = 109; // Width
padding[PAD_R_LEFT][1] = 25; // Height padding[PAD_R_LEFT][1] = 25; // Height
padding[PAD_R_LEFT][2] = 498; // X padding[PAD_R_LEFT][2] = 498; // X
padding[PAD_R_LEFT][3] = 552; // Y padding[PAD_R_LEFT][3] = 552; // Y
// R3 // R3
padding[PAD_R3][0] = 218; // Width padding[PAD_R3][0] = 218; // Width
padding[PAD_R3][1] = 28; // Height padding[PAD_R3][1] = 28; // Height
padding[PAD_R3][2] = 498; // X padding[PAD_R3][2] = 498; // X
padding[PAD_R3][3] = 641; // Y padding[PAD_R3][3] = 641; // Y
// Start // Start
padding[PAD_START][0] = 218; // Width padding[PAD_START][0] = 218; // Width
padding[PAD_START][1] = 28; // Height padding[PAD_START][1] = 28; // Height
padding[PAD_START][2] = 503; // X padding[PAD_START][2] = 503; // X
padding[PAD_START][3] = 34; // Y padding[PAD_START][3] = 34; // Y
// Select // Select
padding[PAD_SELECT][0] = 218; // Width padding[PAD_SELECT][0] = 218; // Width
padding[PAD_SELECT][1] = 28; // Height padding[PAD_SELECT][1] = 28; // Height
padding[PAD_SELECT][2] = 273; // X padding[PAD_SELECT][2] = 273; // X
padding[PAD_SELECT][3] = 34; // Y padding[PAD_SELECT][3] = 34; // Y
// Analog // Analog
padding[Analog][0] = 218; // Width padding[Analog][0] = 218; // Width
padding[Analog][1] = 28; // Height padding[Analog][1] = 28; // Height
padding[Analog][2] = 50; // X padding[Analog][2] = 50; // X
padding[Analog][3] = 452; // Y padding[Analog][3] = 452; // Y
// Left Joystick Configuration // Left Joystick Configuration
padding[JoyL_config][0] = 180; // Width padding[JoyL_config][0] = 180; // Width
padding[JoyL_config][1] = 28; // Height padding[JoyL_config][1] = 28; // Height
padding[JoyL_config][2] = 50; // X padding[JoyL_config][2] = 50; // X
padding[JoyL_config][3] = 550; // Y padding[JoyL_config][3] = 550; // Y
// Right Joystick Configuration // Right Joystick Configuration
padding[JoyR_config][0] = 180; // Width padding[JoyR_config][0] = 180; // Width
padding[JoyR_config][1] = 28; // Height padding[JoyR_config][1] = 28; // Height
padding[JoyR_config][2] = 764; // X padding[JoyR_config][2] = 764; // X
padding[JoyR_config][3] = 550; // Y padding[JoyR_config][3] = 550; // Y
// Gamepad Configuration // Gamepad Configuration
padding[Gamepad_config][0] = 180; // Width padding[Gamepad_config][0] = 180; // Width
padding[Gamepad_config][1] = 28; // Height padding[Gamepad_config][1] = 28; // Height
padding[Gamepad_config][2] = 50; // X padding[Gamepad_config][2] = 50; // X
padding[Gamepad_config][3] = 585; // Y padding[Gamepad_config][3] = 585; // Y
// Set All Buttons // Set All Buttons
padding[Set_all][0] = 180; // Width padding[Set_all][0] = 180; // Width
padding[Set_all][1] = 28; // Height padding[Set_all][1] = 28; // Height
padding[Set_all][2] = 764; // X padding[Set_all][2] = 764; // X
padding[Set_all][3] = 585; // Y padding[Set_all][3] = 585; // Y
// Apply modifications without exit // Apply modifications without exit
padding[Apply][0] = 70; // Width padding[Apply][0] = 70; // Width
padding[Apply][1] = 28; // Height padding[Apply][1] = 28; // Height
padding[Apply][2] = 833; // X padding[Apply][2] = 833; // X
padding[Apply][3] = 642; // Y padding[Apply][3] = 642; // Y
// Ok button // Ok button
padding[Ok][0] = 70; // Width padding[Ok][0] = 70; // Width
padding[Ok][1] = 28; // Height padding[Ok][1] = 28; // Height
padding[Ok][2] = 913; // X padding[Ok][2] = 913; // X
padding[Ok][3] = 642; // Y padding[Ok][3] = 642; // Y
// Cancel button // Cancel button
padding[Cancel][0] = 70; // Width padding[Cancel][0] = 70; // Width
padding[Cancel][1] = 28; // Height padding[Cancel][1] = 28; // Height
padding[Cancel][2] = 753; // X padding[Cancel][2] = 753; // X
padding[Cancel][3] = 642; // Y padding[Cancel][3] = 642; // Y
// create a new Notebook // create a new Notebook
m_tab_gamepad = new wxNotebook(this, wxID_ANY); m_tab_gamepad = new wxNotebook(this, wxID_ANY);
for(int i=0; i<GAMEPAD_NUMBER; ++i) for (int i = 0; i < GAMEPAD_NUMBER; ++i) {
{
// Tabs panels // Tabs panels
m_pan_tabs[i] = new opPanel( m_pan_tabs[i] = new opPanel(
m_tab_gamepad, m_tab_gamepad,
wxID_ANY, wxID_ANY,
wxDefaultPosition, wxDefaultPosition,
wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT) wxSize(DEFAULT_WIDTH, DEFAULT_HEIGHT));
);
// Add new page // Add new page
// Define label // Define label
std::stringstream sstm; std::stringstream sstm;
@ -252,20 +250,19 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
sstm << label << i; sstm << label << i;
// New page creation // New page creation
m_tab_gamepad->AddPage( m_tab_gamepad->AddPage(
m_pan_tabs[i], // Parent m_pan_tabs[i], // Parent
wxString(sstm.str().c_str(), wxConvUTF8) // Title wxString(sstm.str().c_str(), wxConvUTF8) // Title
); );
for(int j=0; j<BUTTONS_LENGHT; ++j) for (int j = 0; j < BUTTONS_LENGHT; ++j) {
{
// Gamepad buttons // Gamepad buttons
m_bt_gamepad[i][j] = new wxButton( m_bt_gamepad[i][j] = new wxButton(
m_pan_tabs[i], // Parent m_pan_tabs[i], // Parent
wxID_HIGHEST+j+1, // ID wxID_HIGHEST + j + 1, // ID
_T("Undefined"), // Label _T("Undefined"), // Label
wxPoint(padding[j][2], padding[j][3]), // Position wxPoint(padding[j][2], padding[j][3]), // Position
wxSize(padding[j][0], padding[j][1]) // Size wxSize(padding[j][0], padding[j][1]) // Size
); );
} }
// Redefine others gui buttons label // Redefine others gui buttons label
m_bt_gamepad[i][JoyL_config]->SetLabel(_T("&Left Joystick Config")); m_bt_gamepad[i][JoyL_config]->SetLabel(_T("&Left Joystick Config"));
@ -286,10 +283,8 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
Bind(wxEVT_TIMER, &Dialog::JoystickEvent, this); Bind(wxEVT_TIMER, &Dialog::JoystickEvent, this);
m_time_update_gui.Start(UPDATE_TIME, wxTIMER_CONTINUOUS); m_time_update_gui.Start(UPDATE_TIME, wxTIMER_CONTINUOUS);
for(int i=0; i<GAMEPAD_NUMBER; ++i) for (int i = 0; i < GAMEPAD_NUMBER; ++i) {
{ for (int j = 0; j < NB_IMG; ++j) {
for(int j=0; j<NB_IMG; ++j)
{
m_pressed[i][j] = false; m_pressed[i][j] = false;
} }
} }
@ -297,9 +292,9 @@ Dialog::Dialog() : wxDialog( NULL, // Parent
void Dialog::InitDialog() void Dialog::InitDialog()
{ {
GamePad::EnumerateGamePads(s_vgamePad); // activate gamepads GamePad::EnumerateGamePads(s_vgamePad); // activate gamepads
LoadConfig(); // Load configuration from the ini file LoadConfig(); // Load configuration from the ini file
repopulate(); // Set label and fit simulated key array repopulate(); // Set label and fit simulated key array
} }
/****************************************/ /****************************************/
@ -309,56 +304,54 @@ void Dialog::InitDialog()
void Dialog::OnButtonClicked(wxCommandEvent &event) void Dialog::OnButtonClicked(wxCommandEvent &event)
{ {
// Affichage d'un message à chaque clic sur le bouton // Affichage d'un message à chaque clic sur le bouton
wxButton* bt_tmp = (wxButton*)event.GetEventObject(); // get the button object wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
int bt_id = bt_tmp->GetId()-wxID_HIGHEST-1; // get the real ID int bt_id = bt_tmp->GetId() - wxID_HIGHEST - 1; // get the real ID
int gamepad_id = m_tab_gamepad->GetSelection(); // get the tab ID (equivalent to the gamepad id) int gamepad_id = m_tab_gamepad->GetSelection(); // get the tab ID (equivalent to the gamepad id)
if(bt_id >= 0 && bt_id <= PAD_R_LEFT) { // if the button ID is a gamepad button if (bt_id >= 0 && bt_id <= PAD_R_LEFT) { // if the button ID is a gamepad button
bt_tmp->Disable(); // switch the button state to "Disable" bt_tmp->Disable(); // switch the button state to "Disable"
config_key(gamepad_id, bt_id); config_key(gamepad_id, bt_id);
bt_tmp->Enable(); // switch the button state to "Enable" bt_tmp->Enable(); // switch the button state to "Enable"
} else if(bt_id == Gamepad_config) { // If the button ID is equals to the Gamepad_config button ID } else if (bt_id == Gamepad_config) { // If the button ID is equals to the Gamepad_config button ID
GamepadConfiguration gamepad_config(gamepad_id, this); GamepadConfiguration gamepad_config(gamepad_id, this);
gamepad_config.InitGamepadConfiguration(); gamepad_config.InitGamepadConfiguration();
gamepad_config.ShowModal(); gamepad_config.ShowModal();
} else if(bt_id == JoyL_config) { // If the button ID is equals to the JoyL_config button ID } else if (bt_id == JoyL_config) { // If the button ID is equals to the JoyL_config button ID
JoystickConfiguration joystick_config(gamepad_id, true, this); JoystickConfiguration joystick_config(gamepad_id, true, this);
joystick_config.InitJoystickConfiguration(); joystick_config.InitJoystickConfiguration();
joystick_config.ShowModal(); joystick_config.ShowModal();
} else if(bt_id == JoyR_config) { // If the button ID is equals to the JoyR_config button ID } else if (bt_id == JoyR_config) { // If the button ID is equals to the JoyR_config button ID
JoystickConfiguration joystick_config(gamepad_id, false, this); JoystickConfiguration joystick_config(gamepad_id, false, this);
joystick_config.InitJoystickConfiguration(); joystick_config.InitJoystickConfiguration();
joystick_config.ShowModal(); joystick_config.ShowModal();
} else if(bt_id == Set_all) { // If the button ID is equals to the Set_all button ID } else if (bt_id == Set_all) { // If the button ID is equals to the Set_all button ID
for(int i=0; i<MAX_KEYS; ++i) for (int i = 0; i < MAX_KEYS; ++i) {
{
bt_tmp = m_bt_gamepad[gamepad_id][i]; bt_tmp = m_bt_gamepad[gamepad_id][i];
switch(i) switch (i) {
{ case PAD_L_UP: // Left joystick (Up) ↑
case PAD_L_UP: // Left joystick (Up) ↑
m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_up); m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_up);
break; break;
case PAD_L_RIGHT: // Left joystick (Right) → case PAD_L_RIGHT: // Left joystick (Right) →
m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_right); m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_right);
break; break;
case PAD_L_DOWN: // Left joystick (Down) ↓ case PAD_L_DOWN: // Left joystick (Down) ↓
m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_bottom); m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_bottom);
break; break;
case PAD_L_LEFT: // Left joystick (Left) ← case PAD_L_LEFT: // Left joystick (Left) ←
m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_left); m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_left);
break; break;
case PAD_R_UP: // Right joystick (Up) ↑ case PAD_R_UP: // Right joystick (Up) ↑
m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_up); m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_up);
break; break;
case PAD_R_RIGHT: // Right joystick (Right) → case PAD_R_RIGHT: // Right joystick (Right) →
m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_right); m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_right);
break; break;
case PAD_R_DOWN: // Right joystick (Down) ↓ case PAD_R_DOWN: // Right joystick (Down) ↓
m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_bottom); m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_bottom);
break; break;
case PAD_R_LEFT: // Right joystick (Left) ← case PAD_R_LEFT: // Right joystick (Left) ←
m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_left); m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_left);
break; break;
default: default:
@ -368,30 +361,29 @@ void Dialog::OnButtonClicked(wxCommandEvent &event)
m_pan_tabs[gamepad_id]->Refresh(); m_pan_tabs[gamepad_id]->Refresh();
m_pan_tabs[gamepad_id]->Update(); m_pan_tabs[gamepad_id]->Update();
config_key(gamepad_id, i); config_key(gamepad_id, i);
switch(i) switch (i) {
{ case PAD_L_UP: // Left joystick (Up) ↑
case PAD_L_UP: // Left joystick (Up) ↑
m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_up); m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_up);
break; break;
case PAD_L_RIGHT: // Left joystick (Right) → case PAD_L_RIGHT: // Left joystick (Right) →
m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_right); m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_right);
break; break;
case PAD_L_DOWN: // Left joystick (Down) ↓ case PAD_L_DOWN: // Left joystick (Down) ↓
m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_bottom); m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_bottom);
break; break;
case PAD_L_LEFT: // Left joystick (Left) ← case PAD_L_LEFT: // Left joystick (Left) ←
m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_left); m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_left);
break; break;
case PAD_R_UP: // Right joystick (Up) ↑ case PAD_R_UP: // Right joystick (Up) ↑
m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_up); m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_up);
break; break;
case PAD_R_RIGHT: // Right joystick (Right) → case PAD_R_RIGHT: // Right joystick (Right) →
m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_right); m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_right);
break; break;
case PAD_R_DOWN: // Right joystick (Down) ↓ case PAD_R_DOWN: // Right joystick (Down) ↓
m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_bottom); m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_bottom);
break; break;
case PAD_R_LEFT: // Right joystick (Left) ← case PAD_R_LEFT: // Right joystick (Left) ←
m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_left); m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_left);
break; break;
default: default:
@ -400,76 +392,64 @@ void Dialog::OnButtonClicked(wxCommandEvent &event)
} }
m_pan_tabs[gamepad_id]->Refresh(); m_pan_tabs[gamepad_id]->Refresh();
m_pan_tabs[gamepad_id]->Update(); m_pan_tabs[gamepad_id]->Update();
usleep(500000); // give enough time to the user to release the button usleep(500000); // give enough time to the user to release the button
} }
} else if(bt_id == Ok) { // If the button ID is equals to the Ok button ID } else if (bt_id == Ok) { // If the button ID is equals to the Ok button ID
SaveConfig(); // Save the configuration SaveConfig(); // Save the configuration
Close(); // Close the window Close(); // Close the window
} else if(bt_id == Apply) { // If the button ID is equals to the Apply button ID } else if (bt_id == Apply) { // If the button ID is equals to the Apply button ID
SaveConfig(); // Save the configuration SaveConfig(); // Save the configuration
} else if(bt_id == Cancel) { // If the button ID is equals to the cancel button ID } else if (bt_id == Cancel) { // If the button ID is equals to the cancel button ID
Close(); // Close the window Close(); // Close the window
} }
} }
void Dialog::JoystickEvent(wxTimerEvent& event) void Dialog::JoystickEvent(wxTimerEvent &event)
{ {
#ifdef SDL_BUILD #ifdef SDL_BUILD
u32 key; u32 key;
int map; int map;
std::map<u32,int>::iterator it; std::map<u32, int>::iterator it;
std::map<u32,int>::iterator it2; std::map<u32, int>::iterator it2;
SDL_JoystickEventState(SDL_ENABLE); SDL_JoystickEventState(SDL_ENABLE);
SDL_Event events; SDL_Event events;
while(SDL_PollEvent(&events)) while (SDL_PollEvent(&events)) {
{ switch (events.type) {
switch(events.type)
{
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: case SDL_KEYUP:
break; break;
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
if(events.jaxis.which < GAMEPAD_NUMBER) if (events.jaxis.which < GAMEPAD_NUMBER) {
{ key = axis_to_key(false, (events.jaxis.value < 0), events.jaxis.axis);
key = axis_to_key(false, (events.jaxis.value<0), events.jaxis.axis); it = m_map_images[events.jaxis.which].find(key);
it=m_map_images[events.jaxis.which].find(key); if (it != m_map_images[events.jaxis.which].end()) {
if(it != m_map_images[events.jaxis.which].end())
{
map = m_map_images[events.jaxis.which][key]; map = m_map_images[events.jaxis.which][key];
if(events.jaxis.value == 0) if (events.jaxis.value == 0) {
{ if (map >= PAD_L_UP && map <= PAD_L_LEFT)
if(map >= PAD_L_UP && map <= PAD_L_LEFT)
m_pan_tabs[events.jaxis.which]->HideImg(img_left_cursor); m_pan_tabs[events.jaxis.which]->HideImg(img_left_cursor);
else if(map >= PAD_R_UP && map <= PAD_R_LEFT) else if (map >= PAD_R_UP && map <= PAD_R_LEFT)
m_pan_tabs[events.jaxis.which]->HideImg(img_right_cursor); m_pan_tabs[events.jaxis.which]->HideImg(img_right_cursor);
else if(map < PAD_L_UP) else if (map < PAD_L_UP)
m_pan_tabs[events.jaxis.which]->HideImg(map); m_pan_tabs[events.jaxis.which]->HideImg(map);
} } else {
else if (map >= PAD_L_UP && map <= PAD_L_LEFT) {
{
if(map >= PAD_L_UP && map <= PAD_L_LEFT)
{
m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value); m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value);
m_pan_tabs[events.jaxis.which]->ShowImg(img_left_cursor); m_pan_tabs[events.jaxis.which]->ShowImg(img_left_cursor);
} } else if (map >= PAD_R_UP && map <= PAD_R_LEFT) {
else if(map >= PAD_R_UP && map <= PAD_R_LEFT)
{
m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value); m_pan_tabs[events.jaxis.which]->MoveJoystick(events.jaxis.axis, events.jaxis.value);
m_pan_tabs[events.jaxis.which]->ShowImg(img_right_cursor); m_pan_tabs[events.jaxis.which]->ShowImg(img_right_cursor);
} } else if (map < PAD_L_UP) { // if this is not a joystick
else if(map < PAD_L_UP) { // if this is not a joystick
m_pan_tabs[events.jaxis.which]->ShowImg(map); m_pan_tabs[events.jaxis.which]->ShowImg(map);
} }
} }
break; break;
} }
// Hack Dualshock 4 (L2, R2) // Hack Dualshock 4 (L2, R2)
key = axis_to_key(false, (events.jaxis.value>0), events.jaxis.axis); key = axis_to_key(false, (events.jaxis.value > 0), events.jaxis.axis);
it2=m_map_images[events.jaxis.which].find(key); it2 = m_map_images[events.jaxis.which].find(key);
if(it2 != m_map_images[events.jaxis.which].end()) if (it2 != m_map_images[events.jaxis.which].end()) {
{
map = m_map_images[events.jaxis.which][key]; map = m_map_images[events.jaxis.which][key];
if(map < PAD_L_UP) { // if this is not a joystick if (map < PAD_L_UP) { // if this is not a joystick
m_pan_tabs[events.jaxis.which]->HideImg(map); m_pan_tabs[events.jaxis.which]->HideImg(map);
} }
break; break;
@ -477,63 +457,53 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
} }
break; break;
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
if(events.jbutton.which < GAMEPAD_NUMBER) if (events.jbutton.which < GAMEPAD_NUMBER) {
{
key = button_to_key(events.jbutton.button); key = button_to_key(events.jbutton.button);
it=m_map_images[events.jbutton.which].find(key); it = m_map_images[events.jbutton.which].find(key);
if(it != m_map_images[events.jbutton.which].end()) if (it != m_map_images[events.jbutton.which].end()) {
{
map = m_map_images[events.jbutton.which][key]; map = m_map_images[events.jbutton.which][key];
m_pan_tabs[events.jbutton.which]->ShowImg(map); m_pan_tabs[events.jbutton.which]->ShowImg(map);
} }
} }
break; break;
case SDL_JOYBUTTONUP: case SDL_JOYBUTTONUP:
if(events.jbutton.which < GAMEPAD_NUMBER) if (events.jbutton.which < GAMEPAD_NUMBER) {
{
key = button_to_key(events.jbutton.button); key = button_to_key(events.jbutton.button);
it=m_map_images[events.jbutton.which].find(key); it = m_map_images[events.jbutton.which].find(key);
if(it != m_map_images[events.jbutton.which].end()) if (it != m_map_images[events.jbutton.which].end()) {
{
map = m_map_images[events.jbutton.which][key]; map = m_map_images[events.jbutton.which][key];
m_pan_tabs[events.jbutton.which]->HideImg(map); m_pan_tabs[events.jbutton.which]->HideImg(map);
} }
} }
break; break;
case SDL_JOYHATMOTION: case SDL_JOYHATMOTION:
if(events.jhat.which < GAMEPAD_NUMBER) if (events.jhat.which < GAMEPAD_NUMBER) {
{ switch (events.jhat.value) {
switch(events.jhat.value)
{
case SDL_HAT_UP: case SDL_HAT_UP:
key = hat_to_key(events.jhat.value, events.jhat.hat); key = hat_to_key(events.jhat.value, events.jhat.hat);
it=m_map_images[events.jhat.which].find(key); it = m_map_images[events.jhat.which].find(key);
if(it != m_map_images[events.jhat.which].end()) if (it != m_map_images[events.jhat.which].end()) {
{
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_up); m_pan_tabs[events.jhat.which]->ShowImg(img_dp_up);
} }
break; break;
case SDL_HAT_DOWN: case SDL_HAT_DOWN:
key = hat_to_key(events.jhat.value, events.jhat.hat); key = hat_to_key(events.jhat.value, events.jhat.hat);
it=m_map_images[events.jhat.which].find(key); it = m_map_images[events.jhat.which].find(key);
if(it != m_map_images[events.jhat.which].end()) if (it != m_map_images[events.jhat.which].end()) {
{
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_bottom); m_pan_tabs[events.jhat.which]->ShowImg(img_dp_bottom);
} }
break; break;
case SDL_HAT_RIGHT: case SDL_HAT_RIGHT:
key = hat_to_key(events.jhat.value, events.jhat.hat); key = hat_to_key(events.jhat.value, events.jhat.hat);
it=m_map_images[events.jhat.which].find(key); it = m_map_images[events.jhat.which].find(key);
if(it != m_map_images[events.jhat.which].end()) if (it != m_map_images[events.jhat.which].end()) {
{
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_right); m_pan_tabs[events.jhat.which]->ShowImg(img_dp_right);
} }
break; break;
case SDL_HAT_LEFT: case SDL_HAT_LEFT:
key = hat_to_key(events.jhat.value, events.jhat.hat); key = hat_to_key(events.jhat.value, events.jhat.hat);
it=m_map_images[events.jhat.which].find(key); it = m_map_images[events.jhat.which].find(key);
if(it != m_map_images[events.jhat.which].end()) if (it != m_map_images[events.jhat.which].end()) {
{
m_pan_tabs[events.jhat.which]->ShowImg(img_dp_left); m_pan_tabs[events.jhat.which]->ShowImg(img_dp_left);
} }
break; break;
@ -549,7 +519,7 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
break; break;
} }
} }
#endif // SDL_BUILD #endif // SDL_BUILD
} }
/****************************************/ /****************************************/
@ -558,62 +528,50 @@ void Dialog::JoystickEvent(wxTimerEvent& event)
void Dialog::config_key(int pad, int key) void Dialog::config_key(int pad, int key)
{ {
bool captured = false; bool captured = false;
u32 key_pressed = 0; u32 key_pressed = 0;
// I don't have any guarantee that not-yet-pressed state is egual to released state // I don't have any guarantee that not-yet-pressed state is egual to released state
GamePad::UpdateReleaseState(); GamePad::UpdateReleaseState();
while (!captured) while (!captured) {
{ vector<GamePad *>::iterator itjoy;
vector<GamePad*>::iterator itjoy; if (PollX11KeyboardMouseEvent(key_pressed)) {
if (PollX11KeyboardMouseEvent(key_pressed)) // special case for keyboard/mouse to handle multiple keys
{ // Note: key_pressed == 0 when ESC is hit to abort the capture
// special case for keyboard/mouse to handle multiple keys if (key_pressed > 0) {
// Note: key_pressed == 0 when ESC is hit to abort the capture
if (key_pressed > 0)
{
clear_key(pad, key); clear_key(pad, key);
set_keyboad_key(pad, key_pressed, key); set_keyboad_key(pad, key_pressed, key);
m_simulatedKeys[pad][key] = key_pressed; m_simulatedKeys[pad][key] = key_pressed;
m_map_images[pad][key_pressed] = key; m_map_images[pad][key_pressed] = key;
} }
captured = true; captured = true;
} } else {
else
{
GamePad::UpdateGamePadState(); GamePad::UpdateGamePadState();
itjoy = s_vgamePad.begin(); itjoy = s_vgamePad.begin();
while ((itjoy != s_vgamePad.end()) && (!captured)) while ((itjoy != s_vgamePad.end()) && (!captured)) {
{ if ((*itjoy)->PollButtons(key_pressed)) {
if ((*itjoy)->PollButtons(key_pressed))
{
clear_key(pad, key); clear_key(pad, key);
set_key(pad, key, key_pressed); set_key(pad, key, key_pressed);
m_map_images[pad][key_pressed] = key; m_map_images[pad][key_pressed] = key;
captured = true; captured = true;
} } else if ((*itjoy)->PollAxes(key_pressed)) {
else if((*itjoy)->PollAxes(key_pressed))
{
clear_key(pad, key); clear_key(pad, key);
set_key(pad, key, key_pressed); set_key(pad, key, key_pressed);
m_map_images[pad][key_pressed] = key; m_map_images[pad][key_pressed] = key;
captured = true; captured = true;
} } else if ((*itjoy)->PollHats(key_pressed)) {
else if((*itjoy)->PollHats(key_pressed))
{
clear_key(pad, key); clear_key(pad, key);
set_key(pad, key, key_pressed); set_key(pad, key, key_pressed);
m_map_images[pad][key_pressed] = key; m_map_images[pad][key_pressed] = key;
captured = true; captured = true;
} }
++itjoy; ++itjoy;
} }
} }
} }
m_bt_gamepad[pad][key]->SetLabel( m_bt_gamepad[pad][key]->SetLabel(
KeyName(pad, key, m_simulatedKeys[pad][key]).c_str() KeyName(pad, key, m_simulatedKeys[pad][key]).c_str());
);
} }
void Dialog::clear_key(int pad, int key) void Dialog::clear_key(int pad, int key)
@ -623,17 +581,16 @@ void Dialog::clear_key(int pad, int key)
m_simulatedKeys[pad][key] = 0; m_simulatedKeys[pad][key] = 0;
// erase gamepad entry (keysim map) // erase gamepad entry (keysim map)
std::map<u32,u32>::iterator it1; std::map<u32, u32>::iterator it1;
it1=conf->keysym_map[pad].find(keysim); it1 = conf->keysym_map[pad].find(keysim);
if(it1 != conf->keysym_map[pad].end()) if (it1 != conf->keysym_map[pad].end())
conf->keysym_map[pad].erase(it1); conf->keysym_map[pad].erase(it1);
// erase gamepad entry (image map) // erase gamepad entry (image map)
int val = get_key(pad, key); int val = get_key(pad, key);
std::map<u32,int>::iterator it2; std::map<u32, int>::iterator it2;
it2=m_map_images[pad].find(val); it2 = m_map_images[pad].find(val);
if(it2 != m_map_images[pad].end()) if (it2 != m_map_images[pad].end()) {
{
m_map_images[pad].erase(it2); m_map_images[pad].erase(it2);
} }
@ -647,31 +604,25 @@ void Dialog::clear_key(int pad, int key)
// Set button values // Set button values
void Dialog::repopulate() void Dialog::repopulate()
{ {
for(int gamepad_id=0; gamepad_id<GAMEPAD_NUMBER; ++gamepad_id) for (int gamepad_id = 0; gamepad_id < GAMEPAD_NUMBER; ++gamepad_id) {
{ for (int key = 0; key < MAX_KEYS; key++) {
for (int key = 0; key < MAX_KEYS; key++) if (get_key(gamepad_id, key) != 0) {
{
if (get_key(gamepad_id, key) != 0)
{
m_bt_gamepad[gamepad_id][key]->SetLabel( m_bt_gamepad[gamepad_id][key]->SetLabel(
KeyName(gamepad_id, key).c_str() KeyName(gamepad_id, key).c_str());
);
m_map_images[gamepad_id][get_key(gamepad_id, key)] = key; m_map_images[gamepad_id][get_key(gamepad_id, key)] = key;
} }
} }
// keyboard/mouse key // keyboard/mouse key
map<u32,u32>::iterator it; map<u32, u32>::iterator it;
for (it = conf->keysym_map[gamepad_id].begin(); for (it = conf->keysym_map[gamepad_id].begin();
it != conf->keysym_map[gamepad_id].end(); ++it) it != conf->keysym_map[gamepad_id].end(); ++it) {
{
int keysym = it->first; int keysym = it->first;
int key = it->second; int key = it->second;
m_bt_gamepad[gamepad_id][key]->SetLabel( m_bt_gamepad[gamepad_id][key]->SetLabel(
KeyName(gamepad_id, key, keysym).c_str() KeyName(gamepad_id, key, keysym).c_str());
);
m_simulatedKeys[gamepad_id][key] = keysym; m_simulatedKeys[gamepad_id][key] = keysym;
m_map_images[gamepad_id][keysym] = key; m_map_images[gamepad_id][keysym] = key;

View File

@ -48,17 +48,17 @@
// see onepad.h for more details about gamepad button id // see onepad.h for more details about gamepad button id
enum gui_buttons { enum gui_buttons {
Analog = PAD_R_LEFT+1, // Analog button (not yet supported ?) Analog = PAD_R_LEFT + 1, // Analog button (not yet supported ?)
JoyL_config, // Left Joystick Configuration JoyL_config, // Left Joystick Configuration
JoyR_config, // Right Joystick Configuration JoyR_config, // Right Joystick Configuration
Gamepad_config, // Gamepad Configuration Gamepad_config, // Gamepad Configuration
Set_all, // Set all buttons Set_all, // Set all buttons
Apply, // Apply modifications without exit Apply, // Apply modifications without exit
Ok, // Apply modifications and exit Ok, // Apply modifications and exit
Cancel // Exit without apply modificatons Cancel // Exit without apply modificatons
}; };
#define BUTTONS_LENGHT 32 // numbers of buttons on the gamepad #define BUTTONS_LENGHT 32 // numbers of buttons on the gamepad
#define UPDATE_TIME 5 #define UPDATE_TIME 5
#define DEFAULT_WIDTH 1000 #define DEFAULT_WIDTH 1000
#define DEFAULT_HEIGHT 740 #define DEFAULT_HEIGHT 740
@ -66,11 +66,11 @@ enum gui_buttons {
class Dialog : public wxDialog class Dialog : public wxDialog
{ {
// Panels // Panels
opPanel* m_pan_tabs[GAMEPAD_NUMBER]; // Gamepad Tabs box opPanel *m_pan_tabs[GAMEPAD_NUMBER]; // Gamepad Tabs box
// Notebooks // Notebooks
wxNotebook* m_tab_gamepad; // Joysticks Tabs wxNotebook *m_tab_gamepad; // Joysticks Tabs
// Buttons // Buttons
wxButton* m_bt_gamepad[GAMEPAD_NUMBER][BUTTONS_LENGHT]; // Joystick button use to modify the button mapping wxButton *m_bt_gamepad[GAMEPAD_NUMBER][BUTTONS_LENGHT]; // Joystick button use to modify the button mapping
// Contain all simulated key // Contain all simulated key
u32 m_simulatedKeys[GAMEPAD_NUMBER][MAX_KEYS]; u32 m_simulatedKeys[GAMEPAD_NUMBER][MAX_KEYS];
// Timer // Timer
@ -78,7 +78,7 @@ class Dialog : public wxDialog
// Check if the gui must display feddback image // Check if the gui must display feddback image
bool m_pressed[GAMEPAD_NUMBER][NB_IMG]; bool m_pressed[GAMEPAD_NUMBER][NB_IMG];
// Map the key pressed with the feedback image id // Map the key pressed with the feedback image id
std::map<u32,int> m_map_images[GAMEPAD_NUMBER]; std::map<u32, int> m_map_images[GAMEPAD_NUMBER];
// methods // methods
void config_key(int, int); void config_key(int, int);
@ -86,8 +86,8 @@ class Dialog : public wxDialog
void repopulate(); void repopulate();
// Events // Events
void OnButtonClicked(wxCommandEvent&); void OnButtonClicked(wxCommandEvent &);
void JoystickEvent(wxTimerEvent&); void JoystickEvent(wxTimerEvent &);
public: public:
Dialog(); Dialog();
@ -95,6 +95,6 @@ public:
void show(); void show();
}; };
extern void DisplayDialog(); // Main function extern void DisplayDialog(); // Main function
#endif // __DIALOG_H__ #endif // __DIALOG_H__

View File

@ -30,181 +30,186 @@ extern std::string s_strIniPath;
string KeyName(int pad, int key, int keysym) string KeyName(int pad, int key, int keysym)
{ {
string tmp; string tmp;
tmp.resize(28); tmp.resize(28);
if (keysym) { if (keysym) {
if (keysym < 10) { if (keysym < 10) {
// mouse // mouse
switch (keysym) { switch (keysym) {
case 1: sprintf(&tmp[0], "Mouse Left"); break; case 1:
case 2: sprintf(&tmp[0], "Mouse Middle"); break; sprintf(&tmp[0], "Mouse Left");
case 3: sprintf(&tmp[0], "Mouse Right"); break; break;
default: // Use only number for extra button case 2:
sprintf(&tmp[0], "Mouse %d", keysym); sprintf(&tmp[0], "Mouse Middle");
} break;
} else { case 3:
// keyboard sprintf(&tmp[0], "Mouse Right");
char* pstr = XKeysymToString(keysym); break;
if (pstr != NULL) tmp = pstr; default: // Use only number for extra button
} sprintf(&tmp[0], "Mouse %d", keysym);
} else { }
// joystick } else {
KeyType k = type_of_joykey(pad, key); // keyboard
switch (k) char *pstr = XKeysymToString(keysym);
{ if (pstr != NULL)
case PAD_JOYBUTTONS: tmp = pstr;
{ }
int button = key_to_button(pad, key); } else {
sprintf(&tmp[0], "JBut %d", button); // joystick
break; KeyType k = type_of_joykey(pad, key);
} switch (k) {
case PAD_AXIS: case PAD_JOYBUTTONS: {
{ int button = key_to_button(pad, key);
if (key_to_axis_type(pad,key)) sprintf(&tmp[0], "JBut %d", button);
sprintf(&tmp[0], "JAxis %d Full", key_to_axis(pad, key)); break;
else }
sprintf(&tmp[0], "JAxis %d Half%s", key_to_axis(pad, key), key_to_axis_sign(pad, key) ? "-" : "+"); case PAD_AXIS: {
break; if (key_to_axis_type(pad, key))
} sprintf(&tmp[0], "JAxis %d Full", key_to_axis(pad, key));
case PAD_HAT: else
{ sprintf(&tmp[0], "JAxis %d Half%s", key_to_axis(pad, key), key_to_axis_sign(pad, key) ? "-" : "+");
int axis = key_to_axis(pad, key); break;
switch(key_to_hat_dir(pad, key)) }
{ case PAD_HAT: {
case HAT_UP: int axis = key_to_axis(pad, key);
sprintf(&tmp[0], "JPOVU-%d", axis); switch (key_to_hat_dir(pad, key)) {
break; case HAT_UP:
sprintf(&tmp[0], "JPOVU-%d", axis);
break;
case HAT_RIGHT: case HAT_RIGHT:
sprintf(&tmp[0], "JPOVR-%d", axis); sprintf(&tmp[0], "JPOVR-%d", axis);
break; break;
case HAT_DOWN: case HAT_DOWN:
sprintf(&tmp[0], "JPOVD-%d", axis); sprintf(&tmp[0], "JPOVD-%d", axis);
break; break;
case HAT_LEFT: case HAT_LEFT:
sprintf(&tmp[0], "JPOVL-%d", axis); sprintf(&tmp[0], "JPOVL-%d", axis);
break; break;
} }
break; break;
} }
default: break; default:
} break;
} }
}
return tmp; return tmp;
} }
void DefaultKeyboardValues() void DefaultKeyboardValues()
{ {
set_keyboad_key(0, XK_a, PAD_L2); set_keyboad_key(0, XK_a, PAD_L2);
set_keyboad_key(0, XK_semicolon, PAD_R2); set_keyboad_key(0, XK_semicolon, PAD_R2);
set_keyboad_key(0, XK_w, PAD_L1); set_keyboad_key(0, XK_w, PAD_L1);
set_keyboad_key(0, XK_p, PAD_R1); set_keyboad_key(0, XK_p, PAD_R1);
set_keyboad_key(0, XK_i, PAD_TRIANGLE); set_keyboad_key(0, XK_i, PAD_TRIANGLE);
set_keyboad_key(0, XK_l, PAD_CIRCLE); set_keyboad_key(0, XK_l, PAD_CIRCLE);
set_keyboad_key(0, XK_k, PAD_CROSS); set_keyboad_key(0, XK_k, PAD_CROSS);
set_keyboad_key(0, XK_j, PAD_SQUARE); set_keyboad_key(0, XK_j, PAD_SQUARE);
set_keyboad_key(0, XK_v, PAD_SELECT); set_keyboad_key(0, XK_v, PAD_SELECT);
set_keyboad_key(0, XK_n, PAD_START); set_keyboad_key(0, XK_n, PAD_START);
set_keyboad_key(0, XK_e, PAD_UP); set_keyboad_key(0, XK_e, PAD_UP);
set_keyboad_key(0, XK_f, PAD_RIGHT); set_keyboad_key(0, XK_f, PAD_RIGHT);
set_keyboad_key(0, XK_d, PAD_DOWN); set_keyboad_key(0, XK_d, PAD_DOWN);
set_keyboad_key(0, XK_s, PAD_LEFT); set_keyboad_key(0, XK_s, PAD_LEFT);
} }
void SaveConfig() void SaveConfig()
{ {
FILE *f; FILE *f;
const std::string iniFile(s_strIniPath + "OnePAD.ini"); const std::string iniFile(s_strIniPath + "OnePAD.ini");
f = fopen(iniFile.c_str(), "w"); f = fopen(iniFile.c_str(), "w");
if (f == NULL) if (f == NULL) {
{ printf("OnePAD: failed to save ini %s\n", iniFile.c_str());
printf("OnePAD: failed to save ini %s\n", iniFile.c_str()); return;
return; }
}
fprintf(f, "log = %d\n", conf->log); fprintf(f, "log = %d\n", conf->log);
fprintf(f, "options = %d\n", conf->packed_options); fprintf(f, "options = %d\n", conf->packed_options);
fprintf(f, "mouse_sensibility = %d\n", conf->get_sensibility()); fprintf(f, "mouse_sensibility = %d\n", conf->get_sensibility());
fprintf(f, "joy_pad_map = %d\n", conf->joyid_map); fprintf(f, "joy_pad_map = %d\n", conf->joyid_map);
fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity()); fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity());
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
{ for (int key = 0; key < MAX_KEYS; key++) {
for (int key = 0; key < MAX_KEYS; key++) fprintf(f, "[%d][%d] = 0x%x\n", pad, key, get_key(pad, key));
{ }
fprintf(f, "[%d][%d] = 0x%x\n", pad, key, get_key(pad,key)); }
}
}
map<u32,u32>::iterator it; map<u32, u32>::iterator it;
for (int pad = 0; pad < GAMEPAD_NUMBER ; pad++) for (int pad = 0; pad < GAMEPAD_NUMBER; pad++)
for (it = conf->keysym_map[pad].begin(); it != conf->keysym_map[pad].end(); ++it) for (it = conf->keysym_map[pad].begin(); it != conf->keysym_map[pad].end(); ++it)
fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it->first, it->second); fprintf(f, "PAD %d:KEYSYM 0x%x = %d\n", pad, it->first, it->second);
fclose(f); fclose(f);
} }
void LoadConfig() void LoadConfig()
{ {
FILE *f; FILE *f;
char str[256]; char str[256];
bool have_user_setting = false; bool have_user_setting = false;
if (!conf) if (!conf)
conf = new PADconf; conf = new PADconf;
conf->init(); conf->init();
const std::string iniFile(s_strIniPath + "OnePAD.ini"); const std::string iniFile(s_strIniPath + "OnePAD.ini");
f = fopen(iniFile.c_str(), "r"); f = fopen(iniFile.c_str(), "r");
if (f == NULL) if (f == NULL) {
{ printf("OnePAD: failed to load ini %s\n", iniFile.c_str());
printf("OnePAD: failed to load ini %s\n", iniFile.c_str()); SaveConfig(); //save and return
SaveConfig(); //save and return return;
return; }
}
u32 value; u32 value;
if (fscanf(f, "log = %u\n", &value) == 0) goto error; if (fscanf(f, "log = %u\n", &value) == 0)
conf->log = value; goto error;
if (fscanf(f, "options = %u\n", &value) == 0) goto error; conf->log = value;
conf->packed_options = value; if (fscanf(f, "options = %u\n", &value) == 0)
if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0) goto error; goto error;
conf->set_sensibility(value); conf->packed_options = value;
if (fscanf(f, "joy_pad_map = %u\n", &value) == 0) goto error; if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0)
conf->joyid_map = value; goto error;
if (fscanf(f, "ff_intensity = %u\n", &value) == 0) goto error; conf->set_sensibility(value);
conf->set_ff_intensity(value); if (fscanf(f, "joy_pad_map = %u\n", &value) == 0)
goto error;
conf->joyid_map = value;
if (fscanf(f, "ff_intensity = %u\n", &value) == 0)
goto error;
conf->set_ff_intensity(value);
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
{ for (int key = 0; key < MAX_KEYS; key++) {
for (int key = 0; key < MAX_KEYS; key++) sprintf(str, "[%d][%d] = 0x%%x\n", pad, key);
{ u32 temp = 0;
sprintf(str, "[%d][%d] = 0x%%x\n", pad, key);
u32 temp = 0;
if (fscanf(f, str, &temp) == 0) temp = 0; if (fscanf(f, str, &temp) == 0)
set_key(pad, key, temp); temp = 0;
if (temp && pad == 0) have_user_setting = true; set_key(pad, key, temp);
} if (temp && pad == 0)
} have_user_setting = true;
}
}
u32 pad; u32 pad;
u32 keysym; u32 keysym;
u32 index; u32 index;
while( fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) != EOF ) { while (fscanf(f, "PAD %u:KEYSYM 0x%x = %u\n", &pad, &keysym, &index) != EOF) {
set_keyboad_key(pad & 1, keysym, index); set_keyboad_key(pad & 1, keysym, index);
if(pad == 0) have_user_setting = true; if (pad == 0)
} have_user_setting = true;
}
if (!have_user_setting) DefaultKeyboardValues(); if (!have_user_setting)
DefaultKeyboardValues();
error: error:
fclose(f); fclose(f);
} }

View File

@ -29,7 +29,7 @@
#include "linux.h" #include "linux.h"
Display *GSdsp; Display *GSdsp;
Window GSwin; Window GSwin;
void SysMessage(const char *fmt, ...) void SysMessage(const char *fmt, ...)
{ {
@ -40,163 +40,164 @@ void SysMessage(const char *fmt, ...)
vsprintf(msg, fmt, list); vsprintf(msg, fmt, list);
va_end(list); va_end(list);
if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; if (msg[strlen(msg) - 1] == '\n')
msg[strlen(msg) - 1] = 0;
GtkWidget *dialog; GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL, dialog = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO, GTK_MESSAGE_INFO,
GTK_BUTTONS_OK, GTK_BUTTONS_OK,
"%s", msg); "%s", msg);
gtk_dialog_run (GTK_DIALOG (dialog)); gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy (dialog); gtk_widget_destroy(dialog);
} }
EXPORT_C_(void) PADabout() EXPORT_C_(void)
PADabout()
{ {
SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42."); SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42.");
} }
EXPORT_C_(s32) PADtest() EXPORT_C_(s32)
PADtest()
{ {
return 0; return 0;
} }
s32 _PADopen(void *pDsp) s32 _PADopen(void *pDsp)
{ {
GSdsp = *(Display**)pDsp; GSdsp = *(Display **)pDsp;
GSwin = (Window)*(((u32*)pDsp)+1); GSwin = (Window) * (((u32 *)pDsp) + 1);
SetAutoRepeat(false); SetAutoRepeat(false);
return 0; return 0;
} }
void _PADclose() void _PADclose()
{ {
SetAutoRepeat(true); SetAutoRepeat(true);
vector<GamePad*>::iterator it = s_vgamePad.begin(); vector<GamePad *>::iterator it = s_vgamePad.begin();
// Delete everything in the vector vjoysticks. // Delete everything in the vector vjoysticks.
while (it != s_vgamePad.end()) while (it != s_vgamePad.end()) {
{ delete *it;
delete *it; ++it;
++it; }
}
s_vgamePad.clear(); s_vgamePad.clear();
} }
void PollForJoystickInput(int cpad) void PollForJoystickInput(int cpad)
{ {
int joyid = conf->get_joyid(cpad); int joyid = conf->get_joyid(cpad);
if (!GamePadIdWithinBounds(joyid)) return; if (!GamePadIdWithinBounds(joyid))
return;
GamePad::UpdateGamePadState(); GamePad::UpdateGamePadState();
for (int i = 0; i < MAX_KEYS; i++) for (int i = 0; i < MAX_KEYS; i++) {
{ GamePad *gamePad = s_vgamePad[joyid];
GamePad* gamePad = s_vgamePad[joyid];
switch (type_of_joykey(cpad, i)) switch (type_of_joykey(cpad, i)) {
{ case PAD_JOYBUTTONS: {
case PAD_JOYBUTTONS:
{
int value = gamePad->GetButton(key_to_button(cpad, i)); int value = gamePad->GetButton(key_to_button(cpad, i));
if (value) if (value)
key_status->press(cpad, i); key_status->press(cpad, i);
else else
key_status->release(cpad, i); key_status->release(cpad, i);
break; break;
} }
case PAD_HAT: case PAD_HAT: {
{ int value = gamePad->GetHat(key_to_axis(cpad, i));
int value = gamePad->GetHat(key_to_axis(cpad, i));
// key_to_hat_dir and SDL_JoystickGetHat are a 4 bits bitmap, one for each directions. Only 1 bit can be high for // key_to_hat_dir and SDL_JoystickGetHat are a 4 bits bitmap, one for each directions. Only 1 bit can be high for
// key_to_hat_dir. SDL_JoystickGetHat handles diagonal too (2 bits) so you must check the intersection // key_to_hat_dir. SDL_JoystickGetHat handles diagonal too (2 bits) so you must check the intersection
// '&' not only equality '=='. -- Gregory // '&' not only equality '=='. -- Gregory
if (key_to_hat_dir(cpad, i) & value) if (key_to_hat_dir(cpad, i) & value)
key_status->press(cpad, i); key_status->press(cpad, i);
else else
key_status->release(cpad, i); key_status->release(cpad, i);
break; break;
} }
case PAD_AXIS: case PAD_AXIS: {
{ int value = gamePad->GetAxisFromKey(cpad, i);
int value = gamePad->GetAxisFromKey(cpad, i); bool sign = key_to_axis_sign(cpad, i);
bool sign = key_to_axis_sign(cpad, i); bool full_axis = key_to_axis_type(cpad, i);
bool full_axis = key_to_axis_type(cpad, i);
if (IsAnalogKey(i)) { if (IsAnalogKey(i)) {
if (abs(value) > gamePad->GetDeadzone()) if (abs(value) > gamePad->GetDeadzone())
key_status->press(cpad, i, value); key_status->press(cpad, i, value);
else else
key_status->release(cpad, i); key_status->release(cpad, i);
} else { } else {
if (full_axis) { if (full_axis) {
value += 0x8000; value += 0x8000;
if (value > gamePad->GetDeadzone()) if (value > gamePad->GetDeadzone())
key_status->press(cpad, i, min(value/256 , 0xFF)); key_status->press(cpad, i, min(value / 256, 0xFF));
else else
key_status->release(cpad, i); key_status->release(cpad, i);
} else { } else {
if (sign && (-value > gamePad->GetDeadzone())) if (sign && (-value > gamePad->GetDeadzone()))
key_status->press(cpad, i, min(-value /128, 0xFF)); key_status->press(cpad, i, min(-value / 128, 0xFF));
else if (!sign && (value > gamePad->GetDeadzone())) else if (!sign && (value > gamePad->GetDeadzone()))
key_status->press(cpad, i, min(value /128, 0xFF)); key_status->press(cpad, i, min(value / 128, 0xFF));
else else
key_status->release(cpad, i); key_status->release(cpad, i);
} }
} }
} }
default: break; default:
} break;
} }
}
} }
EXPORT_C_(void) PADupdate(int pad) EXPORT_C_(void)
PADupdate(int pad)
{ {
// Gamepad inputs don't count as an activity. Therefore screensaver will // Gamepad inputs don't count as an activity. Therefore screensaver will
// be fired after a couple of minute. // be fired after a couple of minute.
// Emulate an user activity // Emulate an user activity
static int count = 0; static int count = 0;
count++; count++;
if ((count & 0xFFF) == 0) { if ((count & 0xFFF) == 0) {
// 1 call every 4096 Vsync is enough // 1 call every 4096 Vsync is enough
XResetScreenSaver(GSdsp); XResetScreenSaver(GSdsp);
} }
// Actually PADupdate is always call with pad == 0. So you need to update both // Actually PADupdate is always call with pad == 0. So you need to update both
// pads -- Gregory // pads -- Gregory
// Poll keyboard/mouse event. There is currently no way to separate pad0 from pad1 event. // Poll keyboard/mouse event. There is currently no way to separate pad0 from pad1 event.
// So we will populate both pad in the same time // So we will populate both pad in the same time
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) { for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
key_status->keyboard_state_acces(cpad); key_status->keyboard_state_acces(cpad);
} }
PollForX11KeyboardInput(); PollForX11KeyboardInput();
// Get joystick state + Commit // Get joystick state + Commit
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) { for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
key_status->joystick_state_acces(cpad); key_status->joystick_state_acces(cpad);
PollForJoystickInput(cpad); PollForJoystickInput(cpad);
key_status->commit_status(cpad); key_status->commit_status(cpad);
} }
Pad::rumble_all(); Pad::rumble_all();
} }
EXPORT_C_(void) PADconfigure() EXPORT_C_(void)
PADconfigure()
{ {
LoadConfig(); LoadConfig();
DisplayDialog(); DisplayDialog();
return; return;
} }

View File

@ -43,10 +43,10 @@
#include "ImgHeader/arrow_left.h" #include "ImgHeader/arrow_left.h"
opPanel::opPanel(wxWindow *parent, opPanel::opPanel(wxWindow *parent,
wxWindowID id=wxID_ANY, wxWindowID id = wxID_ANY,
const wxPoint &pos=wxDefaultPosition, const wxPoint &pos = wxDefaultPosition,
const wxSize &size=wxDefaultSize const wxSize &size = wxDefaultSize)
): wxPanel( parent, id, pos, size) : wxPanel(parent, id, pos, size)
{ {
m_picture[img_background] = EmbeddedImage<res_dualshock2>().Get(); m_picture[img_background] = EmbeddedImage<res_dualshock2>().Get();
@ -85,8 +85,7 @@ opPanel::opPanel(wxWindow *parent,
m_picture[img_r_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get(); m_picture[img_r_arrow_bottom] = EmbeddedImage<res_arrow_bottom>().Get();
m_picture[img_r_arrow_left] = EmbeddedImage<res_arrow_left>().Get(); m_picture[img_r_arrow_left] = EmbeddedImage<res_arrow_left>().Get();
for(int i=0; i<NB_IMG; ++i) for (int i = 0; i < NB_IMG; ++i) {
{
m_show_image[i] = false; m_show_image[i] = false;
HideImg(i); HideImg(i);
} }
@ -101,8 +100,7 @@ opPanel::opPanel(wxWindow *parent,
void opPanel::HideImg(int id) void opPanel::HideImg(int id)
{ {
if(id < NB_IMG) if (id < NB_IMG) {
{
m_show_image[id] = false; m_show_image[id] = false;
Refresh(); Refresh();
} }
@ -110,47 +108,39 @@ void opPanel::HideImg(int id)
void opPanel::ShowImg(int id) void opPanel::ShowImg(int id)
{ {
if(id < NB_IMG) if (id < NB_IMG) {
{
m_show_image[id] = true; m_show_image[id] = true;
Refresh(); Refresh();
} }
} }
void opPanel::MoveJoystick(int axe,int value) void opPanel::MoveJoystick(int axe, int value)
{ {
if(axe == 0) if (axe == 0) {
{ m_left_cursor_x = value * 30 / 40000;
m_left_cursor_x = value*30/40000; } else if (axe == 1) {
} m_left_cursor_y = value * 30 / 40000;
else if(axe == 1) } else if (axe == 2) {
{ m_right_cursor_x = value * 30 / 40000;
m_left_cursor_y = value*30/40000; } else {
} m_right_cursor_y = value * 30 / 40000;
else if( axe == 2)
{
m_right_cursor_x = value*30/40000;
}
else
{
m_right_cursor_y = value*30/40000;
} }
} }
BEGIN_EVENT_TABLE(opPanel, wxPanel) BEGIN_EVENT_TABLE(opPanel, wxPanel)
EVT_PAINT(opPanel::OnPaint) EVT_PAINT(opPanel::OnPaint)
END_EVENT_TABLE() END_EVENT_TABLE()
void opPanel::OnPaint(wxPaintEvent& event) void opPanel::OnPaint(wxPaintEvent &event)
{ {
wxPaintDC dc(this); wxPaintDC dc(this);
wxMemoryDC temp_background, temp_start, temp_select, temp_analog, temp_dp_left, wxMemoryDC temp_background, temp_start, temp_select, temp_analog, temp_dp_left,
temp_dp_right, temp_dp_up, temp_dp_bottom, temp_l1, temp_r1, temp_L3, temp_l2_2, temp_dp_right, temp_dp_up, temp_dp_bottom, temp_l1, temp_r1, temp_L3, temp_l2_2,
temp_R3, temp_r2_2, temp_square, temp_circle, temp_cross, temp_triangle, temp_R3, temp_r2_2, temp_square, temp_circle, temp_cross, temp_triangle,
temp_left_cursor, temp_right_cursor, temp_l_arrow_up, temp_l_arrow_right, temp_left_cursor, temp_right_cursor, temp_l_arrow_up, temp_l_arrow_right,
temp_l_arrow_bottom, temp_l_arrow_left, temp_r_arrow_up, temp_r_arrow_right, temp_l_arrow_bottom, temp_l_arrow_left, temp_r_arrow_up, temp_r_arrow_right,
temp_r_arrow_bottom, temp_r_arrow_left; temp_r_arrow_bottom, temp_r_arrow_left;
temp_background.SelectObject(m_picture[img_background]); temp_background.SelectObject(m_picture[img_background]);
temp_start.SelectObject(m_picture[img_start]); temp_start.SelectObject(m_picture[img_start]);
@ -186,62 +176,62 @@ void opPanel::OnPaint(wxPaintEvent& event)
temp_r_arrow_bottom.SelectObject(m_picture[img_r_arrow_bottom]); temp_r_arrow_bottom.SelectObject(m_picture[img_r_arrow_bottom]);
temp_r_arrow_left.SelectObject(m_picture[img_r_arrow_left]); temp_r_arrow_left.SelectObject(m_picture[img_r_arrow_left]);
if(m_show_image[img_background]) if (m_show_image[img_background])
dc.Blit(wxPoint(0, 0), temp_background.GetSize(), &temp_background, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(0, 0), temp_background.GetSize(), &temp_background, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_start]) if (m_show_image[img_start])
dc.Blit(wxPoint(526, 296), temp_start.GetSize(), &temp_start, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(526, 296), temp_start.GetSize(), &temp_start, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_select]) if (m_show_image[img_select])
dc.Blit(wxPoint(450, 297), temp_select.GetSize(), &temp_select, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(450, 297), temp_select.GetSize(), &temp_select, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_analog]) if (m_show_image[img_analog])
dc.Blit(wxPoint(489, 358), temp_analog.GetSize(), &temp_analog, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(489, 358), temp_analog.GetSize(), &temp_analog, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_dp_left]) if (m_show_image[img_dp_left])
dc.Blit(wxPoint(334, 292), temp_dp_left.GetSize(), &temp_dp_left, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(334, 292), temp_dp_left.GetSize(), &temp_dp_left, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_dp_right]) if (m_show_image[img_dp_right])
dc.Blit(wxPoint(378, 292), temp_dp_right.GetSize(), &temp_dp_right, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(378, 292), temp_dp_right.GetSize(), &temp_dp_right, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_dp_up]) if (m_show_image[img_dp_up])
dc.Blit(wxPoint(358, 269), temp_dp_up.GetSize(), &temp_dp_up, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(358, 269), temp_dp_up.GetSize(), &temp_dp_up, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_dp_bottom]) if (m_show_image[img_dp_bottom])
dc.Blit(wxPoint(358, 312), temp_dp_bottom.GetSize(), &temp_dp_bottom, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(358, 312), temp_dp_bottom.GetSize(), &temp_dp_bottom, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_l1]) if (m_show_image[img_l1])
dc.Blit(wxPoint(343, 186), temp_l1.GetSize(), &temp_l1, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(343, 186), temp_l1.GetSize(), &temp_l1, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_r1]) if (m_show_image[img_r1])
dc.Blit(wxPoint(593, 186), temp_r1.GetSize(), &temp_r1, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(593, 186), temp_r1.GetSize(), &temp_r1, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_l3]) if (m_show_image[img_l3])
dc.Blit(wxPoint(409, 344), temp_L3.GetSize(), &temp_L3, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(409, 344), temp_L3.GetSize(), &temp_L3, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_l2]) if (m_show_image[img_l2])
dc.Blit(wxPoint(346, 158), temp_l2_2.GetSize(), &temp_l2_2, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(346, 158), temp_l2_2.GetSize(), &temp_l2_2, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_r3]) if (m_show_image[img_r3])
dc.Blit(wxPoint(525, 344), temp_R3.GetSize(), &temp_R3, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(525, 344), temp_R3.GetSize(), &temp_R3, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_r2]) if (m_show_image[img_r2])
dc.Blit(wxPoint(582, 158), temp_r2_2.GetSize(), &temp_r2_2, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(582, 158), temp_r2_2.GetSize(), &temp_r2_2, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_square]) if (m_show_image[img_square])
dc.Blit(wxPoint(573, 287), temp_square.GetSize(), &temp_square, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(573, 287), temp_square.GetSize(), &temp_square, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_circle]) if (m_show_image[img_circle])
dc.Blit(wxPoint(647, 287), temp_circle.GetSize(), &temp_circle, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(647, 287), temp_circle.GetSize(), &temp_circle, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_cross]) if (m_show_image[img_cross])
dc.Blit(wxPoint(610, 324), temp_cross.GetSize(), &temp_cross, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(610, 324), temp_cross.GetSize(), &temp_cross, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_triangle]) if (m_show_image[img_triangle])
dc.Blit(wxPoint(610, 250), temp_triangle.GetSize(), &temp_triangle, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(610, 250), temp_triangle.GetSize(), &temp_triangle, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_left_cursor]) if (m_show_image[img_left_cursor])
dc.Blit(wxPoint(439+m_left_cursor_x, 374+m_left_cursor_y), temp_left_cursor.GetSize(), &temp_left_cursor, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(439 + m_left_cursor_x, 374 + m_left_cursor_y), temp_left_cursor.GetSize(), &temp_left_cursor, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_right_cursor]) if (m_show_image[img_right_cursor])
dc.Blit(wxPoint(555+m_right_cursor_x, 374+m_right_cursor_y), temp_right_cursor.GetSize(), &temp_right_cursor, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(555 + m_right_cursor_x, 374 + m_right_cursor_y), temp_right_cursor.GetSize(), &temp_right_cursor, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_l_arrow_up]) if (m_show_image[img_l_arrow_up])
dc.Blit(wxPoint(433, 357), temp_l_arrow_up.GetSize(), &temp_l_arrow_up, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(433, 357), temp_l_arrow_up.GetSize(), &temp_l_arrow_up, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_l_arrow_right]) if (m_show_image[img_l_arrow_right])
dc.Blit(wxPoint(423, 368), temp_l_arrow_right.GetSize(), &temp_l_arrow_right, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(423, 368), temp_l_arrow_right.GetSize(), &temp_l_arrow_right, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_l_arrow_bottom]) if (m_show_image[img_l_arrow_bottom])
dc.Blit(wxPoint(433, 357), temp_l_arrow_bottom.GetSize(), &temp_l_arrow_bottom, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(433, 357), temp_l_arrow_bottom.GetSize(), &temp_l_arrow_bottom, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_l_arrow_left]) if (m_show_image[img_l_arrow_left])
dc.Blit(wxPoint(423, 368), temp_l_arrow_left.GetSize(), &temp_l_arrow_left, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(423, 368), temp_l_arrow_left.GetSize(), &temp_l_arrow_left, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_r_arrow_up]) if (m_show_image[img_r_arrow_up])
dc.Blit(wxPoint(548, 357), temp_r_arrow_up.GetSize(), &temp_r_arrow_up, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(548, 357), temp_r_arrow_up.GetSize(), &temp_r_arrow_up, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_r_arrow_right]) if (m_show_image[img_r_arrow_right])
dc.Blit(wxPoint(539, 368), temp_r_arrow_right.GetSize(), &temp_r_arrow_right, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(539, 368), temp_r_arrow_right.GetSize(), &temp_r_arrow_right, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_r_arrow_bottom]) if (m_show_image[img_r_arrow_bottom])
dc.Blit(wxPoint(548, 357), temp_r_arrow_bottom.GetSize(), &temp_r_arrow_bottom, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(548, 357), temp_r_arrow_bottom.GetSize(), &temp_r_arrow_bottom, wxPoint(0, 0), wxCOPY, true);
if(m_show_image[img_r_arrow_left]) if (m_show_image[img_r_arrow_left])
dc.Blit(wxPoint(539, 368), temp_r_arrow_left.GetSize(), &temp_r_arrow_left, wxPoint(0, 0), wxCOPY, true); dc.Blit(wxPoint(539, 368), temp_r_arrow_left.GetSize(), &temp_r_arrow_left, wxPoint(0, 0), wxCOPY, true);
} }

View File

@ -46,7 +46,7 @@ enum gui_img {
img_left_cursor, img_left_cursor,
img_right_cursor, img_right_cursor,
img_analog, img_analog,
img_background, // background pic img_background, // background pic
img_l_arrow_up, img_l_arrow_up,
img_l_arrow_right, img_l_arrow_right,
img_l_arrow_bottom, img_l_arrow_bottom,
@ -65,13 +65,13 @@ class opPanel : public wxPanel
bool m_show_image[NB_IMG]; bool m_show_image[NB_IMG];
int m_left_cursor_x, m_left_cursor_y, m_right_cursor_x, m_right_cursor_y; int m_left_cursor_x, m_left_cursor_y, m_right_cursor_x, m_right_cursor_y;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent &event);
public: public:
opPanel(wxWindow*, wxWindowID, const wxPoint&, const wxSize&); opPanel(wxWindow *, wxWindowID, const wxPoint &, const wxSize &);
void HideImg(int); void HideImg(int);
void ShowImg(int); void ShowImg(int);
void MoveJoystick(int, int); void MoveJoystick(int, int);
}; };
#endif // __OPPANEL_H__ #endif // __OPPANEL_H__

View File

@ -20,7 +20,7 @@
*/ */
#include "joystick.h" #include "joystick.h"
#include <signal.h> // sigaction #include <signal.h> // sigaction
////////////////////////// //////////////////////////
// Joystick definitions // // Joystick definitions //
@ -30,349 +30,334 @@ static u32 s_bSDLInit = false;
void JoystickInfo::UpdateReleaseState() void JoystickInfo::UpdateReleaseState()
{ {
vector<GamePad*>::iterator itjoy = s_vgamePad.begin(); vector<GamePad *>::iterator itjoy = s_vgamePad.begin();
SDL_JoystickUpdate(); SDL_JoystickUpdate();
// Save everything in the vector s_vjoysticks. // Save everything in the vector s_vjoysticks.
while (itjoy != s_vgamePad.end()) while (itjoy != s_vgamePad.end()) {
{ (*itjoy)->SaveState();
(*itjoy)->SaveState(); ++itjoy;
++itjoy; }
}
} }
// opens handles to all possible joysticks // opens handles to all possible joysticks
void JoystickInfo::EnumerateJoysticks(vector<GamePad*>& vjoysticks) void JoystickInfo::EnumerateJoysticks(vector<GamePad *> &vjoysticks)
{ {
if (!s_bSDLInit) if (!s_bSDLInit) {
{
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
// Tell SDL to catch event even if the windows isn't focussed // Tell SDL to catch event even if the windows isn't focussed
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
if (SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_HAPTIC|SDL_INIT_EVENTS) < 0) return; if (SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_EVENTS) < 0)
// WTF! Give me back the control of my system return;
struct sigaction action = { 0 }; // WTF! Give me back the control of my system
action.sa_handler = SIG_DFL; struct sigaction action = {0};
sigaction(SIGINT, &action, NULL); action.sa_handler = SIG_DFL;
sigaction(SIGTERM, &action, NULL); sigaction(SIGINT, &action, NULL);
sigaction(SIGTERM, &action, NULL);
#else #else
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) return; if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
return;
#endif #endif
SDL_JoystickEventState(SDL_QUERY); SDL_JoystickEventState(SDL_QUERY);
s_bSDLInit = true; s_bSDLInit = true;
} }
vector<GamePad*>::iterator it = vjoysticks.begin(); vector<GamePad *>::iterator it = vjoysticks.begin();
// Delete everything in the vector vjoysticks. // Delete everything in the vector vjoysticks.
while (it != vjoysticks.end()) while (it != vjoysticks.end()) {
{ delete *it;
delete *it; ++it;
++it; }
}
vjoysticks.resize(SDL_NumJoysticks()); vjoysticks.resize(SDL_NumJoysticks());
for (int i = 0; i < (int)vjoysticks.size(); ++i) for (int i = 0; i < (int)vjoysticks.size(); ++i) {
{ vjoysticks[i] = new JoystickInfo();
vjoysticks[i] = new JoystickInfo(); vjoysticks[i]->Init(i);
vjoysticks[i]->Init(i); }
}
} }
void JoystickInfo::GenerateDefaultEffect() void JoystickInfo::GenerateDefaultEffect()
{ {
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
for(int i=0;i<NB_EFFECT;i++) for (int i = 0; i < NB_EFFECT; i++) {
{ SDL_HapticEffect effect;
SDL_HapticEffect effect; memset(&effect, 0, sizeof(SDL_HapticEffect)); // 0 is safe default
memset( &effect, 0, sizeof(SDL_HapticEffect) ); // 0 is safe default SDL_HapticDirection direction;
SDL_HapticDirection direction; direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding.
direction.type = SDL_HAPTIC_POLAR; // We'll be using polar direction encoding. direction.dir[0] = 18000;
direction.dir[0] = 18000; effect.periodic.direction = direction;
effect.periodic.direction = direction; effect.periodic.period = 10;
effect.periodic.period = 10; effect.periodic.magnitude = (Sint16)(conf->get_ff_intensity()); // Effect at maximum instensity
effect.periodic.magnitude = (Sint16)(conf->get_ff_intensity()); // Effect at maximum instensity effect.periodic.offset = 0;
effect.periodic.offset = 0; effect.periodic.phase = 18000;
effect.periodic.phase = 18000; effect.periodic.length = 125; // 125ms feels quite near to original
effect.periodic.length = 125; // 125ms feels quite near to original effect.periodic.delay = 0;
effect.periodic.delay = 0; effect.periodic.attack_length = 0;
effect.periodic.attack_length = 0; effects[i] = effect;
effects[i] = effect; }
}
#endif #endif
} }
void JoystickInfo::Rumble(int type, int pad) void JoystickInfo::Rumble(int type, int pad)
{ {
if (type > 1) return; if (type > 1)
if ( !(conf->pad_options[pad].forcefeedback) ) return; return;
if (!(conf->pad_options[pad].forcefeedback))
return;
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
if (haptic == NULL) return; if (haptic == NULL)
return;
if(first) if (first) { // If done multiple times, device memory will be filled
{// If done multiple times, device memory will be filled first = 0;
first = 0; GenerateDefaultEffect();
GenerateDefaultEffect(); /** Sine and triangle are quite probably the best, don't change that lightly and if you do
/** Sine and triangle are quite probably the best, don't change that lightly and if you do
* keep effects ordered by type * keep effects ordered by type
**/ **/
/** Effect for small motor **/ /** Effect for small motor **/
/** Sine seems to be the only effect making little motor from DS3/4 react /** Sine seems to be the only effect making little motor from DS3/4 react
* Intensity has pretty much no effect either(which is coherent with what is explain in hid_sony driver * Intensity has pretty much no effect either(which is coherent with what is explain in hid_sony driver
**/ **/
effects[0].type = SDL_HAPTIC_SINE; effects[0].type = SDL_HAPTIC_SINE;
effects_id[0] = SDL_HapticNewEffect(haptic, &effects[0]); effects_id[0] = SDL_HapticNewEffect(haptic, &effects[0]);
if(effects_id[0] < 0) if (effects_id[0] < 0) {
{ fprintf(stderr, "ERROR: Effect is not uploaded! %s, id is %d\n", SDL_GetError(), effects_id[0]);
fprintf(stderr,"ERROR: Effect is not uploaded! %s, id is %d\n",SDL_GetError(),effects_id[0]); }
}
/** Effect for big motor **/ /** Effect for big motor **/
effects[1].type = SDL_HAPTIC_TRIANGLE; effects[1].type = SDL_HAPTIC_TRIANGLE;
effects_id[1] = SDL_HapticNewEffect(haptic, &effects[1]); effects_id[1] = SDL_HapticNewEffect(haptic, &effects[1]);
if(effects_id[1] < 0) if (effects_id[1] < 0) {
{ fprintf(stderr, "ERROR: Effect is not uploaded! %s, id is %d\n", SDL_GetError(), effects_id[1]);
fprintf(stderr,"ERROR: Effect is not uploaded! %s, id is %d\n",SDL_GetError(),effects_id[1]); }
} }
}
int id; int id;
id = effects_id[type]; id = effects_id[type];
if(SDL_HapticRunEffect(haptic, id, 1) != 0) if (SDL_HapticRunEffect(haptic, id, 1) != 0) {
{ fprintf(stderr, "ERROR: Effect is not working! %s, id is %d\n", SDL_GetError(), id);
fprintf(stderr,"ERROR: Effect is not working! %s, id is %d\n",SDL_GetError(),id); }
}
#endif #endif
} }
void JoystickInfo::Destroy() void JoystickInfo::Destroy()
{ {
if (joy != NULL) if (joy != NULL) {
{
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
// Haptic must be closed before the joystick // Haptic must be closed before the joystick
if (haptic != NULL) { if (haptic != NULL) {
SDL_HapticClose(haptic); SDL_HapticClose(haptic);
haptic = NULL; haptic = NULL;
} }
#endif #endif
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
#if SDL_MINOR_VERSION >= 4 // Version before 2.0.4 are bugged, JoystickClose crashes randomly #if SDL_MINOR_VERSION >= 4 // Version before 2.0.4 are bugged, JoystickClose crashes randomly
if (joy) SDL_JoystickClose(joy); if (joy)
SDL_JoystickClose(joy);
#endif #endif
#else #else
if (SDL_JoystickOpened(_id)) SDL_JoystickClose(joy); if (SDL_JoystickOpened(_id))
SDL_JoystickClose(joy);
#endif #endif
joy = NULL; joy = NULL;
} }
} }
bool JoystickInfo::Init(int id) bool JoystickInfo::Init(int id)
{ {
Destroy(); Destroy();
_id = id; _id = id;
joy = SDL_JoystickOpen(id); joy = SDL_JoystickOpen(id);
if (joy == NULL) if (joy == NULL) {
{ PAD_LOG("failed to open joystick %d\n", id);
PAD_LOG("failed to open joystick %d\n", id); return false;
return false; }
}
numaxes = SDL_JoystickNumAxes(joy); numaxes = SDL_JoystickNumAxes(joy);
numbuttons = SDL_JoystickNumButtons(joy); numbuttons = SDL_JoystickNumButtons(joy);
numhats = SDL_JoystickNumHats(joy); numhats = SDL_JoystickNumHats(joy);
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
devname = SDL_JoystickName(joy); devname = SDL_JoystickName(joy);
#else #else
devname = SDL_JoystickName(id); devname = SDL_JoystickName(id);
#endif #endif
vaxisstate.resize(numaxes); vaxisstate.resize(numaxes);
vbuttonstate.resize(numbuttons); vbuttonstate.resize(numbuttons);
vhatstate.resize(numhats); vhatstate.resize(numhats);
// Sixaxis, dualshock3 hack // Sixaxis, dualshock3 hack
// Most buttons are actually axes due to analog pressure support. Only the first 4 buttons // Most buttons are actually axes due to analog pressure support. Only the first 4 buttons
// are digital (select, start, l3, r3). To avoid conflict just forget the others. // are digital (select, start, l3, r3). To avoid conflict just forget the others.
// Keep the 4 hat buttons too (usb driver). (left pressure does not work with recent kernel). Moreover the pressure // Keep the 4 hat buttons too (usb driver). (left pressure does not work with recent kernel). Moreover the pressure
// work sometime on half axis neg others time in fulll axis. So better keep them as button for the moment // work sometime on half axis neg others time in fulll axis. So better keep them as button for the moment
u32 found_hack = devname.find(string("PLAYSTATION(R)3")); u32 found_hack = devname.find(string("PLAYSTATION(R)3"));
// FIXME: people need to restart the plugin to take the option into account. // FIXME: people need to restart the plugin to take the option into account.
bool hack_enabled = (conf->pad_options[0].sixaxis_pressure) || (conf->pad_options[1].sixaxis_pressure); bool hack_enabled = (conf->pad_options[0].sixaxis_pressure) || (conf->pad_options[1].sixaxis_pressure);
if (found_hack != string::npos && numaxes > 4 && hack_enabled) { if (found_hack != string::npos && numaxes > 4 && hack_enabled) {
numbuttons = 4; // (select, start, l3, r3) numbuttons = 4; // (select, start, l3, r3)
// Enable this hack in bluetooth too. It avoid to restart the onepad gui // Enable this hack in bluetooth too. It avoid to restart the onepad gui
numbuttons += 4; // the 4 hat buttons numbuttons += 4; // the 4 hat buttons
} }
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
if ( haptic == NULL ) { if (haptic == NULL) {
if (!SDL_JoystickIsHaptic(joy)) { if (!SDL_JoystickIsHaptic(joy)) {
PAD_LOG("Haptic devices not supported!\n"); PAD_LOG("Haptic devices not supported!\n");
} else { } else {
haptic = SDL_HapticOpenFromJoystick(joy); haptic = SDL_HapticOpenFromJoystick(joy);
first = true; first = true;
} }
} }
#endif #endif
//PAD_LOG("There are %d buttons, %d axises, and %d hats.\n", numbuttons, numaxes, numhats); //PAD_LOG("There are %d buttons, %d axises, and %d hats.\n", numbuttons, numaxes, numhats);
return true; return true;
} }
void JoystickInfo::SaveState() void JoystickInfo::SaveState()
{ {
for (int i = 0; i < numbuttons; ++i) for (int i = 0; i < numbuttons; ++i)
SetButtonState(i, SDL_JoystickGetButton(joy, i)); SetButtonState(i, SDL_JoystickGetButton(joy, i));
for (int i = 0; i < numaxes; ++i) for (int i = 0; i < numaxes; ++i)
SetAxisState(i, SDL_JoystickGetAxis(joy, i)); SetAxisState(i, SDL_JoystickGetAxis(joy, i));
for (int i = 0; i < numhats; ++i) for (int i = 0; i < numhats; ++i)
SetHatState(i, SDL_JoystickGetHat(joy, i)); SetHatState(i, SDL_JoystickGetHat(joy, i));
} }
bool JoystickInfo::TestForce(float strength=0.60) bool JoystickInfo::TestForce(float strength = 0.60)
{ {
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
// This code just use standard rumble to check that SDL handles the pad correctly! --3kinox // This code just use standard rumble to check that SDL handles the pad correctly! --3kinox
if(haptic == NULL) if (haptic == NULL)
return false; // Otherwise, core dump! return false; // Otherwise, core dump!
SDL_HapticRumbleInit( haptic ); SDL_HapticRumbleInit(haptic);
// Make the haptic pad rumble 60% strength for half a second, shoudld be enough for user to see if it works or not // Make the haptic pad rumble 60% strength for half a second, shoudld be enough for user to see if it works or not
if( SDL_HapticRumblePlay( haptic, strength, 400 ) != 0) if (SDL_HapticRumblePlay(haptic, strength, 400) != 0) {
{ fprintf(stderr, "ERROR: Rumble is not working! %s\n", SDL_GetError());
fprintf(stderr,"ERROR: Rumble is not working! %s\n",SDL_GetError()); return false;
return false; }
}
#endif #endif
return true; return true;
} }
bool JoystickInfo::PollButtons(u32 &pkey) bool JoystickInfo::PollButtons(u32 &pkey)
{ {
// MAKE sure to look for changes in the state!! // MAKE sure to look for changes in the state!!
for (int i = 0; i < GetNumButtons(); ++i) for (int i = 0; i < GetNumButtons(); ++i) {
{ int but = SDL_JoystickGetButton(GetJoy(), i);
int but = SDL_JoystickGetButton(GetJoy(), i); if (but != GetButtonState(i)) {
if (but != GetButtonState(i)) // Pressure sensitive button are detected as both button (digital) and axes (analog). So better
{ // drop the button to emulate the pressure sensiblity of the ds2 :)
// Pressure sensitive button are detected as both button (digital) and axes (analog). So better // Trick: detect the release of the button. It avoid all races condition between axes and buttons :)
// drop the button to emulate the pressure sensiblity of the ds2 :) // If the button support pressure it will be detected as an axis when it is pressed.
// Trick: detect the release of the button. It avoid all races condition between axes and buttons :) if (but) {
// If the button support pressure it will be detected as an axis when it is pressed. SetButtonState(i, but);
if (but) { return false;
SetButtonState(i, but); }
return false;
}
pkey = button_to_key(i); pkey = button_to_key(i);
return true; return true;
} }
} }
return false; return false;
} }
bool JoystickInfo::PollAxes(u32 &pkey) bool JoystickInfo::PollAxes(u32 &pkey)
{ {
u32 found_hack = devname.find(string("PLAYSTATION(R)3")); u32 found_hack = devname.find(string("PLAYSTATION(R)3"));
for (int i = 0; i < GetNumAxes(); ++i) for (int i = 0; i < GetNumAxes(); ++i) {
{ // Sixaxis, dualshock3 hack
// Sixaxis, dualshock3 hack if (found_hack != string::npos) {
if (found_hack != string::npos) { // The analog mode of the hat button is quite erratic. Values can be in half- axis
// The analog mode of the hat button is quite erratic. Values can be in half- axis // or full axis... So better keep them as button for the moment -- gregory
// or full axis... So better keep them as button for the moment -- gregory if (i >= 8 && i <= 11 && (conf->pad_options[pad].sixaxis_usb))
if (i >= 8 && i <= 11 && (conf->pad_options[pad].sixaxis_usb)) continue;
continue; // Disable accelerometer
// Disable accelerometer if ((i >= 4 && i <= 6))
if ((i >= 4 && i <= 6)) continue;
continue; }
}
s32 value = SDL_JoystickGetAxis(GetJoy(), i); s32 value = SDL_JoystickGetAxis(GetJoy(), i);
s32 old_value = GetAxisState(i); s32 old_value = GetAxisState(i);
if (abs(value - old_value) < 0x1000) if (abs(value - old_value) < 0x1000)
continue; continue;
if (value != old_value) if (value != old_value) {
{ PAD_LOG("Change in joystick %d: %d.\n", i, value);
PAD_LOG("Change in joystick %d: %d.\n", i, value); // There are several kinds of axes
// There are several kinds of axes // Half+: 0 (release) -> 32768
// Half+: 0 (release) -> 32768 // Half-: 0 (release) -> -32768
// Half-: 0 (release) -> -32768 // Full (like dualshock 3): -32768 (release) ->32768
// Full (like dualshock 3): -32768 (release) ->32768 const s32 full_axis_ceil = -0x6FFF;
const s32 full_axis_ceil = -0x6FFF; const s32 half_axis_ceil = 0x1FFF;
const s32 half_axis_ceil = 0x1FFF;
// Normally, old_value contains the release state so it can be used to detect the types of axis. // Normally, old_value contains the release state so it can be used to detect the types of axis.
bool is_full_axis = (old_value < full_axis_ceil) ? true : false; bool is_full_axis = (old_value < full_axis_ceil) ? true : false;
if ((!is_full_axis && abs(value) <= half_axis_ceil) if ((!is_full_axis && abs(value) <= half_axis_ceil) || (is_full_axis && value <= full_axis_ceil)) // we don't want this
|| (is_full_axis && value <= full_axis_ceil)) // we don't want this {
{ continue;
continue; }
}
if ((!is_full_axis && abs(value) > half_axis_ceil) if ((!is_full_axis && abs(value) > half_axis_ceil) || (is_full_axis && value > full_axis_ceil)) {
|| (is_full_axis && value > full_axis_ceil)) bool sign = (value < 0);
{ pkey = axis_to_key(is_full_axis, sign, i);
bool sign = (value < 0);
pkey = axis_to_key(is_full_axis, sign, i);
return true; return true;
} }
} }
} }
return false; return false;
} }
bool JoystickInfo::PollHats(u32 &pkey) bool JoystickInfo::PollHats(u32 &pkey)
{ {
for (int i = 0; i < GetNumHats(); ++i) for (int i = 0; i < GetNumHats(); ++i) {
{ int value = SDL_JoystickGetHat(GetJoy(), i);
int value = SDL_JoystickGetHat(GetJoy(), i);
if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED)) if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED)) {
{ switch (value) {
switch (value) case SDL_HAT_UP:
{ case SDL_HAT_RIGHT:
case SDL_HAT_UP: case SDL_HAT_DOWN:
case SDL_HAT_RIGHT: case SDL_HAT_LEFT:
case SDL_HAT_DOWN: pkey = hat_to_key(value, i);
case SDL_HAT_LEFT: PAD_LOG("Hat Pressed!");
pkey = hat_to_key(value, i); return true;
PAD_LOG("Hat Pressed!"); default:
return true; break;
default: }
break; }
} }
} return false;
}
return false;
} }
int JoystickInfo::GetHat(int key_to_axis) int JoystickInfo::GetHat(int key_to_axis)
{ {
return SDL_JoystickGetHat(GetJoy(),key_to_axis); return SDL_JoystickGetHat(GetJoy(), key_to_axis);
} }
int JoystickInfo::GetButton(int key_to_button) int JoystickInfo::GetButton(int key_to_button)
{ {
return SDL_JoystickGetButton(GetJoy(),key_to_button); return SDL_JoystickGetButton(GetJoy(), key_to_button);
} }
int JoystickInfo::GetAxisFromKey(int pad, int index) int JoystickInfo::GetAxisFromKey(int pad, int index)
{ {
return SDL_JoystickGetAxis(GetJoy(), key_to_axis(pad, index)); return SDL_JoystickGetAxis(GetJoy(), key_to_axis(pad, index));
} }

View File

@ -29,63 +29,66 @@
#include "GamePad.h" #include "GamePad.h"
#include "onepad.h" #include "onepad.h"
#include "controller.h" #include "controller.h"
#define NB_EFFECT 2 // Don't use more than two, ps2 only has one for big motor and one for small(like most systems) #define NB_EFFECT 2 // Don't use more than two, ps2 only has one for big motor and one for small(like most systems)
// holds all joystick info // holds all joystick info
class JoystickInfo : GamePad class JoystickInfo : GamePad
{ {
public: public:
JoystickInfo() : GamePad(), joy(NULL) { JoystickInfo()
: GamePad()
, joy(NULL)
{
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
haptic = NULL; haptic = NULL;
first = true; first = true;
#endif #endif
} }
~JoystickInfo() ~JoystickInfo()
{ {
Destroy(); Destroy();
} }
JoystickInfo(const JoystickInfo&); // copy constructor JoystickInfo(const JoystickInfo &); // copy constructor
JoystickInfo& operator=(const JoystickInfo&); // assignment JoystickInfo &operator=(const JoystickInfo &); // assignment
void Destroy(); void Destroy();
// opens handles to all possible joysticks // opens handles to all possible joysticks
static void EnumerateJoysticks(vector<GamePad*>& vjoysticks); static void EnumerateJoysticks(vector<GamePad *> &vjoysticks);
void Rumble(int type,int pad); void Rumble(int type, int pad);
bool Init(int id); // opens a handle and gets information bool Init(int id); // opens a handle and gets information
bool TestForce(float); bool TestForce(float);
bool PollButtons(u32 &pkey); bool PollButtons(u32 &pkey);
bool PollAxes(u32 &pkey); bool PollAxes(u32 &pkey);
bool PollHats(u32 &pkey); bool PollHats(u32 &pkey);
int GetHat(int key_to_axis); int GetHat(int key_to_axis);
int GetButton(int key_to_button); int GetButton(int key_to_button);
void SaveState(); void SaveState();
int GetAxisFromKey(int pad, int index); int GetAxisFromKey(int pad, int index);
static void UpdateReleaseState(); static void UpdateReleaseState();
private: private:
SDL_Joystick* GetJoy() SDL_Joystick *GetJoy()
{ {
return joy; return joy;
} }
void GenerateDefaultEffect(); void GenerateDefaultEffect();
SDL_Joystick* joy; SDL_Joystick *joy;
#if SDL_MAJOR_VERSION >= 2 #if SDL_MAJOR_VERSION >= 2
SDL_Haptic* haptic; SDL_Haptic *haptic;
bool first; bool first;
SDL_HapticEffect effects[NB_EFFECT]; SDL_HapticEffect effects[NB_EFFECT];
int effects_id[NB_EFFECT]; int effects_id[NB_EFFECT];
#endif #endif
}; };

View File

@ -19,26 +19,26 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
template <class T> template <class T>
static void __forceinline set_bit(T &value, int bit) static void __forceinline set_bit(T &value, int bit)
{ {
value |= (1 << bit); value |= (1 << bit);
} }
template <class T> template <class T>
static void __forceinline clear_bit(T &value, int bit) static void __forceinline clear_bit(T &value, int bit)
{ {
value &= ~(1 << bit); value &= ~(1 << bit);
} }
template <class T> template <class T>
static void __forceinline toggle_bit(T &value, int bit) static void __forceinline toggle_bit(T &value, int bit)
{ {
value ^= (1 << bit); value ^= (1 << bit);
} }
template <class T> template <class T>
static bool __forceinline test_bit(T &value, int bit) static bool __forceinline test_bit(T &value, int bit)
{ {
return (value & (1 << bit)); return (value & (1 << bit));
} }

View File

@ -24,43 +24,47 @@
__forceinline void set_keyboad_key(int pad, int keysym, int index) __forceinline void set_keyboad_key(int pad, int keysym, int index)
{ {
conf->keysym_map[pad][keysym] = index; conf->keysym_map[pad][keysym] = index;
} }
__forceinline int get_keyboard_key(int pad, int keysym) __forceinline int get_keyboard_key(int pad, int keysym)
{ {
// You must use find instead of [] // You must use find instead of []
// [] will create an element if the key does not exist and return 0 // [] will create an element if the key does not exist and return 0
map<u32,u32>::iterator it = conf->keysym_map[pad].find(keysym); map<u32, u32>::iterator it = conf->keysym_map[pad].find(keysym);
if (it != conf->keysym_map[pad].end()) if (it != conf->keysym_map[pad].end())
return it->second; return it->second;
else else
return -1; return -1;
} }
__forceinline void set_key(int pad, int index, int value) __forceinline void set_key(int pad, int index, int value)
{ {
conf->keys[pad][index] = value; conf->keys[pad][index] = value;
} }
__forceinline int get_key(int pad, int index) __forceinline int get_key(int pad, int index)
{ {
return conf->keys[pad][index]; return conf->keys[pad][index];
} }
__forceinline KeyType type_of_joykey(int pad, int index) __forceinline KeyType type_of_joykey(int pad, int index)
{ {
int key = get_key(pad, index); int key = get_key(pad, index);
if (key >= 0x10000 && key < 0x20000) return PAD_JOYBUTTONS; if (key >= 0x10000 && key < 0x20000)
else if (key >= 0x20000 && key < 0x30000) return PAD_AXIS; return PAD_JOYBUTTONS;
else if (key >= 0x30000 && key < 0x40000) return PAD_HAT; else if (key >= 0x20000 && key < 0x30000)
else return PAD_NULL; return PAD_AXIS;
else if (key >= 0x30000 && key < 0x40000)
return PAD_HAT;
else
return PAD_NULL;
} }
__forceinline bool IsAnalogKey(int index) __forceinline bool IsAnalogKey(int index)
{ {
return ((index >= PAD_L_UP) && (index <= PAD_R_LEFT)); return ((index >= PAD_L_UP) && (index <= PAD_R_LEFT));
} }
//******************************************************* //*******************************************************
@ -68,27 +72,27 @@ __forceinline bool IsAnalogKey(int index)
//******************************************************* //*******************************************************
__forceinline int key_to_button(int pad, int index) __forceinline int key_to_button(int pad, int index)
{ {
return (get_key(pad, index) & 0xff); return (get_key(pad, index) & 0xff);
} }
__forceinline int key_to_axis(int pad, int index) __forceinline int key_to_axis(int pad, int index)
{ {
return (get_key(pad, index) & 0xff); return (get_key(pad, index) & 0xff);
} }
__forceinline bool key_to_axis_sign(int pad, int index) __forceinline bool key_to_axis_sign(int pad, int index)
{ {
return ((get_key(pad, index) >> 8) & 0x1); return ((get_key(pad, index) >> 8) & 0x1);
} }
__forceinline bool key_to_axis_type(int pad, int index) __forceinline bool key_to_axis_type(int pad, int index)
{ {
return ((get_key(pad, index) >> 9) & 0x1); return ((get_key(pad, index) >> 9) & 0x1);
} }
__forceinline int key_to_hat_dir(int pad, int index) __forceinline int key_to_hat_dir(int pad, int index)
{ {
return ((get_key(pad, index) >> 8) & 0xF); return ((get_key(pad, index) >> 8) & 0xF);
} }
//******************************************************* //*******************************************************
@ -96,15 +100,15 @@ __forceinline int key_to_hat_dir(int pad, int index)
//******************************************************* //*******************************************************
__forceinline int button_to_key(int button_id) __forceinline int button_to_key(int button_id)
{ {
return (0x10000 | button_id); return (0x10000 | button_id);
} }
__forceinline int axis_to_key(int full_axis, int sign, int axis_id) __forceinline int axis_to_key(int full_axis, int sign, int axis_id)
{ {
return (0x20000 | (full_axis << 9) | (sign << 8) | axis_id); return (0x20000 | (full_axis << 9) | (sign << 8) | axis_id);
} }
__forceinline int hat_to_key(int dir, int axis_id) __forceinline int hat_to_key(int dir, int axis_id)
{ {
return (0x30000 | (dir << 8) | axis_id); return (0x30000 | (dir << 8) | axis_id);
} }

View File

@ -20,15 +20,14 @@
*/ */
#pragma once #pragma once
#include <string.h> // for memset #include <string.h> // for memset
#define MAX_KEYS 24 #define MAX_KEYS 24
enum KeyType enum KeyType {
{ PAD_JOYBUTTONS = 0,
PAD_JOYBUTTONS = 0, PAD_AXIS,
PAD_AXIS, PAD_HAT,
PAD_HAT, PAD_NULL = -1
PAD_NULL = -1
}; };
extern void set_keyboad_key(int pad, int keysym, int index); extern void set_keyboad_key(int pad, int keysym, int index);
@ -52,91 +51,94 @@ extern int hat_to_key(int dir, int axis_id);
class PADconf class PADconf
{ {
u32 ff_intensity; u32 ff_intensity;
u32 sensibility; 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;
u16 sixaxis_usb :1;
u16 sixaxis_pressure :1;
u16 _free : 7; // The 8 remaining bits are unused, do what you wish with them ;)
} 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
};
u32 keys[GAMEPAD_NUMBER][MAX_KEYS]; public:
u32 log; union
u32 joyid_map; {
map<u32,u32> keysym_map[GAMEPAD_NUMBER]; 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;
u16 sixaxis_usb : 1;
u16 sixaxis_pressure : 1;
u16 _free : 7; // The 8 remaining bits are unused, do what you wish with them ;)
} 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
};
PADconf() { init(); } u32 keys[GAMEPAD_NUMBER][MAX_KEYS];
u32 log;
u32 joyid_map;
map<u32, u32> keysym_map[GAMEPAD_NUMBER];
void init() { PADconf() { init(); }
memset(&keys, 0, sizeof(keys));
log = packed_options = joyid_map = 0;
ff_intensity = 0x7FFF; // set it at max value by default
sensibility = 500;
for (int pad = 0; pad < GAMEPAD_NUMBER ; pad++)
{
keysym_map[pad].clear();
set_joyid((u32)pad, (u32)pad); // define id mapping for each gamepad
}
}
void set_joyid(u32 pad, u32 joy_id) { void init()
int shift = 8 * pad; {
joyid_map &= ~(0xFF << shift); // clear memset(&keys, 0, sizeof(keys));
joyid_map |= (joy_id & 0xFF) << shift; // set log = packed_options = joyid_map = 0;
} ff_intensity = 0x7FFF; // set it at max value by default
sensibility = 500;
for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) {
keysym_map[pad].clear();
set_joyid((u32)pad, (u32)pad); // define id mapping for each gamepad
}
}
u32 get_joyid(u32 pad) { void set_joyid(u32 pad, u32 joy_id)
int shift = 8 * pad; {
return ((joyid_map >> shift) & 0xFF); int shift = 8 * pad;
} joyid_map &= ~(0xFF << shift); // clear
joyid_map |= (joy_id & 0xFF) << shift; // set
}
/** u32 get_joyid(u32 pad)
{
int shift = 8 * pad;
return ((joyid_map >> shift) & 0xFF);
}
/**
* Return (a copy of) private memner ff_instensity * Return (a copy of) private memner ff_instensity
**/ **/
u32 get_ff_intensity() u32 get_ff_intensity()
{ {
return ff_intensity; return ff_intensity;
} }
/** /**
* Set intensity while checking that the new value is within * 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) * valid range, more than 0x7FFF will cause pad not to rumble(and less than 0 is obviously bad)
**/ **/
void set_ff_intensity(u32 new_intensity) void set_ff_intensity(u32 new_intensity)
{ {
if(new_intensity <= 0x7FFF) if (new_intensity <= 0x7FFF) {
{ ff_intensity = new_intensity;
ff_intensity = new_intensity; }
} }
}
/** /**
* Set sensibility value, sensibility is not yet implemented(and will probably be after evdev) * 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 * 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 * Anyway, we are doing object oriented code, members are definitely not supposed to be public
**/ **/
void set_sensibility(u32 new_sensibility) void set_sensibility(u32 new_sensibility)
{ {
if(sensibility > 0) if (sensibility > 0) {
{ sensibility = new_sensibility;
sensibility = new_sensibility; }
} }
}
u32 get_sensibility() u32 get_sensibility()
{ {
return sensibility; return sensibility;
} }
}; };
extern PADconf *conf; extern PADconf *conf;

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
/* /*
* Theoretically, this header is for anything to do with keyboard input. * Theoretically, this header is for anything to do with keyboard input.
* Pragmatically, event handing's going in here too. * Pragmatically, event handing's going in here too.
*/ */
@ -29,20 +29,19 @@
#include "keyboard.h" #include "keyboard.h"
#ifdef _WIN32 #ifdef _WIN32
char* KeysymToChar(int keysym) char *KeysymToChar(int keysym)
{ {
LPWORD temp; LPWORD temp;
ToAscii((UINT) keysym, NULL, NULL, temp, NULL); ToAscii((UINT)keysym, NULL, NULL, temp, NULL);
return (char*)temp; return (char *)temp;
} }
#endif #endif
void SetAutoRepeat(bool autorep) void SetAutoRepeat(bool autorep)
{ {
#if defined(__unix__) #if defined(__unix__)
if (toggleAutoRepeat) if (toggleAutoRepeat) {
{
if (autorep) if (autorep)
XAutoRepeatOn(GSdsp); XAutoRepeatOn(GSdsp);
else else
@ -54,268 +53,259 @@ void SetAutoRepeat(bool autorep)
#if defined(__unix__) #if defined(__unix__)
static bool s_grab_input = false; static bool s_grab_input = false;
static bool s_Shift = false; static bool s_Shift = false;
static unsigned int s_previous_mouse_x = 0; static unsigned int s_previous_mouse_x = 0;
static unsigned int s_previous_mouse_y = 0; static unsigned int s_previous_mouse_y = 0;
void AnalyzeKeyEvent(keyEvent &evt) void AnalyzeKeyEvent(keyEvent &evt)
{ {
KeySym key = (KeySym)evt.key; KeySym key = (KeySym)evt.key;
int pad = 0; int pad = 0;
int index = -1; int index = -1;
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) { for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
int tmp_index = get_keyboard_key(cpad, key); int tmp_index = get_keyboard_key(cpad, key);
if (tmp_index != -1) { if (tmp_index != -1) {
pad = cpad; pad = cpad;
index = tmp_index; index = tmp_index;
} }
} }
switch (evt.evt) switch (evt.evt) {
{ case KeyPress:
case KeyPress: // Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input
// Shift F12 is not yet use by pcsx2. So keep it to grab/ungrab input // I found it very handy vs the automatic fullscreen detection
// I found it very handy vs the automatic fullscreen detection // 1/ Does not need to detect full-screen
// 1/ Does not need to detect full-screen // 2/ Can use a debugger in full-screen
// 2/ Can use a debugger in full-screen // 3/ Can grab input in window without the need of a pixelated full-screen
// 3/ Can grab input in window without the need of a pixelated full-screen if (key == XK_Shift_R || key == XK_Shift_L)
if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = true; s_Shift = true;
if (key == XK_F12 && s_Shift) { if (key == XK_F12 && s_Shift) {
if(!s_grab_input) { if (!s_grab_input) {
s_grab_input = true; s_grab_input = true;
XGrabPointer(GSdsp, GSwin, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, GSwin, None, CurrentTime); XGrabPointer(GSdsp, GSwin, True, ButtonPressMask, GrabModeAsync, GrabModeAsync, GSwin, None, CurrentTime);
XGrabKeyboard(GSdsp, GSwin, True, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabKeyboard(GSdsp, GSwin, True, GrabModeAsync, GrabModeAsync, CurrentTime);
} else { } else {
s_grab_input = false; s_grab_input = false;
XUngrabPointer(GSdsp, CurrentTime); XUngrabPointer(GSdsp, CurrentTime);
XUngrabKeyboard(GSdsp, CurrentTime); XUngrabKeyboard(GSdsp, CurrentTime);
} }
} }
// Analog controls. // Analog controls.
if (IsAnalogKey(index)) if (IsAnalogKey(index)) {
{ switch (index) {
switch (index) case PAD_R_LEFT:
{ case PAD_R_UP:
case PAD_R_LEFT: case PAD_L_LEFT:
case PAD_R_UP: case PAD_L_UP:
case PAD_L_LEFT: key_status->press(pad, index, -MAX_ANALOG_VALUE);
case PAD_L_UP: break;
key_status->press(pad, index, -MAX_ANALOG_VALUE); case PAD_R_RIGHT:
break; case PAD_R_DOWN:
case PAD_R_RIGHT: case PAD_L_RIGHT:
case PAD_R_DOWN: case PAD_L_DOWN:
case PAD_L_RIGHT: key_status->press(pad, index, MAX_ANALOG_VALUE);
case PAD_L_DOWN: break;
key_status->press(pad, index, MAX_ANALOG_VALUE); }
break; } else if (index != -1)
} key_status->press(pad, index);
} else if (index != -1)
key_status->press(pad, index);
//PAD_LOG("Key pressed:%d\n", index); //PAD_LOG("Key pressed:%d\n", index);
event.evt = KEYPRESS; event.evt = KEYPRESS;
event.key = key; event.key = key;
break; break;
case KeyRelease: case KeyRelease:
if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false; if (key == XK_Shift_R || key == XK_Shift_L)
s_Shift = false;
if (index != -1) if (index != -1)
key_status->release(pad, index); key_status->release(pad, index);
event.evt = KEYRELEASE; event.evt = KEYRELEASE;
event.key = key; event.key = key;
break; break;
case FocusIn: case FocusIn:
//XAutoRepeatOff(GSdsp); //XAutoRepeatOff(GSdsp);
break; break;
case FocusOut: case FocusOut:
//XAutoRepeatOn(GSdsp); //XAutoRepeatOn(GSdsp);
s_Shift = false; s_Shift = false;
break; break;
case ButtonPress: case ButtonPress:
if (index != -1) if (index != -1)
key_status->press(pad, index); key_status->press(pad, index);
break; break;
case ButtonRelease: case ButtonRelease:
if (index != -1) if (index != -1)
key_status->release(pad, index); key_status->release(pad, index);
break; break;
case MotionNotify: case MotionNotify:
// FIXME: How to handle when the mouse does not move, no event generated!!! // FIXME: How to handle when the mouse does not move, no event generated!!!
// 1/ small move == no move. Cons : can not do small movement // 1/ small move == no move. Cons : can not do small movement
// 2/ use a watchdog timer thread // 2/ use a watchdog timer thread
// 3/ ??? idea welcome ;) // 3/ ??? idea welcome ;)
if (conf->pad_options[pad].mouse_l|conf->pad_options[pad].mouse_r) { if (conf->pad_options[pad].mouse_l | conf->pad_options[pad].mouse_r) {
unsigned int pad_x; unsigned int pad_x;
unsigned int pad_y; unsigned int pad_y;
// Note when both PADOPTION_MOUSE_R and PADOPTION_MOUSE_L are set, take only the right one // Note when both PADOPTION_MOUSE_R and PADOPTION_MOUSE_L are set, take only the right one
if (conf->pad_options[pad].mouse_r) { if (conf->pad_options[pad].mouse_r) {
pad_x = PAD_R_RIGHT; pad_x = PAD_R_RIGHT;
pad_y = PAD_R_UP; pad_y = PAD_R_UP;
} else { } else {
pad_x = PAD_L_RIGHT; pad_x = PAD_L_RIGHT;
pad_y = PAD_L_UP; pad_y = PAD_L_UP;
} }
unsigned x = evt.key & 0xFFFF; unsigned x = evt.key & 0xFFFF;
unsigned int value = (s_previous_mouse_x > x) ? s_previous_mouse_x - x : x - s_previous_mouse_x; unsigned int value = (s_previous_mouse_x > x) ? s_previous_mouse_x - x : x - s_previous_mouse_x;
value *= conf->get_sensibility(); value *= conf->get_sensibility();
if (x == 0) if (x == 0)
key_status->press(pad, pad_x, -MAX_ANALOG_VALUE); key_status->press(pad, pad_x, -MAX_ANALOG_VALUE);
else if (x == 0xFFFF) else if (x == 0xFFFF)
key_status->press(pad, pad_x, MAX_ANALOG_VALUE); key_status->press(pad, pad_x, MAX_ANALOG_VALUE);
else if (x < (s_previous_mouse_x -2)) else if (x < (s_previous_mouse_x - 2))
key_status->press(pad, pad_x, -value); key_status->press(pad, pad_x, -value);
else if (x > (s_previous_mouse_x +2)) else if (x > (s_previous_mouse_x + 2))
key_status->press(pad, pad_x, value); key_status->press(pad, pad_x, value);
else else
key_status->release(pad, pad_x); key_status->release(pad, pad_x);
unsigned y = evt.key >> 16; unsigned y = evt.key >> 16;
value = (s_previous_mouse_y > y) ? s_previous_mouse_y - y : y - s_previous_mouse_y; value = (s_previous_mouse_y > y) ? s_previous_mouse_y - y : y - s_previous_mouse_y;
value *= conf->get_sensibility(); value *= conf->get_sensibility();
if (y == 0) if (y == 0)
key_status->press(pad, pad_y, -MAX_ANALOG_VALUE); key_status->press(pad, pad_y, -MAX_ANALOG_VALUE);
else if (y == 0xFFFF) else if (y == 0xFFFF)
key_status->press(pad, pad_y, MAX_ANALOG_VALUE); key_status->press(pad, pad_y, MAX_ANALOG_VALUE);
else if (y < (s_previous_mouse_y -2)) else if (y < (s_previous_mouse_y - 2))
key_status->press(pad, pad_y, -value); key_status->press(pad, pad_y, -value);
else if (y > (s_previous_mouse_y +2)) else if (y > (s_previous_mouse_y + 2))
key_status->press(pad, pad_y, value); key_status->press(pad, pad_y, value);
else else
key_status->release(pad, pad_y); key_status->release(pad, pad_y);
s_previous_mouse_x = x; s_previous_mouse_x = x;
s_previous_mouse_y = y; s_previous_mouse_y = y;
} }
break; break;
} }
} }
void PollForX11KeyboardInput() void PollForX11KeyboardInput()
{ {
keyEvent evt = {0}; keyEvent evt = {0};
XEvent E = {0}; XEvent E = {0};
// Keyboard input send by PCSX2 // Keyboard input send by PCSX2
while (!ev_fifo.empty()) { while (!ev_fifo.empty()) {
AnalyzeKeyEvent(ev_fifo.front()); AnalyzeKeyEvent(ev_fifo.front());
pthread_spin_lock(&mutex_KeyEvent); pthread_spin_lock(&mutex_KeyEvent);
ev_fifo.pop(); ev_fifo.pop();
pthread_spin_unlock(&mutex_KeyEvent); pthread_spin_unlock(&mutex_KeyEvent);
} }
// keyboard input // keyboard input
while (XPending(GSdsp) > 0) while (XPending(GSdsp) > 0) {
{ XNextEvent(GSdsp, &E);
XNextEvent(GSdsp, &E);
// Change the format of the structure to be compatible with GSOpen2 // Change the format of the structure to be compatible with GSOpen2
// mode (event come from pcsx2 not X) // mode (event come from pcsx2 not X)
evt.evt = E.type; evt.evt = E.type;
switch (E.type) { switch (E.type) {
case MotionNotify: case MotionNotify:
evt.key = (E.xbutton.x & 0xFFFF) | (E.xbutton.y << 16); evt.key = (E.xbutton.x & 0xFFFF) | (E.xbutton.y << 16);
break; break;
case ButtonRelease: case ButtonRelease:
case ButtonPress: case ButtonPress:
evt.key = E.xbutton.button; evt.key = E.xbutton.button;
break; break;
default: default:
evt.key = (int)XLookupKeysym(&E.xkey, 0); evt.key = (int)XLookupKeysym(&E.xkey, 0);
} }
AnalyzeKeyEvent(evt); AnalyzeKeyEvent(evt);
} }
} }
bool PollX11KeyboardMouseEvent(u32 &pkey) bool PollX11KeyboardMouseEvent(u32 &pkey)
{ {
GdkEvent *ev = gdk_event_get(); GdkEvent *ev = gdk_event_get();
if (ev != NULL) if (ev != NULL) {
{ if (ev->type == GDK_KEY_PRESS) {
if (ev->type == GDK_KEY_PRESS) { pkey = ev->key.keyval != GDK_KEY_Escape ? ev->key.keyval : 0;
pkey = ev->key.keyval != GDK_KEY_Escape ? ev->key.keyval : 0; return true;
return true; } else if (ev->type == GDK_BUTTON_PRESS) {
} else if(ev->type == GDK_BUTTON_PRESS) { pkey = ev->button.button;
pkey = ev->button.button; return true;
return true; }
} }
}
return false; return false;
} }
#else #else
LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
static bool lbutton = false, rbutton = false; static bool lbutton = false, rbutton = false;
key_status->keyboard_state_acces(cpad); key_status->keyboard_state_acces(cpad);
switch (msg) switch (msg) {
{ case WM_KEYDOWN:
case WM_KEYDOWN: if (lParam & 0x40000000)
if (lParam & 0x40000000) return TRUE; return TRUE;
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
{ for (int i = 0; i < MAX_KEYS; i++) {
for (int i = 0; i < MAX_KEYS; i++) if (wParam == get_key(pad, i)) {
{ key_status->press(pad, i);
if (wParam == get_key(pad, i)) break;
{ }
key_status->press(pad, i); }
break; }
}
}
}
event.evt = KEYPRESS; event.evt = KEYPRESS;
event.key = wParam; event.key = wParam;
break; break;
case WM_KEYUP: case WM_KEYUP:
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) {
{ for (int i = 0; i < MAX_KEYS; i++) {
for (int i = 0; i < MAX_KEYS; i++) if (wParam == get_key(pad, i)) {
{ key_status->release(pad, i);
if (wParam == get_key(pad,i)) break;
{ }
key_status->release(pad, i); }
break; }
}
}
}
event.evt = KEYRELEASE; event.evt = KEYRELEASE;
event.key = wParam; event.key = wParam;
break; break;
case WM_DESTROY: case WM_DESTROY:
case WM_QUIT: case WM_QUIT:
event.evt = KEYPRESS; event.evt = KEYPRESS;
event.key = VK_ESCAPE; event.key = VK_ESCAPE;
return GSwndProc(hWnd, msg, wParam, lParam); return GSwndProc(hWnd, msg, wParam, lParam);
default: default:
return GSwndProc(hWnd, msg, wParam, lParam); return GSwndProc(hWnd, msg, wParam, lParam);
} }
for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad) for (int pad = 0; pad < GAMEPAD_NUMBER; ++pad)
key_status->commit_status(pad); key_status->commit_status(pad);
return TRUE; return TRUE;
} }
#endif #endif

View File

@ -19,8 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/ */
#ifndef __KEYBOARD_H__ #ifndef __KEYBOARD_H__
#define __KEYBOARD_H__ #define __KEYBOARD_H__
#include "onepad.h" #include "onepad.h"
@ -35,7 +35,7 @@ extern Window GSwin;
#else #else
extern char* KeysymToChar(int keysym); extern char *KeysymToChar(int keysym);
extern WNDPROC GSwndProc; extern WNDPROC GSwndProc;
extern HWND GShwnd; extern HWND GShwnd;

View File

@ -36,7 +36,7 @@
#define snprintf sprintf_s #define snprintf sprintf_s
#endif #endif
PADconf* conf; PADconf *conf;
static char libraryName[256]; static char libraryName[256];
keyEvent event; keyEvent event;
@ -46,16 +46,16 @@ std::string s_strIniPath("inis/");
std::string s_strLogPath("logs/"); std::string s_strLogPath("logs/");
bool toggleAutoRepeat = false; bool toggleAutoRepeat = false;
const u32 version = PS2E_PAD_VERSION; const u32 version = PS2E_PAD_VERSION;
const u32 revision = 1; const u32 revision = 1;
const u32 build = 3; // increase that with each version const u32 build = 3; // increase that with each version
#define PAD_SAVE_STATE_VERSION ((revision << 8) | (build << 0)) #define PAD_SAVE_STATE_VERSION ((revision << 8) | (build << 0))
FILE *padLog = NULL; FILE *padLog = NULL;
pthread_spinlock_t mutex_KeyEvent; pthread_spinlock_t mutex_KeyEvent;
bool mutex_WasInit = false; bool mutex_WasInit = false;
KeyStatus* key_status = NULL; KeyStatus *key_status = NULL;
queue<keyEvent> ev_fifo; queue<keyEvent> ev_fifo;
@ -63,281 +63,302 @@ static void InitLibraryName()
{ {
#ifdef PUBLIC #ifdef PUBLIC
// Public Release! // Public Release!
// Output a simplified string that's just our name: // Output a simplified string that's just our name:
strcpy(libraryName, "OnePAD"); strcpy(libraryName, "OnePAD");
#else #else
// Use TortoiseSVN's SubWCRev utility's output // Use TortoiseSVN's SubWCRev utility's output
// to label the specific revision: // to label the specific revision:
snprintf(libraryName, 255, "OnePAD %lld%s" snprintf(libraryName, 255, "OnePAD %lld%s"
# ifdef PCSX2_DEBUG #ifdef PCSX2_DEBUG
"-Debug" "-Debug"
# elif defined(PCSX2_DEVBUILD) #elif defined(PCSX2_DEVBUILD)
"-Dev" "-Dev"
# endif #endif
, SVN_REV, ,
SVN_MODS ? "m" : "" SVN_REV,
); SVN_MODS ? "m" : "");
#endif #endif
} }
EXPORT_C_(u32) PS2EgetLibType() EXPORT_C_(u32)
PS2EgetLibType()
{ {
return PS2E_LT_PAD; return PS2E_LT_PAD;
} }
EXPORT_C_(char*) PS2EgetLibName() EXPORT_C_(char *)
PS2EgetLibName()
{ {
InitLibraryName(); InitLibraryName();
return libraryName; return libraryName;
} }
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type) EXPORT_C_(u32)
PS2EgetLibVersion2(u32 type)
{ {
return (version << 16) | (revision << 8) | build; return (version << 16) | (revision << 8) | build;
} }
void __Log(const char *fmt, ...) void __Log(const char *fmt, ...)
{ {
va_list list; va_list list;
if (padLog == NULL) return; if (padLog == NULL)
va_start(list, fmt); return;
vfprintf(padLog, fmt, list); va_start(list, fmt);
va_end(list); vfprintf(padLog, fmt, list);
va_end(list);
} }
void __LogToConsole(const char *fmt, ...) void __LogToConsole(const char *fmt, ...)
{ {
va_list list; va_list list;
va_start(list, fmt); va_start(list, fmt);
if (padLog != NULL) vfprintf(padLog, fmt, list); if (padLog != NULL)
vfprintf(padLog, fmt, list);
printf("OnePAD: "); printf("OnePAD: ");
vprintf(fmt, list); vprintf(fmt, list);
va_end(list); va_end(list);
} }
void initLogging() void initLogging()
{ {
#ifdef PAD_LOG #ifdef PAD_LOG
if (padLog) return; if (padLog)
return;
const std::string LogFile(s_strLogPath + "padLog.txt"); const std::string LogFile(s_strLogPath + "padLog.txt");
padLog = fopen(LogFile.c_str(), "w"); padLog = fopen(LogFile.c_str(), "w");
if (padLog) if (padLog)
setvbuf(padLog, NULL, _IONBF, 0); setvbuf(padLog, NULL, _IONBF, 0);
PAD_LOG("PADinit\n"); PAD_LOG("PADinit\n");
#endif #endif
} }
void CloseLogging() void CloseLogging()
{ {
#ifdef PAD_LOG #ifdef PAD_LOG
if (padLog) if (padLog) {
{ fclose(padLog);
fclose(padLog); padLog = NULL;
padLog = NULL; }
}
#endif #endif
} }
void clearPAD(int pad) void clearPAD(int pad)
{ {
conf->keysym_map[pad].clear(); conf->keysym_map[pad].clear();
for (int key= 0; key < MAX_KEYS; ++key) for (int key = 0; key < MAX_KEYS; ++key)
set_key(pad, key, 0); set_key(pad, key, 0);
} }
EXPORT_C_(s32) PADinit(u32 flags) EXPORT_C_(s32)
PADinit(u32 flags)
{ {
initLogging(); initLogging();
LoadConfig(); LoadConfig();
key_status = new KeyStatus(); key_status = new KeyStatus();
Pad::reset_all(); Pad::reset_all();
query.reset(); query.reset();
for (int port = 0; port < 2; port++) for (int port = 0; port < 2; port++)
slots[port] = 0; slots[port] = 0;
return 0; return 0;
} }
EXPORT_C_(void) PADshutdown() EXPORT_C_(void)
PADshutdown()
{ {
CloseLogging(); CloseLogging();
delete conf; delete conf;
conf = nullptr; conf = nullptr;
delete key_status; delete key_status;
key_status = nullptr; key_status = nullptr;
} }
EXPORT_C_(s32) PADopen(void *pDsp) EXPORT_C_(s32)
PADopen(void *pDsp)
{ {
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
key_status->Init(); key_status->Init();
while (!ev_fifo.empty()) ev_fifo.pop(); while (!ev_fifo.empty())
pthread_spin_init(&mutex_KeyEvent, PTHREAD_PROCESS_PRIVATE); ev_fifo.pop();
mutex_WasInit = true; pthread_spin_init(&mutex_KeyEvent, PTHREAD_PROCESS_PRIVATE);
mutex_WasInit = true;
#if defined(__unix__) #if defined(__unix__)
GamePad::EnumerateGamePads(s_vgamePad); GamePad::EnumerateGamePads(s_vgamePad);
#endif #endif
return _PADopen(pDsp); return _PADopen(pDsp);
} }
EXPORT_C_(void) PADsetSettingsDir(const char* dir) EXPORT_C_(void)
PADsetSettingsDir(const char *dir)
{ {
// Get the path to the ini directory. // Get the path to the ini directory.
s_strIniPath = (dir==NULL) ? "inis/" : dir; s_strIniPath = (dir == NULL) ? "inis/" : dir;
} }
EXPORT_C_(void) PADsetLogDir(const char* dir) EXPORT_C_(void)
PADsetLogDir(const char *dir)
{ {
// Get the path to the log directory. // Get the path to the log directory.
s_strLogPath = (dir==NULL) ? "logs/" : dir; s_strLogPath = (dir == NULL) ? "logs/" : dir;
// Reload the log file after updated the path // Reload the log file after updated the path
CloseLogging(); CloseLogging();
initLogging(); initLogging();
} }
EXPORT_C_(void) PADclose() EXPORT_C_(void)
PADclose()
{ {
while (!ev_fifo.empty()) ev_fifo.pop(); while (!ev_fifo.empty())
mutex_WasInit = false; ev_fifo.pop();
pthread_spin_destroy(&mutex_KeyEvent); mutex_WasInit = false;
_PADclose(); pthread_spin_destroy(&mutex_KeyEvent);
_PADclose();
} }
EXPORT_C_(u32) PADquery() EXPORT_C_(u32)
PADquery()
{ {
return 3; // both return 3; // both
} }
EXPORT_C_(s32) PADsetSlot(u8 port, u8 slot) EXPORT_C_(s32)
PADsetSlot(u8 port, u8 slot)
{ {
port--; port--;
slot--; slot--;
if (port > 1 || slot > 3) { if (port > 1 || slot > 3) {
return 0; return 0;
} }
// Even if no pad there, record the slot, as it is the active slot regardless. // Even if no pad there, record the slot, as it is the active slot regardless.
slots[port] = slot; slots[port] = slot;
return 1; return 1;
} }
EXPORT_C_(s32) PADfreeze(int mode, freezeData *data) EXPORT_C_(s32)
PADfreeze(int mode, freezeData *data)
{ {
if (!data) if (!data)
return -1; return -1;
if (mode == FREEZE_SIZE) { if (mode == FREEZE_SIZE) {
data->size = sizeof(PadPluginFreezeData); data->size = sizeof(PadPluginFreezeData);
} else if (mode == FREEZE_LOAD) { } else if (mode == FREEZE_LOAD) {
PadPluginFreezeData* pdata = (PadPluginFreezeData*)(data->data); PadPluginFreezeData *pdata = (PadPluginFreezeData *)(data->data);
Pad::stop_vibrate_all(); Pad::stop_vibrate_all();
if (data->size != sizeof(PadPluginFreezeData) || pdata->version != PAD_SAVE_STATE_VERSION || if (data->size != sizeof(PadPluginFreezeData) || pdata->version != PAD_SAVE_STATE_VERSION ||
strncmp(pdata->format, "OnePad", sizeof(pdata->format))) strncmp(pdata->format, "OnePad", sizeof(pdata->format)))
return 0; return 0;
query = pdata->query; query = pdata->query;
if (pdata->query.slot < 4) { if (pdata->query.slot < 4) {
query = pdata->query; query = pdata->query;
} }
// Tales of the Abyss - pad fix // Tales of the Abyss - pad fix
// - restore data for both ports // - restore data for both ports
for (int port=0; port<2; port++) { for (int port = 0; port < 2; port++) {
for (int slot=0; slot<4; slot++) { for (int slot = 0; slot < 4; slot++) {
u8 mode = pdata->padData[port][slot].mode; u8 mode = pdata->padData[port][slot].mode;
if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) { if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) {
break; break;
} }
memcpy(&pads[port][slot], &pdata->padData[port][slot], sizeof(PadFreezeData)); memcpy(&pads[port][slot], &pdata->padData[port][slot], sizeof(PadFreezeData));
} }
if (pdata->slot[port] < 4) if (pdata->slot[port] < 4)
slots[port] = pdata->slot[port]; slots[port] = pdata->slot[port];
} }
} else if (mode == FREEZE_SAVE) { } else if (mode == FREEZE_SAVE) {
if (data->size != sizeof(PadPluginFreezeData)) return 0; if (data->size != sizeof(PadPluginFreezeData))
return 0;
PadPluginFreezeData* pdata = (PadPluginFreezeData*)(data->data); PadPluginFreezeData *pdata = (PadPluginFreezeData *)(data->data);
// Tales of the Abyss - pad fix // Tales of the Abyss - pad fix
// - PCSX2 only saves port0 (save #1), then port1 (save #2) // - PCSX2 only saves port0 (save #1), then port1 (save #2)
memset(pdata, 0, data->size); memset(pdata, 0, data->size);
strncpy(pdata->format, "OnePad", sizeof(pdata->format)); strncpy(pdata->format, "OnePad", sizeof(pdata->format));
pdata->version = PAD_SAVE_STATE_VERSION; pdata->version = PAD_SAVE_STATE_VERSION;
pdata->query = query; pdata->query = query;
for (int port=0; port<2; port++) { for (int port = 0; port < 2; port++) {
for (int slot=0; slot<4; slot++) { for (int slot = 0; slot < 4; slot++) {
pdata->padData[port][slot] = pads[port][slot]; pdata->padData[port][slot] = pads[port][slot];
} }
pdata->slot[port] = slots[port]; pdata->slot[port] = slots[port];
} }
} else { } else {
return -1; return -1;
} }
return 0; return 0;
} }
EXPORT_C_(u8) PADstartPoll(int pad) EXPORT_C_(u8)
PADstartPoll(int pad)
{ {
return pad_start_poll(pad); return pad_start_poll(pad);
} }
EXPORT_C_(u8) PADpoll(u8 value) EXPORT_C_(u8)
PADpoll(u8 value)
{ {
return pad_poll(value); return pad_poll(value);
} }
// PADkeyEvent is called every vsync (return NULL if no event) // PADkeyEvent is called every vsync (return NULL if no event)
EXPORT_C_(keyEvent*) PADkeyEvent() EXPORT_C_(keyEvent *)
PADkeyEvent()
{ {
s_event = event; s_event = event;
event.evt = 0; event.evt = 0;
event.key = 0; event.key = 0;
return &s_event; return &s_event;
} }
#if defined(__unix__) #if defined(__unix__)
EXPORT_C_(void) PADWriteEvent(keyEvent &evt) EXPORT_C_(void)
PADWriteEvent(keyEvent &evt)
{ {
// This function call be called before PADopen. Therefore we cann't // This function call be called before PADopen. Therefore we cann't
// guarantee that the spin lock was initialized // guarantee that the spin lock was initialized
if (mutex_WasInit) { if (mutex_WasInit) {
pthread_spin_lock(&mutex_KeyEvent); pthread_spin_lock(&mutex_KeyEvent);
ev_fifo.push(evt); ev_fifo.push(evt);
pthread_spin_unlock(&mutex_KeyEvent); pthread_spin_unlock(&mutex_KeyEvent);
} }
} }
#endif #endif

View File

@ -22,7 +22,7 @@
#ifndef __PAD_H__ #ifndef __PAD_H__
#define __PAD_H__ #define __PAD_H__
#define GAMEPAD_NUMBER 2 // numbers of gamepad #define GAMEPAD_NUMBER 2 // numbers of gamepad
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
@ -59,20 +59,19 @@ using namespace std;
#ifdef _MSC_VER #ifdef _MSC_VER
#define EXPORT_C_(type) extern "C" __declspec(dllexport) type CALLBACK #define EXPORT_C_(type) extern "C" __declspec(dllexport) type CALLBACK
#else #else
#define EXPORT_C_(type) extern "C" __attribute__((stdcall,externally_visible,visibility("default"))) type #define EXPORT_C_(type) extern "C" __attribute__((stdcall, externally_visible, visibility("default"))) type
#endif #endif
enum PadOptions enum PadOptions {
{ PADOPTION_FORCEFEEDBACK = 0x1,
PADOPTION_FORCEFEEDBACK = 0x1, PADOPTION_REVERSELX = 0x2,
PADOPTION_REVERSELX = 0x2, PADOPTION_REVERSELY = 0x4,
PADOPTION_REVERSELY = 0x4, PADOPTION_REVERSERX = 0x8,
PADOPTION_REVERSERX = 0x8, PADOPTION_REVERSERY = 0x10,
PADOPTION_REVERSERY = 0x10, PADOPTION_MOUSE_L = 0x20,
PADOPTION_MOUSE_L = 0x20, PADOPTION_MOUSE_R = 0x40,
PADOPTION_MOUSE_R = 0x40, PADOPTION_SIXAXIS_USB = 0x80,
PADOPTION_SIXAXIS_USB = 0x80, PADOPTION_SIXAXIS_PRESSURE = 0x100
PADOPTION_SIXAXIS_PRESSURE = 0x100
}; };
extern FILE *padLog; extern FILE *padLog;
@ -82,55 +81,53 @@ extern bool toggleAutoRepeat;
#define PAD_LOG __Log #define PAD_LOG __Log
//#define PAD_LOG __LogToConsole //#define PAD_LOG __LogToConsole
enum PadCommands enum PadCommands {
{ CMD_SET_VREF_PARAM = 0x40,
CMD_SET_VREF_PARAM = 0x40, CMD_QUERY_DS2_ANALOG_MODE = 0x41,
CMD_QUERY_DS2_ANALOG_MODE = 0x41, CMD_READ_DATA_AND_VIBRATE = 0x42,
CMD_READ_DATA_AND_VIBRATE = 0x42, CMD_CONFIG_MODE = 0x43,
CMD_CONFIG_MODE = 0x43, CMD_SET_MODE_AND_LOCK = 0x44,
CMD_SET_MODE_AND_LOCK = 0x44, CMD_QUERY_MODEL_AND_MODE = 0x45,
CMD_QUERY_MODEL_AND_MODE = 0x45, CMD_QUERY_ACT = 0x46, // ??
CMD_QUERY_ACT = 0x46, // ?? CMD_QUERY_COMB = 0x47, // ??
CMD_QUERY_COMB = 0x47, // ?? CMD_QUERY_MODE = 0x4C, // QUERY_MODE ??
CMD_QUERY_MODE = 0x4C, // QUERY_MODE ?? CMD_VIBRATION_TOGGLE = 0x4D,
CMD_VIBRATION_TOGGLE = 0x4D, CMD_SET_DS2_NATIVE_MODE = 0x4F // SET_DS2_NATIVE_MODE
CMD_SET_DS2_NATIVE_MODE = 0x4F // SET_DS2_NATIVE_MODE
}; };
enum gamePadValues enum gamePadValues {
{ PAD_L2 = 0, // L2 button
PAD_L2 = 0, // L2 button PAD_R2, // R2 button
PAD_R2, // R2 button PAD_L1, // L1 button
PAD_L1, // L1 button PAD_R1, // R1 button
PAD_R1, // R1 button PAD_TRIANGLE, // Triangle button ▲
PAD_TRIANGLE, // Triangle button ▲ PAD_CIRCLE, // Circle button ●
PAD_CIRCLE, // Circle button ● PAD_CROSS, // Cross button ✖
PAD_CROSS, // Cross button ✖ PAD_SQUARE, // Square button ■
PAD_SQUARE, // Square button ■ PAD_SELECT, // Select button
PAD_SELECT, // Select button PAD_L3, // Left joystick button (L3)
PAD_L3, // Left joystick button (L3) PAD_R3, // Right joystick button (R3)
PAD_R3, // Right joystick button (R3) PAD_START, // Start button
PAD_START, // Start button PAD_UP, // Directional pad ↑
PAD_UP, // Directional pad ↑ PAD_RIGHT, // Directional pad →
PAD_RIGHT, // Directional pad → PAD_DOWN, // Directional pad ↓
PAD_DOWN, // Directional pad ↓ PAD_LEFT, // Directional pad ←
PAD_LEFT, // Directional pad ← PAD_L_UP, // Left joystick (Up) ↑
PAD_L_UP, // Left joystick (Up) ↑ PAD_L_RIGHT, // Left joystick (Right) →
PAD_L_RIGHT, // Left joystick (Right) → PAD_L_DOWN, // Left joystick (Down) ↓
PAD_L_DOWN, // Left joystick (Down) ↓ PAD_L_LEFT, // Left joystick (Left) ←
PAD_L_LEFT, // Left joystick (Left) ← PAD_R_UP, // Right joystick (Up) ↑
PAD_R_UP, // Right joystick (Up) ↑ PAD_R_RIGHT, // Right joystick (Right) →
PAD_R_RIGHT, // Right joystick (Right) → PAD_R_DOWN, // Right joystick (Down) ↓
PAD_R_DOWN, // Right joystick (Down) ↓ PAD_R_LEFT // Right joystick (Left) ←
PAD_R_LEFT // Right joystick (Left) ←
}; };
extern keyEvent event; extern keyEvent event;
extern queue<keyEvent> ev_fifo; extern queue<keyEvent> ev_fifo;
extern pthread_spinlock_t mutex_KeyEvent; extern pthread_spinlock_t mutex_KeyEvent;
void clearPAD(int pad); void clearPAD(int pad);
s32 _PADopen(void *pDsp); s32 _PADopen(void *pDsp);
void _PADclose(); void _PADclose();
void PADsetMode(int pad, int mode); void PADsetMode(int pad, int mode);

View File

@ -22,20 +22,20 @@
#include "state_management.h" #include "state_management.h"
// Typical packet response on the bus // Typical packet response on the bus
static const u8 ConfigExit[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static const u8 ConfigExit[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const u8 noclue[7] = {0x5A, 0x00, 0x00, 0x02, 0x00, 0x00, 0x5A}; static const u8 noclue[7] = {0x5A, 0x00, 0x00, 0x02, 0x00, 0x00, 0x5A};
static const u8 setMode[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static const u8 setMode[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const u8 queryModelDS2[7] = {0x5A, 0x03, 0x02, 0x00, 0x02, 0x01, 0x00}; static const u8 queryModelDS2[7] = {0x5A, 0x03, 0x02, 0x00, 0x02, 0x01, 0x00};
static const u8 queryModelDS1[7] = {0x5A, 0x01, 0x02, 0x00, 0x02, 0x01, 0x00}; static const u8 queryModelDS1[7] = {0x5A, 0x01, 0x02, 0x00, 0x02, 0x01, 0x00};
static const u8 queryComb[7] = {0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}; static const u8 queryComb[7] = {0x5A, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00};
static const u8 queryMode[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static const u8 queryMode[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const u8 setNativeMode[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A}; static const u8 setNativeMode[7] = {0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5A};
static u8 queryMaskMode[7] = {0x5A, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x5A}; static u8 queryMaskMode[7] = {0x5A, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x5A};
static const u8 queryAct[2][7] = { static const u8 queryAct[2][7] = {
{0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}, {0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A},
{0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14}}; {0x5A, 0x00, 0x00, 0x01, 0x01, 0x01, 0x14}};
QueryInfo query; QueryInfo query;
Pad pads[2][4]; Pad pads[2][4];
@ -47,29 +47,29 @@ int slots[2] = {0, 0};
void QueryInfo::reset() void QueryInfo::reset()
{ {
port = 0; port = 0;
slot = 0; slot = 0;
lastByte = 1; lastByte = 1;
currentCommand = 0; currentCommand = 0;
numBytes = 0; numBytes = 0;
queryDone = 1; queryDone = 1;
memset(response, 0xF3, sizeof(response)); memset(response, 0xF3, sizeof(response));
} }
u8 QueryInfo::start_poll(int _port) u8 QueryInfo::start_poll(int _port)
{ {
if (port > 1) { if (port > 1) {
reset(); reset();
return 0; return 0;
} }
queryDone = 0; queryDone = 0;
port = _port; port = _port;
slot = slots[port]; slot = slots[port];
numBytes = 2; numBytes = 2;
lastByte = 0; lastByte = 0;
return 0xFF; return 0xFF;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -78,53 +78,53 @@ u8 QueryInfo::start_poll(int _port)
void Pad::set_mode(int _mode) void Pad::set_mode(int _mode)
{ {
mode = _mode; mode = _mode;
fprintf(stdout, "OnePad: set new pad mode="); fprintf(stdout, "OnePad: set new pad mode=");
if (mode == MODE_DIGITAL) if (mode == MODE_DIGITAL)
fprintf(stdout, "DIGITAL\n"); fprintf(stdout, "DIGITAL\n");
else if (mode == MODE_ANALOG) else if (mode == MODE_ANALOG)
fprintf(stdout, "ANALOG\n"); fprintf(stdout, "ANALOG\n");
else if (mode == MODE_DS2_NATIVE) else if (mode == MODE_DS2_NATIVE)
fprintf(stdout, "DS2 NATIVE\n"); fprintf(stdout, "DS2 NATIVE\n");
else else
fprintf(stdout, "??? 0x%x\n", mode); fprintf(stdout, "??? 0x%x\n", mode);
} }
void Pad::set_vibrate(int motor, u8 val) void Pad::set_vibrate(int motor, u8 val)
{ {
nextVibrate[motor] = val; nextVibrate[motor] = val;
} }
void Pad::reset_vibrate() void Pad::reset_vibrate()
{ {
set_vibrate(0, 0); set_vibrate(0, 0);
set_vibrate(1, 0); set_vibrate(1, 0);
memset(vibrate, 0xFF, sizeof(vibrate)); memset(vibrate, 0xFF, sizeof(vibrate));
vibrate[0] = 0x5A; vibrate[0] = 0x5A;
} }
void Pad::reset() void Pad::reset()
{ {
memset(this, 0, sizeof(PadFreezeData)); memset(this, 0, sizeof(PadFreezeData));
set_mode(MODE_DIGITAL); set_mode(MODE_DIGITAL);
umask[0] = umask[1] = 0xFF; umask[0] = umask[1] = 0xFF;
// Sets up vibrate variable. // Sets up vibrate variable.
reset_vibrate(); reset_vibrate();
} }
void Pad::rumble(int port) void Pad::rumble(int port)
{ {
for (int motor=0; motor<2; motor++) { for (int motor = 0; motor < 2; motor++) {
// TODO: Probably be better to send all of these at once. // TODO: Probably be better to send all of these at once.
if (nextVibrate[motor] | currentVibrate[motor]) { if (nextVibrate[motor] | currentVibrate[motor]) {
currentVibrate[motor] = nextVibrate[motor]; currentVibrate[motor] = nextVibrate[motor];
GamePad::DoRumble(motor, port); GamePad::DoRumble(motor, port);
} }
} }
} }
void Pad::stop_vibrate_all() void Pad::stop_vibrate_all()
@ -135,71 +135,71 @@ void Pad::stop_vibrate_all()
SetVibrate(i&1, i>>1, 1, 0); SetVibrate(i&1, i>>1, 1, 0);
} }
#endif #endif
// FIXME equivalent ? // FIXME equivalent ?
for (int port = 0; port < 2; port++) for (int port = 0; port < 2; port++)
for (int slot = 0; slot < 4; slot++) for (int slot = 0; slot < 4; slot++)
pads[port][slot].reset_vibrate(); pads[port][slot].reset_vibrate();
} }
void Pad::reset_all() void Pad::reset_all()
{ {
for (int port = 0; port < 2; port++) for (int port = 0; port < 2; port++)
for (int slot = 0; slot < 4; slot++) for (int slot = 0; slot < 4; slot++)
pads[port][slot].reset(); pads[port][slot].reset();
} }
void Pad::rumble_all() void Pad::rumble_all()
{ {
for (int port=0; port<2; port++) for (int port = 0; port < 2; port++)
for (int slot=0; slot<4; slot++) for (int slot = 0; slot < 4; slot++)
pads[port][slot].rumble(port); pads[port][slot].rumble(port);
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Pad implementation // Pad implementation
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
inline bool IsDualshock2() { inline bool IsDualshock2()
{
// FIXME // FIXME
#if 0 #if 0
return config.padConfigs[query.port][query.slot].type == Dualshock2Pad || return config.padConfigs[query.port][query.slot].type == Dualshock2Pad ||
(config.padConfigs[query.port][query.slot].type == GuitarPad && config.GH2); (config.padConfigs[query.port][query.slot].type == GuitarPad && config.GH2);
#else #else
return true; return true;
#endif #endif
} }
u8 pad_start_poll(u8 pad) u8 pad_start_poll(u8 pad)
{ {
return query.start_poll(pad - 1); return query.start_poll(pad - 1);
} }
u8 pad_poll(u8 value) u8 pad_poll(u8 value)
{ {
if (query.lastByte+1 >= query.numBytes) { if (query.lastByte + 1 >= query.numBytes) {
return 0; return 0;
} }
if (query.lastByte && query.queryDone) { if (query.lastByte && query.queryDone) {
return query.response[++query.lastByte]; return query.response[++query.lastByte];
} }
Pad *pad = &pads[query.port][query.slot]; Pad *pad = &pads[query.port][query.slot];
if (query.lastByte == 0) { if (query.lastByte == 0) {
query.lastByte++; query.lastByte++;
query.currentCommand = value; query.currentCommand = value;
switch(value) { switch (value) {
case CMD_CONFIG_MODE: case CMD_CONFIG_MODE:
if (pad->config) { if (pad->config) {
// In config mode. Might not actually be leaving it. // In config mode. Might not actually be leaving it.
query.set_result(ConfigExit); query.set_result(ConfigExit);
} }
break; break;
case CMD_READ_DATA_AND_VIBRATE: case CMD_READ_DATA_AND_VIBRATE: {
{ query.response[2] = 0x5A;
query.response[2] = 0x5A;
#if 0 #if 0
int i; int i;
Update(query.port, query.slot); Update(query.port, query.slot);
@ -214,7 +214,7 @@ u8 pad_poll(u8 value)
} }
#endif #endif
// FIXME // FIXME
#if 0 #if 0
if (config.padConfigs[query.port][query.slot].type == GuitarPad && !config.GH2) { if (config.padConfigs[query.port][query.slot].type == GuitarPad && !config.GH2) {
sum->buttons[15] = 255; sum->buttons[15] = 255;
@ -229,46 +229,46 @@ u8 pad_poll(u8 value)
} }
#endif #endif
// FIXME // FIXME
#if 0 #if 0
//Left, Right and Down are always pressed on Pop'n Music controller. //Left, Right and Down are always pressed on Pop'n Music controller.
if (config.padConfigs[query.port][query.slot].type == PopnPad) if (config.padConfigs[query.port][query.slot].type == PopnPad)
b1=b1 & 0x1f; b1=b1 & 0x1f;
#endif #endif
uint16_t buttons = key_status->get(query.port); uint16_t buttons = key_status->get(query.port);
query.numBytes = 5; query.numBytes = 5;
query.response[3] = (buttons >> 8) & 0xFF; query.response[3] = (buttons >> 8) & 0xFF;
query.response[4] = (buttons >> 0) & 0xFF; query.response[4] = (buttons >> 0) & 0xFF;
if (pad->mode != MODE_DIGITAL) { // ANALOG || DS2 native if (pad->mode != MODE_DIGITAL) { // ANALOG || DS2 native
query.numBytes = 9; query.numBytes = 9;
query.response[5] = key_status->get(query.port, PAD_R_RIGHT); query.response[5] = key_status->get(query.port, PAD_R_RIGHT);
query.response[6] = key_status->get(query.port, PAD_R_UP); query.response[6] = key_status->get(query.port, PAD_R_UP);
query.response[7] = key_status->get(query.port, PAD_L_RIGHT); query.response[7] = key_status->get(query.port, PAD_L_RIGHT);
query.response[8] = key_status->get(query.port, PAD_L_UP); query.response[8] = key_status->get(query.port, PAD_L_UP);
if (pad->mode != MODE_ANALOG) { // DS2 native if (pad->mode != MODE_ANALOG) { // DS2 native
query.numBytes = 21; query.numBytes = 21;
query.response[9] = !test_bit(buttons, 13) ? key_status->get(query.port, PAD_RIGHT) : 0; query.response[9] = !test_bit(buttons, 13) ? key_status->get(query.port, PAD_RIGHT) : 0;
query.response[10] = !test_bit(buttons, 15) ? key_status->get(query.port, PAD_LEFT) : 0; query.response[10] = !test_bit(buttons, 15) ? key_status->get(query.port, PAD_LEFT) : 0;
query.response[11] = !test_bit(buttons, 12) ? key_status->get(query.port, PAD_UP) : 0; query.response[11] = !test_bit(buttons, 12) ? key_status->get(query.port, PAD_UP) : 0;
query.response[12] = !test_bit(buttons, 14) ? key_status->get(query.port, PAD_DOWN) : 0; query.response[12] = !test_bit(buttons, 14) ? key_status->get(query.port, PAD_DOWN) : 0;
query.response[13] = !test_bit(buttons, 4) ? key_status->get(query.port, PAD_TRIANGLE) : 0; query.response[13] = !test_bit(buttons, 4) ? key_status->get(query.port, PAD_TRIANGLE) : 0;
query.response[14] = !test_bit(buttons, 5) ? key_status->get(query.port, PAD_CIRCLE) : 0; query.response[14] = !test_bit(buttons, 5) ? key_status->get(query.port, PAD_CIRCLE) : 0;
query.response[15] = !test_bit(buttons, 6) ? key_status->get(query.port, PAD_CROSS) : 0; query.response[15] = !test_bit(buttons, 6) ? key_status->get(query.port, PAD_CROSS) : 0;
query.response[16] = !test_bit(buttons, 7) ? key_status->get(query.port, PAD_SQUARE) : 0; query.response[16] = !test_bit(buttons, 7) ? key_status->get(query.port, PAD_SQUARE) : 0;
query.response[17] = !test_bit(buttons, 2) ? key_status->get(query.port, PAD_L1) : 0; query.response[17] = !test_bit(buttons, 2) ? key_status->get(query.port, PAD_L1) : 0;
query.response[18] = !test_bit(buttons, 3) ? key_status->get(query.port, PAD_R1) : 0; query.response[18] = !test_bit(buttons, 3) ? key_status->get(query.port, PAD_R1) : 0;
query.response[19] = !test_bit(buttons, 0) ? key_status->get(query.port, PAD_L2) : 0; query.response[19] = !test_bit(buttons, 0) ? key_status->get(query.port, PAD_L2) : 0;
query.response[20] = !test_bit(buttons, 1) ? key_status->get(query.port, PAD_R2) : 0; query.response[20] = !test_bit(buttons, 1) ? key_status->get(query.port, PAD_R2) : 0;
} }
} }
#if 0 #if 0
query.response[3] = b1; query.response[3] = b1;
@ -305,161 +305,160 @@ u8 pad_poll(u8 value)
} }
} }
#endif #endif
} }
query.lastByte=1; query.lastByte = 1;
return pad->mode; return pad->mode;
case CMD_SET_VREF_PARAM: case CMD_SET_VREF_PARAM:
query.set_final_result(noclue); query.set_final_result(noclue);
break; break;
case CMD_QUERY_DS2_ANALOG_MODE: case CMD_QUERY_DS2_ANALOG_MODE:
// Right? Wrong? No clue. // Right? Wrong? No clue.
if (pad->mode == MODE_DIGITAL) { if (pad->mode == MODE_DIGITAL) {
queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0; queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0;
queryMaskMode[6] = 0x00; queryMaskMode[6] = 0x00;
} } else {
else { queryMaskMode[1] = pad->umask[0];
queryMaskMode[1] = pad->umask[0]; queryMaskMode[2] = pad->umask[1];
queryMaskMode[2] = pad->umask[1]; queryMaskMode[3] = 0x03;
queryMaskMode[3] = 0x03; // Not entirely sure about this.
// Not entirely sure about this. //queryMaskMode[3] = 0x01 | (pad->mode == MODE_DS2_NATIVE)*2;
//queryMaskMode[3] = 0x01 | (pad->mode == MODE_DS2_NATIVE)*2; queryMaskMode[6] = 0x5A;
queryMaskMode[6] = 0x5A; }
} query.set_final_result(queryMaskMode);
query.set_final_result(queryMaskMode); break;
break;
case CMD_SET_MODE_AND_LOCK: case CMD_SET_MODE_AND_LOCK:
query.set_result(setMode); query.set_result(setMode);
pad->reset_vibrate(); pad->reset_vibrate();
break; break;
case CMD_QUERY_MODEL_AND_MODE: case CMD_QUERY_MODEL_AND_MODE:
if (IsDualshock2()) { if (IsDualshock2()) {
query.set_final_result(queryModelDS2); query.set_final_result(queryModelDS2);
} else { } else {
query.set_final_result(queryModelDS1); query.set_final_result(queryModelDS1);
} }
// Not digital mode. // Not digital mode.
query.response[5] = (pad->mode & 0xF) != 1; query.response[5] = (pad->mode & 0xF) != 1;
break; break;
case CMD_QUERY_ACT: case CMD_QUERY_ACT:
query.set_result(queryAct[0]); query.set_result(queryAct[0]);
break; break;
case CMD_QUERY_COMB: case CMD_QUERY_COMB:
query.set_final_result(queryComb); query.set_final_result(queryComb);
break; break;
case CMD_QUERY_MODE: case CMD_QUERY_MODE:
query.set_result(queryMode); query.set_result(queryMode);
break; break;
case CMD_VIBRATION_TOGGLE: case CMD_VIBRATION_TOGGLE:
memcpy(query.response+2, pad->vibrate, 7); memcpy(query.response + 2, pad->vibrate, 7);
query.numBytes = 9; query.numBytes = 9;
//query.set_result(pad->vibrate); // warning copy 7b not 8 (but it is really important?) //query.set_result(pad->vibrate); // warning copy 7b not 8 (but it is really important?)
pad->reset_vibrate(); pad->reset_vibrate();
break; break;
case CMD_SET_DS2_NATIVE_MODE: case CMD_SET_DS2_NATIVE_MODE:
if (IsDualshock2()) { if (IsDualshock2()) {
query.set_result(setNativeMode); query.set_result(setNativeMode);
} else { } else {
query.set_final_result(setNativeMode); query.set_final_result(setNativeMode);
} }
break; break;
default: default:
query.numBytes = 0; query.numBytes = 0;
query.queryDone = 1; query.queryDone = 1;
break; break;
} }
return 0xF3; return 0xF3;
} else { } else {
query.lastByte++; query.lastByte++;
switch (query.currentCommand) { switch (query.currentCommand) {
case CMD_READ_DATA_AND_VIBRATE: case CMD_READ_DATA_AND_VIBRATE:
if (query.lastByte == pad->vibrateI[0]) if (query.lastByte == pad->vibrateI[0])
pad->set_vibrate(1, 255*(value&1)); pad->set_vibrate(1, 255 * (value & 1));
else if (query.lastByte == pad->vibrateI[1]) else if (query.lastByte == pad->vibrateI[1])
pad->set_vibrate(0, value); pad->set_vibrate(0, value);
break; break;
case CMD_CONFIG_MODE: case CMD_CONFIG_MODE:
if (query.lastByte == 3) { if (query.lastByte == 3) {
query.queryDone = 1; query.queryDone = 1;
pad->config = value; pad->config = value;
} }
break; break;
case CMD_SET_MODE_AND_LOCK: case CMD_SET_MODE_AND_LOCK:
if (query.lastByte == 3 && value < 2) { if (query.lastByte == 3 && value < 2) {
pad->set_mode(value ? MODE_ANALOG : MODE_DIGITAL); pad->set_mode(value ? MODE_ANALOG : MODE_DIGITAL);
} else if (query.lastByte == 4) { } else if (query.lastByte == 4) {
if (value == 3) if (value == 3)
pad->modeLock = 3; pad->modeLock = 3;
else else
pad->modeLock = 0; pad->modeLock = 0;
query.queryDone = 1; query.queryDone = 1;
} }
break; break;
case CMD_QUERY_ACT: case CMD_QUERY_ACT:
if (query.lastByte == 3) { if (query.lastByte == 3) {
if (value<2) query.set_result(queryAct[value]); if (value < 2)
// bunch of 0's query.set_result(queryAct[value]);
// else query.set_result(setMode); // bunch of 0's
query.queryDone = 1; // else query.set_result(setMode);
} query.queryDone = 1;
break; }
break;
case CMD_QUERY_MODE: case CMD_QUERY_MODE:
if (query.lastByte == 3 && value<2) { if (query.lastByte == 3 && value < 2) {
query.response[6] = 4+value*3; query.response[6] = 4 + value * 3;
query.queryDone = 1; query.queryDone = 1;
} }
// bunch of 0's // bunch of 0's
//else data = setMode; //else data = setMode;
break; break;
case CMD_VIBRATION_TOGGLE: case CMD_VIBRATION_TOGGLE:
if (query.lastByte>=3) { if (query.lastByte >= 3) {
if (value == 0) { if (value == 0) {
pad->vibrateI[0] = (u8)query.lastByte; pad->vibrateI[0] = (u8)query.lastByte;
} } else if (value == 1) {
else if (value == 1) { pad->vibrateI[1] = (u8)query.lastByte;
pad->vibrateI[1] = (u8)query.lastByte; }
} pad->vibrate[query.lastByte - 2] = value;
pad->vibrate[query.lastByte-2] = value; }
} break;
break;
case CMD_SET_DS2_NATIVE_MODE: case CMD_SET_DS2_NATIVE_MODE:
if (query.lastByte == 3 || query.lastByte == 4) { if (query.lastByte == 3 || query.lastByte == 4) {
pad->umask[query.lastByte-3] = value; pad->umask[query.lastByte - 3] = value;
} else if (query.lastByte == 5) { } else if (query.lastByte == 5) {
if (!(value & 1)) if (!(value & 1))
pad->set_mode(MODE_DIGITAL); pad->set_mode(MODE_DIGITAL);
else if (!(value & 2)) else if (!(value & 2))
pad->set_mode(MODE_ANALOG); pad->set_mode(MODE_ANALOG);
else else
pad->set_mode(MODE_DS2_NATIVE); pad->set_mode(MODE_DS2_NATIVE);
} }
break; break;
default: default:
return 0; return 0;
} }
return query.response[query.lastByte]; return query.response[query.lastByte];
} }
} }

View File

@ -26,79 +26,83 @@
#define MODE_DS2_NATIVE 0x79 #define MODE_DS2_NATIVE 0x79
// The state of the PS2 bus // The state of the PS2 bus
struct QueryInfo { struct QueryInfo
u8 port; {
u8 slot; u8 port;
u8 lastByte; u8 slot;
u8 currentCommand; u8 lastByte;
u8 numBytes; u8 currentCommand;
u8 queryDone; u8 numBytes;
u8 response[42]; u8 queryDone;
u8 response[42];
void reset(); void reset();
u8 start_poll(int port); u8 start_poll(int port);
template<size_t S> template <size_t S>
void set_result(const u8 (&rsp)[S]) void set_result(const u8 (&rsp)[S])
{ {
memcpy(response+2, rsp, S); memcpy(response + 2, rsp, S);
numBytes = 2 + S; numBytes = 2 + S;
} }
template<size_t S> template <size_t S>
void set_final_result(const u8 (&rsp)[S]) void set_final_result(const u8 (&rsp)[S])
{ {
set_result(rsp); set_result(rsp);
queryDone = 1; queryDone = 1;
} }
}; };
// Freeze data, for a single pad. Basically has all pad state that // Freeze data, for a single pad. Basically has all pad state that
// a PS2 can set. // a PS2 can set.
struct PadFreezeData { struct PadFreezeData
// Digital / Analog / DS2 Native {
u8 mode; // Digital / Analog / DS2 Native
u8 mode;
u8 modeLock; u8 modeLock;
// In config mode // In config mode
u8 config; u8 config;
u8 vibrate[8]; u8 vibrate[8];
u8 umask[2]; u8 umask[2];
// Vibration indices. // Vibration indices.
u8 vibrateI[2]; u8 vibrateI[2];
// Last vibration value sent to controller. // Last vibration value sent to controller.
// Only used so as not to call vibration // Only used so as not to call vibration
// functions when old and new values are both 0. // functions when old and new values are both 0.
u8 currentVibrate[2]; u8 currentVibrate[2];
// Next vibrate val to send to controller. If next and current are // Next vibrate val to send to controller. If next and current are
// both 0, nothing is sent to the controller. Otherwise, it's sent // both 0, nothing is sent to the controller. Otherwise, it's sent
// on every update. // on every update.
u8 nextVibrate[2]; u8 nextVibrate[2];
}; };
class Pad : public PadFreezeData { class Pad : public PadFreezeData
{
public: public:
// Lilypad store here the state of PC pad // Lilypad store here the state of PC pad
void rumble(int port); void rumble(int port);
void set_vibrate(int motor, u8 val); void set_vibrate(int motor, u8 val);
void reset_vibrate(); void reset_vibrate();
void reset(); void reset();
void set_mode(int mode); void set_mode(int mode);
static void reset_all(); static void reset_all();
static void stop_vibrate_all(); static void stop_vibrate_all();
static void rumble_all(); static void rumble_all();
}; };
// Full state to manage save state // Full state to manage save state
struct PadPluginFreezeData { struct PadPluginFreezeData
{
char format[8]; char format[8];
u32 version; u32 version;
// active slot for port // active slot for port