From 0b23b770513f7218d71acf69c020b2c76b8995a9 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Sat, 9 May 2009 20:06:57 +0000 Subject: [PATCH] Zeropad: Continuing to do some cleanup. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1162 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/zeropad/Linux/joystick.cpp | 6 +- plugins/zeropad/Linux/joystick.h | 42 +++--- plugins/zeropad/Linux/linux.cpp | 142 ++++++-------------- plugins/zeropad/Makefile.am | 3 +- plugins/zeropad/Windows/ZeroPAD_2008.vcproj | 8 ++ plugins/zeropad/configure.ac | 8 +- plugins/zeropad/zeropad.cpp | 49 +++---- plugins/zeropad/zeropad.h | 17 ++- 8 files changed, 114 insertions(+), 161 deletions(-) diff --git a/plugins/zeropad/Linux/joystick.cpp b/plugins/zeropad/Linux/joystick.cpp index a4af64108d..514de20e5a 100644 --- a/plugins/zeropad/Linux/joystick.cpp +++ b/plugins/zeropad/Linux/joystick.cpp @@ -108,7 +108,6 @@ bool JoystickInfo::Init(int id, bool bStartThread) numaxes = SDL_JoystickNumAxes(joy); numbuttons = SDL_JoystickNumButtons(joy); numpov = SDL_JoystickNumHats(joy); - numhats = SDL_JoystickNumHats(joy); devname = SDL_JoystickName(id); vbutstate.resize(numbuttons); vaxisstate.resize(numbuttons); @@ -144,9 +143,8 @@ void JoystickInfo::SaveState() vbutstate[i] = SDL_JoystickGetButton(joy, i); for (int i = 0; i < numaxes; ++i) vaxisstate[i] = SDL_JoystickGetAxis(joy, i); - - //for (int i = 0; i < numhats; ++i) - // vhatstate[i] = SDL_JoystickGetHat(joy, i); + /*for (int i = 0; i < numpov; ++i) + vpovstate[i] = SDL_JoystickGetHat(joy, i);*/ } void JoystickInfo::TestForce() diff --git a/plugins/zeropad/Linux/joystick.h b/plugins/zeropad/Linux/joystick.h index b7e53ac37b..fd4d2266d8 100644 --- a/plugins/zeropad/Linux/joystick.h +++ b/plugins/zeropad/Linux/joystick.h @@ -42,60 +42,71 @@ class JoystickInfo { return devname; } + int GetNumButtons() { return numbuttons; } + int GetNumAxes() { return numaxes; } + int GetNumPOV() { return numpov; } - /*int GetNumHats() - { - return numhats; - }*/ + int GetId() { return _id; } + int GetPAD() { return pad; } + int GetDeadzone(int axis) { return deadzone; } void SaveState(); + int GetButtonState(int i) { return vbutstate[i]; } + int GetAxisState(int i) { return vaxisstate[i]; } - /*int GetHatState(int i) + + int GetPOVState(int i) { - return vhatstate[i]; - }*/ + //printf("Getting POV State of %d.\n", i); + return vpovstate[i]; + } + void SetButtonState(int i, int state) { vbutstate[i] = state; } + void SetAxisState(int i, int value) { vaxisstate[i] = value; } - /*void SetHatState(int i, int value) + + void SetPOVState(int i, int value) { - vhatstate[i] = value; - }*/ + //printf("We should set %d to %d.\n", i, value); + vpovstate[i] = value; + } + SDL_Joystick* GetJoy() { return joy; @@ -105,11 +116,11 @@ class JoystickInfo string devname; // pretty device name int _id; - int numbuttons, numaxes, numpov, numhats; + int numbuttons, numaxes, numpov; int axisrange, deadzone; int pad; - vector vbutstate, vaxisstate; + vector vbutstate, vaxisstate, vpovstate; SDL_Joystick* joy; }; @@ -117,10 +128,3 @@ class JoystickInfo extern int s_selectedpad; extern vector s_vjoysticks; -//extern void JoystickInfo::EnumerateJoysticks(vector& vjoysticks); -/*extern JoystickInfo::JoystickInfo(); -extern void JoystickInfo::Destroy(); -extern bool JoystickInfo::Init(int id, bool bStartThread); -extern void JoystickInfo::Assign(int newpad); -extern void JoystickInfo::SaveState(); -extern void JoystickInfo::TestForce();*/ \ No newline at end of file diff --git a/plugins/zeropad/Linux/linux.cpp b/plugins/zeropad/Linux/linux.cpp index dcf346c382..e61b1f5792 100644 --- a/plugins/zeropad/Linux/linux.cpp +++ b/plugins/zeropad/Linux/linux.cpp @@ -138,50 +138,23 @@ void CALLBACK PADupdate(int pad) switch (key) { case KEY_PAD_LX_LEFT: - g_lanalog[pad].x = DEF_VALUE / 256; - if (conf.options&PADOPTION_REVERTLX) g_lanalog[pad].x = -g_lanalog[pad].x; - g_lanalog[pad].x += 0x80; + case KEY_PAD_LY_UP: + case KEY_PAD_RX_LEFT: + case KEY_PAD_RY_UP: + Analog::ConfigurePad(KeypadToPad(key), pad, DEF_VALUE); break; case KEY_PAD_LX_RIGHT: - g_lanalog[pad].x = -DEF_VALUE / 256; - if (conf.options&PADOPTION_REVERTLX) g_lanalog[pad].x = -g_lanalog[pad].x; - g_lanalog[pad].x += 0x80; - break; - case KEY_PAD_LY_UP: - g_lanalog[pad].y = DEF_VALUE / 256; - if (conf.options&PADOPTION_REVERTLY) g_lanalog[pad].y = -g_lanalog[pad].y; - g_lanalog[pad].y += 0x80; - break; case KEY_PAD_LY_DOWN: - g_lanalog[pad].y = -DEF_VALUE / 256; - if (conf.options&PADOPTION_REVERTLY) g_lanalog[pad].y = -g_lanalog[pad].y; - g_lanalog[pad].y += 0x80; - break; - case KEY_PAD_RX_LEFT: - g_ranalog[pad].x = DEF_VALUE / 256; - if (conf.options&PADOPTION_REVERTRX) g_ranalog[pad].x = -g_ranalog[pad].x; - g_ranalog[pad].x += 0x80; - break; case KEY_PAD_RX_RIGHT: - g_ranalog[pad].x = -DEF_VALUE / 256; - if (conf.options&PADOPTION_REVERTRX) g_ranalog[pad].x = -g_ranalog[pad].x; - g_ranalog[pad].x += 0x80; - break; - case KEY_PAD_RY_UP: - g_ranalog[pad].y = DEF_VALUE / 256; - if (conf.options&PADOPTION_REVERTRY) g_ranalog[pad].y = -g_ranalog[pad].y; - g_ranalog[pad].y += 0x80; - break; case KEY_PAD_RY_DOWN: - g_ranalog[pad].y = -DEF_VALUE / 256; - if (conf.options&PADOPTION_REVERTRY) g_ranalog[pad].y = -g_ranalog[pad].y; - g_ranalog[pad].y += 0x80; + Analog::ConfigurePad(KeypadToPad(key), pad, -DEF_VALUE); break; } #endif i = FindKey(key, pad); - if (i != -1) { + if (i != -1) + { keyPress |= (1 << i); keyRelease &= ~(1 << i); } @@ -196,34 +169,21 @@ void CALLBACK PADupdate(int pad) switch (key) { case KEY_PAD_LX_LEFT: - g_lanalog[pad].x = 0x80; - break; - case KEY_PAD_LY_UP: - g_lanalog[pad].y = 0x80; - break; - case KEY_PAD_RX_LEFT: - g_ranalog[pad].x = 0x80; - break; - case KEY_PAD_RY_UP: - g_ranalog[pad].y = 0x80; - break; case KEY_PAD_LX_RIGHT: - g_lanalog[pad].x = 0x80; - break; + case KEY_PAD_LY_UP: case KEY_PAD_LY_DOWN: - g_lanalog[pad].y = 0x80; - break; + case KEY_PAD_RX_LEFT: case KEY_PAD_RX_RIGHT: - g_ranalog[pad].x = 0x80; - break; + case KEY_PAD_RY_UP: case KEY_PAD_RY_DOWN: - g_ranalog[pad].y = 0x80; + Analog::ResetPad(KeypadToPad(key)); break; } #endif i = FindKey(key, pad); - if (i != -1) { + if (i != -1) + { keyPress &= ~(1 << i); keyRelease |= (1 << i); } @@ -277,52 +237,13 @@ void CALLBACK PADupdate(int pad) switch (i) { case PAD_LX: - if (abs(value) > (pjoy)->GetDeadzone(value)) - { - g_lanalog[pad].x = value / 256; - if (conf.options & PADOPTION_REVERTLX) g_lanalog[pad].x = -g_lanalog[pad].x; - g_lanalog[pad].x += 0x80; - } - else - { - g_lanalog[pad].x = 0x80; - } - break; case PAD_LY: - if (abs(value) > (pjoy)->GetDeadzone(value)) - { - g_lanalog[pad].y = value / 256; - if (conf.options & PADOPTION_REVERTLY) g_lanalog[pad].y = -g_lanalog[pad].y; - g_lanalog[pad].y += 0x80; - } - else - { - g_lanalog[pad].y = 0x80; - } - break; case PAD_RX: - if (abs(value) > (pjoy)->GetDeadzone(value)) - { - g_ranalog[pad].x = value / 256; - if (conf.options & PADOPTION_REVERTRX) g_ranalog[pad].x = -g_ranalog[pad].x; - g_ranalog[pad].x += 0x80; - } - else - { - g_ranalog[pad].x = 0x80; - } - break; case PAD_RY: if (abs(value) > (pjoy)->GetDeadzone(value)) - { - g_ranalog[pad].y = value / 256; - if (conf.options&PADOPTION_REVERTRY) g_ranalog[pad].y = -g_ranalog[pad].y; - g_ranalog[pad].y += 0x80; - } + Analog::ConfigurePad(i, pad, value); else - { - g_ranalog[pad].y = 0x80; - } + Analog::ResetPad(i, pad); break; } } @@ -516,6 +437,7 @@ void OnConf_Key(GtkButton *button, gpointer user_data) if (abs(value) <= (*itjoy)->GetAxisState(i)) // we don't want this { // released, we don't really want this + // SetButtonState? Shouldn't this be SetAxisState? (*itjoy)->SetButtonState(i, value); break; } @@ -543,21 +465,33 @@ void OnConf_Key(GtkButton *button, gpointer user_data) } } - - /*for (int i = 0; i < (*itjoy)->GetNumHats(); ++i) + /*for (int i = 0; i < (*itjoy)->GetNumPOV(); ++i) { int value = SDL_JoystickGetHat((*itjoy)->GetJoy(), i); - if (value != (*itjoy)->GetAxisState(i)) + if (value != (*itjoy)->GetPOVState(i)) { - *pkey = PAD_HAT((*itjoy)->GetId(), i); - char str[32]; - sprintf(str, "JHat %d", i); - gtk_entry_set_text(GTK_ENTRY(label), str); - return; + if (abs(value) > 0x3fff) + { + if (key < 16) // POV + { + *pkey = PAD_POV((*itjoy)->GetId(), value < 0, i); + char str[32]; + sprintf(str, "JPOV %d%s", i, value < 0 ? "-" : "+"); + gtk_entry_set_text(GTK_ENTRY(label), str); + return; + } + else // axis + { + *pkey = PAD_JOYSTICK((*itjoy)->GetId(), i); + char str[32]; + sprintf(str, "JAxis %d", i); + gtk_entry_set_text(GTK_ENTRY(label), str); + return; + } + } } }*/ - itjoy++; } #endif @@ -590,7 +524,7 @@ void CALLBACK PADconfigure() while (it != s_vjoysticks.end()) { sprintf(str, "%d: %s - but: %d, axes: %d, pov: %d", (*it)->GetId(), (*it)->GetName().c_str(), - (*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetNumPOV()/*, (*it)->GetNumHats()*/); // ,hats: %d + (*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetNumPOV()); gtk_combo_box_append_text(GTK_COMBO_BOX(s_devicecombo), str); it++; } diff --git a/plugins/zeropad/Makefile.am b/plugins/zeropad/Makefile.am index 81e048bcc9..9376619c69 100644 --- a/plugins/zeropad/Makefile.am +++ b/plugins/zeropad/Makefile.am @@ -27,4 +27,5 @@ libZeroPAD_LDFLAGS= @SHARED_LDFLAGS@ libZeroPAD_LDFLAGS+=-Wl,-soname,@ZEROPAD_SONAME@ libZeroPAD_LDADD=$(libZeroPAD_a_OBJECTS) -libZeroPAD_a_SOURCES = zeropad.cpp Linux/gui.cpp Linux/linux.cpp Linux/joystick.cpp Linux/support.c Linux/interface.c +libZeroPAD_a_SOURCES = analog.cpp analog.h zeropad.cpp zeropad.h \ +Linux/gui.cpp Linux/linux.cpp Linux/joystick.cpp Linux/support.c Linux/interface.c diff --git a/plugins/zeropad/Windows/ZeroPAD_2008.vcproj b/plugins/zeropad/Windows/ZeroPAD_2008.vcproj index f1e2d0552f..957161cb48 100644 --- a/plugins/zeropad/Windows/ZeroPAD_2008.vcproj +++ b/plugins/zeropad/Windows/ZeroPAD_2008.vcproj @@ -250,6 +250,10 @@ RelativePath="..\zeropad.cpp" > + + + + > 8; stdpar[curPad][3] = status[curPad] & 0xff; - stdpar[curPad][4] = g_ranalog[curPad].x; - stdpar[curPad][5] = g_ranalog[curPad].y; - stdpar[curPad][6] = g_lanalog[curPad].x; - stdpar[curPad][7] = g_lanalog[curPad].y; + stdpar[curPad][4] = Analog::Pad(PAD_RX, curPad); + stdpar[curPad][5] = Analog::Pad(PAD_RY, curPad); + stdpar[curPad][6] = Analog::Pad(PAD_LX, curPad); + stdpar[curPad][7] = Analog::Pad(PAD_LY, curPad); if (padMode[curPad] == 1) cmdLen = 20; @@ -473,44 +466,44 @@ u8 _PADpoll(u8 value) buf = stdpar[curPad]; return padID[curPad]; - case 0x43: // CONFIG_MODE + case CMD_CONFIG_MODE: // CONFIG_MODE cmdLen = 8; buf = stdcfg[curPad]; if (stdcfg[curPad][3] == 0xff) return 0xf3; else return padID[curPad]; - case 0x44: // SET_MODE_AND_LOCK + case CMD_SET_MODE_AND_LOCK: // SET_MODE_AND_LOCK cmdLen = 8; buf = stdmode[curPad]; return 0xf3; - case 0x45: // QUERY_MODEL_AND_MODE + case CMD_QUERY_MODEL_AND_MODE: // QUERY_MODEL_AND_MODE cmdLen = 8; buf = stdmodel[curPad]; buf[4] = padMode[curPad]; return 0xf3; - case 0x46: // ?? + case CMD_QUERY_ACT: // ?? cmdLen = 8; buf = unk46[curPad]; return 0xf3; - case 0x47: // ?? + case CMD_QUERY_COMB: // ?? cmdLen = 8; buf = unk47[curPad]; return 0xf3; - case 0x4c: // QUERY_MODE ?? + case CMD_QUERY_MODE: // QUERY_MODE ?? cmdLen = 8; buf = unk4c[curPad]; return 0xf3; - case 0x4d: + case CMD_VIBRATION_TOGGLE: cmdLen = 8; buf = unk4d[curPad]; return 0xf3; - case 0x4f: // SET_DS2_NATIVE_MODE + case CMD_SET_DS2_NATIVE_MODE: // SET_DS2_NATIVE_MODE cmdLen = 8; padID[curPad] = 0x79; // setting ds2 mode ds2mode = 1; // Set DS2 Mode @@ -527,7 +520,7 @@ u8 _PADpoll(u8 value) switch (curCmd) { - case 0x43: + case CMD_CONFIG_MODE: if (curByte == 2) { switch (value) @@ -544,14 +537,14 @@ u8 _PADpoll(u8 value) } break; - case 0x44: + case CMD_SET_MODE_AND_LOCK: if (curByte == 2) { PADsetMode(curPad, value); } break; - case 0x46: + case CMD_QUERY_ACT: if (curByte == 2) { switch (value) @@ -570,7 +563,7 @@ u8 _PADpoll(u8 value) } break; - case 0x4c: + case CMD_QUERY_MODE: if (curByte == 2) { switch (value) diff --git a/plugins/zeropad/zeropad.h b/plugins/zeropad/zeropad.h index 8d633ec780..81bd31fe4b 100644 --- a/plugins/zeropad/zeropad.h +++ b/plugins/zeropad/zeropad.h @@ -44,6 +44,7 @@ extern "C" { #include "PS2Edefs.h" } +#include "analog.h" extern char libraryName[256]; @@ -93,11 +94,25 @@ typedef struct } PADAnalog; extern PADconf conf; - extern PADAnalog g_lanalog[2], g_ranalog[2]; extern FILE *padLog; #define PAD_LOG __Log +enum PadCommands +{ + CMD_SET_VREF_PARAM = 0x40, + CMD_QUERY_DS2_ANALOG_MODE = 0x41, + CMD_READ_DATA_AND_VIBRATE = 0x42, + CMD_CONFIG_MODE = 0x43, + CMD_SET_MODE_AND_LOCK = 0x44, + CMD_QUERY_MODEL_AND_MODE = 0x45, + CMD_QUERY_ACT = 0x46, // ?? + CMD_QUERY_COMB = 0x47, // ?? + CMD_QUERY_MODE = 0x4C, // QUERY_MODE ?? + CMD_VIBRATION_TOGGLE = 0x4D, + CMD_SET_DS2_NATIVE_MODE = 0x4F // SET_DS2_NATIVE_MODE +}; + enum gamePadValues { PAD_RY = 19,