Holy Crap Batman! nJoy Testing changes. Anyway, this makes axises actually work for buttons. It needs cleaned up still. Buttons dont work as axises yet, will work on that later.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1477 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Sonicadvance1 2008-12-10 03:49:17 +00:00
parent 4f40c79345
commit 2cbef47d0e
3 changed files with 152 additions and 51 deletions

View File

@ -392,10 +392,10 @@ void ConfigBox::SetControllerAll(int controller)
} }
else else
{ {
tmp << joysticks[controller].dpad2[CTL_D_PAD_UP]; m_JoyDpadUp[controller]->SetValue(tmp); tmp.clear(); m_JoyDpadUp[controller]->SetValue(wxString::FromAscii(joysticks[controller].buttons[CTL_D_PAD_UP].c_str()));
tmp << joysticks[controller].dpad2[CTL_D_PAD_DOWN]; m_JoyDpadDown[controller]->SetValue(tmp); tmp.clear(); m_JoyDpadDown[controller]->SetValue(wxString::FromAscii(joysticks[controller].buttons[CTL_D_PAD_DOWN].c_str()));
tmp << joysticks[controller].dpad2[CTL_D_PAD_LEFT]; m_JoyDpadLeft[controller]->SetValue(tmp); tmp.clear(); m_JoyDpadLeft[controller]->SetValue(wxString::FromAscii(joysticks[controller].buttons[CTL_D_PAD_LEFT].c_str()));
tmp << joysticks[controller].dpad2[CTL_D_PAD_RIGHT]; m_JoyDpadRight[controller]->SetValue(tmp); tmp.clear(); m_JoyDpadRight[controller]->SetValue(wxString::FromAscii(joysticks[controller].buttons[CTL_D_PAD_RIGHT].c_str()));
} }
} }
@ -426,10 +426,10 @@ void ConfigBox::GetControllerAll(int controller)
} }
else else
{ {
m_JoyDpadUp[controller]->GetValue().ToLong(&lvalue); joysticks[controller].dpad2[CTL_D_PAD_UP] = lvalue; tmp.clear(); joysticks[controller].buttons[CTL_D_PAD_UP] = std::string(m_JoyDpadUp[controller]->GetValue().mb_str());
m_JoyDpadDown[controller]->GetValue().ToLong(&lvalue); joysticks[controller].dpad2[CTL_D_PAD_DOWN] = lvalue; tmp.clear(); joysticks[controller].buttons[CTL_D_PAD_DOWN] = std::string(m_JoyDpadDown[controller]->GetValue().mb_str());
m_JoyDpadLeft[controller]->GetValue().ToLong(&lvalue); joysticks[controller].dpad2[CTL_D_PAD_LEFT] = lvalue; tmp.clear(); joysticks[controller].buttons[CTL_D_PAD_LEFT] = std::string(m_JoyDpadLeft[controller]->GetValue().mb_str());
m_JoyDpadRight[controller]->GetValue().ToLong(&lvalue); joysticks[controller].dpad2[CTL_D_PAD_RIGHT] = lvalue; tmp.clear(); joysticks[controller].buttons[CTL_D_PAD_RIGHT] = std::string(m_JoyDpadRight[controller]->GetValue().mb_str());
} }
joysticks[controller].buttons[CTL_MAIN_X] = std::string(m_JoyAnalogMainX[controller]->GetValue().mb_str()); tmp.clear(); joysticks[controller].buttons[CTL_MAIN_X] = std::string(m_JoyAnalogMainX[controller]->GetValue().mb_str()); tmp.clear();
@ -662,10 +662,15 @@ void ConfigBox::GetInputs(wxCommandEvent& event)
for(int b = 0; b < axes; b++) for(int b = 0; b < axes; b++)
{ {
value = SDL_JoystickGetAxis(joy, b); value = SDL_JoystickGetAxis(joy, b);
if(value <= (joysticks[controller].sData[b].Min - (joysticks[controller].sData[b].Min * joysticks[controller].deadzone / 100)) || value >= (joysticks[controller].sData[b].Max - (joysticks[controller].sData[b].Max * joysticks[controller].deadzone / 100))) // Add and subtract a small value if(joysticks[controller].sData[b].Min == 0)
if(value == 0)
continue; // Do nothing
if(
(value <= (joysticks[controller].sData[b].Min - joysticks[controller].sData[b].Min * joysticks[controller].deadzone/100.0f) ) ||
(value >= (joysticks[controller].sData[b].Max - joysticks[controller].sData[b].Max * joysticks[controller].deadzone/100.0f) )) // Add and subtract a small value
{ // It allows for some small jitter { // It allows for some small jitter
printf("value %d, Min %d Max %d Removal %d\n", value, joysticks[controller].sData[b].Min,joysticks[controller].sData[b].Max, (joysticks[controller].sData[b].Min * joysticks[controller].deadzone / 100)); printf("value %d, Min %d Max %d Removal %f %f\n", value, joysticks[controller].sData[b].Min,joysticks[controller].sData[b].Max, joysticks[controller].sData[b].Min * joysticks[controller].deadzone/100.0f, joysticks[controller].sData[b].Max * joysticks[controller].deadzone/100.0f);
value = value <= (joysticks[controller].sData[b].Min - joysticks[controller].sData[b].Min * joysticks[controller].deadzone) ? -1 : 1; // Makes it know if the value is negative or positive value = value < 0 ? -1 : 1; // Makes it know if the value is negative or positive
pressed = b; pressed = b;
waiting = false; waiting = false;
succeed = true; succeed = true;

View File

@ -278,10 +278,29 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
// Adjust range // Adjust range
// The value returned by SDL_JoystickGetAxis is a signed integer (-32768 to 32768) // The value returned by SDL_JoystickGetAxis is a signed integer (-32768 to 32768)
// The value used for the gamecube controller is an unsigned char (0 to 255) // The value used for the gamecube controller is an unsigned char (0 to 255)
int main_stick_x = (joystate[_numPAD].buttons[CTL_MAIN_X]>>8); int main_stick_x, main_stick_y, sub_stick_x, sub_stick_y;
int main_stick_y = -(joystate[_numPAD].buttons[CTL_MAIN_Y]>>8); if(joysticks[_numPAD].buttons[CTL_MAIN_X].c_str()[0] == 'A') // Axis
int sub_stick_x = (joystate[_numPAD].buttons[CTL_SUB_X]>>8); {
int sub_stick_y = -(joystate[_numPAD].buttons[CTL_SUB_Y]>>8); main_stick_x = (joystate[_numPAD].buttons[CTL_MAIN_X]>>8);
main_stick_y = -(joystate[_numPAD].buttons[CTL_MAIN_Y]>>8);
sub_stick_x = (joystate[_numPAD].buttons[CTL_SUB_X]>>8);
sub_stick_y = -(joystate[_numPAD].buttons[CTL_SUB_Y]>>8);
}
else if(joysticks[_numPAD].buttons[CTL_MAIN_X].c_str()[0] == 'B') // Button
{
PanicAlert("Buttons as Joysticks don't work yet!");
}
else if(joysticks[_numPAD].buttons[CTL_MAIN_X].c_str()[0] == 'H') // Hat
{
PanicAlert("Hats as Joysticks don't work yet!\n");
}
else if(joysticks[_numPAD].buttons[CTL_MAIN_X].c_str()[0] == 'N') // None
{}
else // Wtf?
{
//Do a panicAlert here?
}
// Quick fix // Quick fix
if(main_stick_x > 127) if(main_stick_x > 127)
@ -311,9 +330,104 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
int triggervalue = 255; int triggervalue = 255;
if (joystate[_numPAD].halfpress) if (joystate[_numPAD].halfpress)
triggervalue = 100; triggervalue = 100;
int ButtonArray[] = {PAD_TRIGGER_L, PAD_TRIGGER_R, PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y, PAD_TRIGGER_Z, PAD_BUTTON_START, PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT};
for(int a = 0;a <= CTL_D_PAD_RIGHT;a++)
{
switch(joysticks[_numPAD].buttons[a].c_str()[0])
{
case 'A':
{
// JoyNum refers to which Joystick the button is assigned to
// a is the actual button we are working with
// _numPad is the controller we are working with
int JoyNum = atoi(joysticks[_numPAD].buttons[a].c_str() + 2);
if(joysticks[_numPAD].sData[JoyNum].Min == 0)
if(joystate[_numPAD].buttons[a] == 0)
continue; // Do nothing
// We use Deadzone % to detect if we have pressed the button.
bool Pressed = false;
if(a == CTL_L_SHOULDER || a == CTL_R_SHOULDER || a == CTL_A_BUTTON || a == CTL_B_BUTTON)
Pressed = true;
else
{
if(joysticks[_numPAD].buttons[a].c_str()[1] == '-')
{
if(joystate[_numPAD].buttons[a] <= (joysticks[_numPAD].sData[JoyNum].Min - joysticks[_numPAD].sData[JoyNum].Min * joysticks[_numPAD].deadzone/100.0f))
{
Pressed = true;
}
}
if(joysticks[_numPAD].buttons[a].c_str()[1] == '+')
{
if(joystate[_numPAD].buttons[a] >= (joysticks[_numPAD].sData[JoyNum].Max - joysticks[_numPAD].sData[JoyNum].Max * joysticks[_numPAD].deadzone/100.0f))
{
Pressed = true;
}
}
}
if(Pressed == true)
{
int TriggerValue = 0;
if(joysticks[_numPAD].buttons[a].c_str()[1] == '+')
{
if(joystate[_numPAD].buttons[a] >= 0)
TriggerValue = (255.0f / joysticks[_numPAD].sData[JoyNum].Max) * joystate[_numPAD].buttons[a];
}
if(joysticks[_numPAD].buttons[a].c_str()[1] == '-')
{
if(joystate[_numPAD].buttons[a] <= 0)
TriggerValue = abs((255.0f / joysticks[_numPAD].sData[JoyNum].Min) * joystate[_numPAD].buttons[a]);
}
if(a == CTL_L_SHOULDER)
{
if(TriggerValue == 255)
_pPADStatus->button |= ButtonArray[a];
_pPADStatus->triggerLeft = TriggerValue;
}
else if(a == CTL_R_SHOULDER)
{
if(TriggerValue == 255)
_pPADStatus->button |= ButtonArray[a];
_pPADStatus->triggerRight = TriggerValue;
}
// TODO: Should we do the same for A and B as the L and R trigger?
else if(a == CTL_A_BUTTON)
{
_pPADStatus->button |= ButtonArray[a];
_pPADStatus->analogA = TriggerValue;
}
else if(a == CTL_B_BUTTON)
{
_pPADStatus->button |= ButtonArray[a];
_pPADStatus->analogB = TriggerValue;
}
else
_pPADStatus->button |= ButtonArray[a];
}
}
break;
case 'B':
if(joystate[_numPAD].buttons[a])
{
_pPADStatus->button |= ButtonArray[a];
if(a == CTL_L_SHOULDER)
_pPADStatus->triggerLeft = 255; //TODO: Do half press with these
else if(a == CTL_R_SHOULDER)
_pPADStatus->triggerRight = 255; //TODO: Half Press with these
else if(a == CTL_A_BUTTON)
_pPADStatus->analogA = 255;
else if(a == CTL_B_BUTTON)
_pPADStatus->analogB = 255;
}
case 'H':
//PanicAlert("Hats are currently not implemented!");
default:
break;
}
}
// Set buttons // Set buttons
if (joystate[_numPAD].buttons[CTL_L_SHOULDER]) /*if (joystate[_numPAD].buttons[CTL_L_SHOULDER])
{ {
_pPADStatus->button|=PAD_TRIGGER_L; _pPADStatus->button|=PAD_TRIGGER_L;
_pPADStatus->triggerLeft = triggervalue; _pPADStatus->triggerLeft = triggervalue;
@ -337,9 +451,10 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
if (joystate[_numPAD].buttons[CTL_X_BUTTON]) _pPADStatus->button|=PAD_BUTTON_X; if (joystate[_numPAD].buttons[CTL_X_BUTTON]) _pPADStatus->button|=PAD_BUTTON_X;
if (joystate[_numPAD].buttons[CTL_Y_BUTTON]) _pPADStatus->button|=PAD_BUTTON_Y; if (joystate[_numPAD].buttons[CTL_Y_BUTTON]) _pPADStatus->button|=PAD_BUTTON_Y;
if (joystate[_numPAD].buttons[CTL_Z_TRIGGER]) _pPADStatus->button|=PAD_TRIGGER_Z; if (joystate[_numPAD].buttons[CTL_Z_TRIGGER]) _pPADStatus->button|=PAD_TRIGGER_Z;
if (joystate[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START; if (joystate[_numPAD].buttons[CTL_START]) _pPADStatus->button|=PAD_BUTTON_START;*/
// Set D-pad // Set D-pad
// TODO: Currently disabled! D:>
if(joysticks[_numPAD].controllertype == CTL_TYPE_JOYSTICK) if(joysticks[_numPAD].controllertype == CTL_TYPE_JOYSTICK)
{ {
if(joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_UP || joystate[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP; if(joystate[_numPAD].dpad == SDL_HAT_LEFTUP || joystate[_numPAD].dpad == SDL_HAT_UP || joystate[_numPAD].dpad == SDL_HAT_RIGHTUP ) _pPADStatus->button|=PAD_BUTTON_UP;
@ -349,14 +464,6 @@ void PAD_GetStatus(u8 _numPAD, SPADStatus* _pPADStatus)
} }
else else
{ {
if(joystate[_numPAD].dpad2[CTL_D_PAD_UP])
_pPADStatus->button|=PAD_BUTTON_UP;
if(joystate[_numPAD].dpad2[CTL_D_PAD_DOWN])
_pPADStatus->button|=PAD_BUTTON_DOWN;
if(joystate[_numPAD].dpad2[CTL_D_PAD_LEFT])
_pPADStatus->button|=PAD_BUTTON_LEFT;
if(joystate[_numPAD].dpad2[CTL_D_PAD_RIGHT])
_pPADStatus->button|=PAD_BUTTON_RIGHT;
} }
_pPADStatus->err = PAD_ERR_NONE; _pPADStatus->err = PAD_ERR_NONE;
@ -546,10 +653,6 @@ void GetJoyState(int controller)
joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, joysticks[controller].dpad); joystate[controller].dpad = SDL_JoystickGetHat(joystate[controller].joy, joysticks[controller].dpad);
else else
{ {
joystate[controller].dpad2[CTL_D_PAD_UP] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_UP]);
joystate[controller].dpad2[CTL_D_PAD_DOWN] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_DOWN]);
joystate[controller].dpad2[CTL_D_PAD_LEFT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_LEFT]);
joystate[controller].dpad2[CTL_D_PAD_RIGHT] = SDL_JoystickGetButton(joystate[controller].joy, joysticks[controller].dpad2[CTL_D_PAD_RIGHT]);
} }
} }
@ -674,10 +777,10 @@ void SaveConfig()
file.Set(SectionName, "z_trigger", joysticks[i].buttons[CTL_Z_TRIGGER]); file.Set(SectionName, "z_trigger", joysticks[i].buttons[CTL_Z_TRIGGER]);
file.Set(SectionName, "start_button", joysticks[i].buttons[CTL_START]); file.Set(SectionName, "start_button", joysticks[i].buttons[CTL_START]);
file.Set(SectionName, "dpad", joysticks[i].dpad); file.Set(SectionName, "dpad", joysticks[i].dpad);
file.Set(SectionName, "dpad_up", joysticks[i].dpad2[CTL_D_PAD_UP]); file.Set(SectionName, "dpad_up", joysticks[i].buttons[CTL_D_PAD_UP]);
file.Set(SectionName, "dpad_down", joysticks[i].dpad2[CTL_D_PAD_DOWN]); file.Set(SectionName, "dpad_down", joysticks[i].buttons[CTL_D_PAD_DOWN]);
file.Set(SectionName, "dpad_left", joysticks[i].dpad2[CTL_D_PAD_LEFT]); file.Set(SectionName, "dpad_left", joysticks[i].buttons[CTL_D_PAD_LEFT]);
file.Set(SectionName, "dpad_right", joysticks[i].dpad2[CTL_D_PAD_RIGHT]); file.Set(SectionName, "dpad_right", joysticks[i].buttons[CTL_D_PAD_RIGHT]);
file.Set(SectionName, "main_x", joysticks[i].buttons[CTL_MAIN_X]); file.Set(SectionName, "main_x", joysticks[i].buttons[CTL_MAIN_X]);
file.Set(SectionName, "main_y", joysticks[i].buttons[CTL_MAIN_Y]); file.Set(SectionName, "main_y", joysticks[i].buttons[CTL_MAIN_Y]);
file.Set(SectionName, "sub_x", joysticks[i].buttons[CTL_SUB_X]); file.Set(SectionName, "sub_x", joysticks[i].buttons[CTL_SUB_X]);
@ -722,10 +825,10 @@ void LoadConfig()
file.Get(SectionName, "z_trigger", &joysticks[i].buttons[CTL_Z_TRIGGER], "B7"); file.Get(SectionName, "z_trigger", &joysticks[i].buttons[CTL_Z_TRIGGER], "B7");
file.Get(SectionName, "start_button", &joysticks[i].buttons[CTL_START], "B9"); file.Get(SectionName, "start_button", &joysticks[i].buttons[CTL_START], "B9");
file.Get(SectionName, "dpad", &joysticks[i].dpad, 0); file.Get(SectionName, "dpad", &joysticks[i].dpad, 0);
file.Get(SectionName, "dpad_up", &joysticks[i].dpad2[CTL_D_PAD_UP], 0); file.Get(SectionName, "dpad_up", &joysticks[i].buttons[CTL_D_PAD_UP], 0);
file.Get(SectionName, "dpad_down", &joysticks[i].dpad2[CTL_D_PAD_DOWN], 0); file.Get(SectionName, "dpad_down", &joysticks[i].buttons[CTL_D_PAD_DOWN], 0);
file.Get(SectionName, "dpad_left", &joysticks[i].dpad2[CTL_D_PAD_LEFT], 0); file.Get(SectionName, "dpad_left", &joysticks[i].buttons[CTL_D_PAD_LEFT], 0);
file.Get(SectionName, "dpad_right", &joysticks[i].dpad2[CTL_D_PAD_RIGHT], 0); file.Get(SectionName, "dpad_right", &joysticks[i].buttons[CTL_D_PAD_RIGHT], 0);
file.Get(SectionName, "main_x", &joysticks[i].buttons[CTL_MAIN_X], "A0"); file.Get(SectionName, "main_x", &joysticks[i].buttons[CTL_MAIN_X], "A0");
file.Get(SectionName, "main_y", &joysticks[i].buttons[CTL_MAIN_Y], "A1"); file.Get(SectionName, "main_y", &joysticks[i].buttons[CTL_MAIN_Y], "A1");
file.Get(SectionName, "sub_x", &joysticks[i].buttons[CTL_SUB_X], "A2"); file.Get(SectionName, "sub_x", &joysticks[i].buttons[CTL_SUB_X], "A2");

View File

@ -107,18 +107,16 @@ class sCalibration
Sint16 Max; Sint16 Max;
}; // Simple Calibration Data }; // Simple Calibration Data
struct CONTROLLER_STATE{ // GC PAD INFO/STATE struct CONTROLLER_STATE{ // GC PAD INFO/STATE
int buttons[12]; // Amount of buttons (A B X Y Z, L-Trigger R-Trigger Start) might need to change the triggers buttons int buttons[16]; // Amount of buttons (A B X Y Z, L-Trigger R-Trigger Start) might need to change the triggers buttons
int dpad; // 1 HAT (8 directions + neutral) int dpad; // 1 HAT (8 directions + neutral)
int dpad2[4]; // d-pad using buttons
int halfpress; // ... int halfpress; // ...
SDL_Joystick *joy; // SDL joystick device SDL_Joystick *joy; // SDL joystick device
}; };
struct CONTROLLER_MAPPING{ // GC PAD MAPPING struct CONTROLLER_MAPPING{ // GC PAD MAPPING
std::string buttons[12];// Amount of buttons (A B X Y Z, L-Trigger R-Trigger Start) might need to change the triggers buttons std::string buttons[16];// Amount of buttons (A B X Y Z, L-Trigger R-Trigger Start) might need to change the triggers buttons
sCalibration sData[MAX_AXISES]; // Calibration Data sCalibration sData[MAX_AXISES]; // Calibration Data
int dpad; // 1 HAT (8 directions + neutral) int dpad; // 1 HAT (8 directions + neutral)
int dpad2[4]; // d-pad using buttons
int enabled; // Pad attached? int enabled; // Pad attached?
int deadzone; // Deadzone... what else? int deadzone; // Deadzone... what else?
int halfpress; // Halfpress... you know, like not fully pressed ;)... int halfpress; // Halfpress... you know, like not fully pressed ;)...
@ -147,6 +145,10 @@ enum
CTL_Y_BUTTON, CTL_Y_BUTTON,
CTL_Z_TRIGGER, CTL_Z_TRIGGER,
CTL_START, CTL_START,
CTL_D_PAD_UP,
CTL_D_PAD_DOWN,
CTL_D_PAD_LEFT,
CTL_D_PAD_RIGHT,
CTL_MAIN_X, CTL_MAIN_X,
CTL_MAIN_Y, CTL_MAIN_Y,
CTL_SUB_X, CTL_SUB_X,
@ -161,15 +163,6 @@ enum
CTL_TYPE_JOYSTICK_XBOX360, CTL_TYPE_JOYSTICK_XBOX360,
CTL_TYPE_KEYBOARD CTL_TYPE_KEYBOARD
}; };
enum
{
CTL_D_PAD_UP = 0,
CTL_D_PAD_DOWN,
CTL_D_PAD_LEFT,
CTL_D_PAD_RIGHT
};
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
// Custom Functions // Custom Functions
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ // ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯