Zeropad: More cleanup, and some incomplete work on the POV code, which looks like it was only halfway implemented.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1164 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2009-05-09 22:44:06 +00:00
parent 05867d69cb
commit ae975a354e
6 changed files with 68 additions and 32 deletions

View File

@ -199,7 +199,7 @@ void SysMessage(char *fmt, ...)
MsgDlg = gtk_window_new(GTK_WINDOW_TOPLEVEL); MsgDlg = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER); gtk_window_set_position(GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(MsgDlg), "GSsoft Msg"); gtk_window_set_title(GTK_WINDOW(MsgDlg), "ZeroPad");
gtk_container_set_border_width(GTK_CONTAINER(MsgDlg), 5); gtk_container_set_border_width(GTK_CONTAINER(MsgDlg), 5);
Box = gtk_vbox_new(5, 0); Box = gtk_vbox_new(5, 0);

View File

@ -101,7 +101,7 @@ bool JoystickInfo::Init(int id, bool bStartThread)
joy = SDL_JoystickOpen(id); joy = SDL_JoystickOpen(id);
if (joy == NULL) if (joy == NULL)
{ {
printf("failed to open joystick %d\n", id); PAD_LOG("failed to open joystick %d\n", id);
return false; return false;
} }
@ -109,9 +109,12 @@ bool JoystickInfo::Init(int id, bool bStartThread)
numbuttons = SDL_JoystickNumButtons(joy); numbuttons = SDL_JoystickNumButtons(joy);
numpov = SDL_JoystickNumHats(joy); numpov = SDL_JoystickNumHats(joy);
devname = SDL_JoystickName(id); devname = SDL_JoystickName(id);
vaxisstate.resize(numaxes);
vbutstate.resize(numbuttons); vbutstate.resize(numbuttons);
vaxisstate.resize(numbuttons); vpovstate.resize(numpov);
//PAD_LOG("There are %d buttons, %d axises, and %d povs.\n", numbuttons, numaxes, numpov);
return true; return true;
} }
@ -140,11 +143,11 @@ void JoystickInfo::Assign(int newpad)
void JoystickInfo::SaveState() void JoystickInfo::SaveState()
{ {
for (int i = 0; i < numbuttons; ++i) for (int i = 0; i < numbuttons; ++i)
vbutstate[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)
vaxisstate[i] = SDL_JoystickGetAxis(joy, i); SetAxisState(i, SDL_JoystickGetAxis(joy, i));
/*for (int i = 0; i < numpov; ++i) for (int i = 0; i < numpov; ++i)
vpovstate[i] = SDL_JoystickGetHat(joy, i);*/ SetPOVState(i, SDL_JoystickGetHat(joy, i));
} }
void JoystickInfo::TestForce() void JoystickInfo::TestForce()

View File

@ -87,7 +87,7 @@ class JoystickInfo
int GetPOVState(int i) int GetPOVState(int i)
{ {
//printf("Getting POV State of %d.\n", i); //PAD_LOG("Getting POV State of %d.\n", i);
return vpovstate[i]; return vpovstate[i];
} }
@ -103,7 +103,7 @@ class JoystickInfo
void SetPOVState(int i, int value) void SetPOVState(int i, int value)
{ {
//printf("We should set %d to %d.\n", i, value); //PAD_LOG("We should set %d to %d.\n", i, value);
vpovstate[i] = value; vpovstate[i] = value;
} }

View File

@ -266,6 +266,7 @@ void CALLBACK PADupdate(int pad)
status[pad] |= (1 << i); status[pad] |= (1 << i);
} }
} }
// Need to add in new POV code here, to match the new configuration pov code.
} }
#endif #endif
@ -279,6 +280,7 @@ void CALLBACK PADupdate(int pad)
void UpdateConf(int pad) void UpdateConf(int pad)
{ {
initLogging();
s_selectedpad = pad; s_selectedpad = pad;
int i; int i;
@ -292,7 +294,7 @@ void UpdateConf(int pad)
Btn = lookup_widget(Conf, GetLabelFromButton(s_pGuiKeyMap[i]).c_str()); Btn = lookup_widget(Conf, GetLabelFromButton(s_pGuiKeyMap[i]).c_str());
if (Btn == NULL) if (Btn == NULL)
{ {
printf("ZeroPAD: cannot find key %s\n", s_pGuiKeyMap[i]); PAD_LOG("ZeroPAD: cannot find key %s\n", s_pGuiKeyMap[i]);
continue; continue;
} }
@ -359,7 +361,7 @@ void OnConf_Key(GtkButton *button, gpointer user_data)
GtkWidget* label = lookup_widget(Conf, GetLabelFromButton(gtk_button_get_label(button)).c_str()); GtkWidget* label = lookup_widget(Conf, GetLabelFromButton(gtk_button_get_label(button)).c_str());
if (label == NULL) if (label == NULL)
{ {
printf("couldn't find correct label\n"); PAD_LOG("couldn't find correct label\n");
return; return;
} }
@ -433,16 +435,15 @@ void OnConf_Key(GtkButton *button, gpointer user_data)
if (value != (*itjoy)->GetAxisState(i)) if (value != (*itjoy)->GetAxisState(i))
{ {
PAD_LOG("Change in joystick %d: %d.\n", i, value);
if (abs(value) <= (*itjoy)->GetAxisState(i)) // we don't want this if (abs(value) <= (*itjoy)->GetAxisState(i)) // we don't want this
{ {
// released, we don't really want this // released, we don't really want this
// SetButtonState? Shouldn't this be SetAxisState? (*itjoy)->SetAxisState(i, value);
(*itjoy)->SetButtonState(i, value);
break; break;
} }
if (abs(value) > 0x3fff) if (abs(value) > 0x3fff)
{ {
if (key < 16) // POV if (key < 16) // POV
@ -465,33 +466,44 @@ void OnConf_Key(GtkButton *button, gpointer user_data)
} }
} }
/*for (int i = 0; i < (*itjoy)->GetNumPOV(); ++i) #ifdef EXPERAMENTAL_POV_CODE
for (int i = 0; i < (*itjoy)->GetNumPOV(); ++i)
{ {
int value = SDL_JoystickGetHat((*itjoy)->GetJoy(), i); int value = SDL_JoystickGetHat((*itjoy)->GetJoy(), i);
if (value != (*itjoy)->GetPOVState(i)) if (value != (*itjoy)->GetPOVState(i))
{ {
if (abs(value) > 0x3fff) switch (value)
{ {
if (key < 16) // POV char str[32];
{
case SDL_HAT_UP:
*pkey = PAD_POV((*itjoy)->GetId(), value < 0, i); *pkey = PAD_POV((*itjoy)->GetId(), value < 0, i);
char str[32]; sprintf(str, "JPOV%d%s", i, "U");
sprintf(str, "JPOV %d%s", i, value < 0 ? "-" : "+");
gtk_entry_set_text(GTK_ENTRY(label), str); gtk_entry_set_text(GTK_ENTRY(label), str);
return; return;
} case SDL_HAT_RIGHT:
else // axis *pkey = PAD_POV((*itjoy)->GetId(), value < 0, i);
{ sprintf(str, "JPOV%d%s", i, "R");
*pkey = PAD_JOYSTICK((*itjoy)->GetId(), i);
char str[32];
sprintf(str, "JAxis %d", i);
gtk_entry_set_text(GTK_ENTRY(label), str); gtk_entry_set_text(GTK_ENTRY(label), str);
return; return;
} case SDL_HAT_DOWN:
*pkey = PAD_POV((*itjoy)->GetId(), value < 0, i);
sprintf(str, "JPOV%d%s", i, "D");
gtk_entry_set_text(GTK_ENTRY(label), str);
return;
case SDL_HAT_LEFT:
*pkey = PAD_POV((*itjoy)->GetId(), value < 0, i);
sprintf(str, "JPOV%d%s", i, "L");
gtk_entry_set_text(GTK_ENTRY(label), str);
return;
// Not handling SDL_HAT_RIGHTUP, SDL_HAT_RIGHTDOWN,
// SDL_HAT_LEFTUP, or SDL_HAT_LEFTDOWN here. They should be
// handled in the PADUpdate code, though.
} }
} }
}*/ }
#endif
itjoy++; itjoy++;
} }
#endif #endif

View File

@ -251,18 +251,31 @@ u32 CALLBACK PS2EgetLibVersion2(u32 type)
return (version << 16) | (revision << 8) | build; return (version << 16) | (revision << 8) | build;
} }
void __Log(char *fmt, ...) void __Log(const char *fmt, ...)
{ {
va_list list; va_list list;
if (!conf.log || padLog == NULL) return; //if (padLog == NULL || !conf.log) return;
if (padLog == NULL) return;
va_start(list, fmt); va_start(list, fmt);
vfprintf(padLog, fmt, list); vfprintf(padLog, fmt, list);
va_end(list); va_end(list);
} }
void __LogToConsole(const char *fmt, ...)
{
va_list list;
s32 CALLBACK PADinit(u32 flags) va_start(list, fmt);
if (padLog != NULL) vfprintf(padLog, fmt, list);
printf("ZeroPad: ");
vprintf(fmt, list);
va_end(list);
}
void initLogging()
{ {
#ifdef PAD_LOG #ifdef PAD_LOG
if (padLog == NULL) if (padLog == NULL)
@ -272,6 +285,11 @@ s32 CALLBACK PADinit(u32 flags)
} }
PAD_LOG("PADinit\n"); PAD_LOG("PADinit\n");
#endif #endif
}
s32 CALLBACK PADinit(u32 flags)
{
initLogging();
pads |= flags; pads |= flags;
status[0] = 0xffff; status[0] = 0xffff;

View File

@ -96,7 +96,9 @@ typedef struct
extern PADconf conf; extern PADconf conf;
extern PADAnalog g_lanalog[2], g_ranalog[2]; extern PADAnalog g_lanalog[2], g_ranalog[2];
extern FILE *padLog; extern FILE *padLog;
extern void initLogging();
#define PAD_LOG __Log #define PAD_LOG __Log
//#define PAD_LOG __LogToConsole
enum PadCommands enum PadCommands
{ {
@ -171,7 +173,8 @@ void _KeyRelease(int pad, u32 key);
void PADsetMode(int pad, int mode); void PADsetMode(int pad, int mode);
void _PADupdate(int pad); void _PADupdate(int pad);
void __Log(char *fmt, ...); void __Log(const char *fmt, ...);
void __LogToConsole(const char *fmt, ...);
void LoadConfig(); void LoadConfig();
void SaveConfig(); void SaveConfig();