Esempio n. 1
0
bool JoystickInfo::PollButtons(u32 &pkey)
{
    // MAKE sure to look for changes in the state!!
    for (int i = 0; i < GetNumButtons(); ++i)
    {
        int but = SDL_JoystickGetButton(GetJoy(), 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 :)
            // Trick: detect the release of the button. It avoid all races condition between axes and buttons :)
            // If the button support pressure it will be detected as an axis when it is pressed.
            if (but) {
                SetButtonState(i, but);
                return false;
            }


            pkey = button_to_key(i);
            return true;
        }
    }

    return false;
}
Esempio n. 2
0
bool JoystickInfo::PollButtons(u32 &pkey)
{
	// MAKE sure to look for changes in the state!!
	for (int i = 0; i < GetNumButtons(); ++i)
	{
		int but = SDL_JoystickGetButton(GetJoy(), i);

		if (but != GetButtonState(i))
		{
			if (!but)    // released, we don't really want this
			{
				continue;
			}

			// 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 :) -- Gregory
			u32 pkey_dummy;
			if (PollAxes(pkey_dummy))
				return false;

			pkey = button_to_key(i);
			return true;
		}
	}

	return false;
}
Esempio n. 3
0
bool JoystickInfo::PollAxes(u32 &pkey)
{
    for (int i = 0; i < GetNumAxes(); ++i)
    {
        // Sixaxis, dualshock3 hack
        u32 found_hack = devname.find(string("PLAYSTATION(R)3"));
        if (found_hack != string::npos) {
            // 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
            if (i >= 8 && i <= 11 && (conf->pad_options[pad].sixaxis_usb))
                continue;
            // Disable accelerometer
            if ((i >= 4 && i <= 6))
                continue;
        }

        s32 value = SDL_JoystickGetAxis(GetJoy(), i);
        s32 old_value = GetAxisState(i);

        if (abs(value - old_value) < 0x1000)
            continue;

        if (value != old_value)
        {
            PAD_LOG("Change in joystick %d: %d.\n", i, value);
            // There are several kinds of axes
            // Half+: 0 (release) -> 32768
            // Half-: 0 (release) -> -32768
            // Full (like dualshock 3): -32768 (release) ->32768
            const s32 full_axis_ceil = -0x6FFF;
            const s32 half_axis_ceil = 0x1FFF;

            // 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;

            if ((!is_full_axis && abs(value) <= half_axis_ceil)
                    || (is_full_axis && value <= full_axis_ceil))  // we don't want this
            {
                continue;
            }

            if ((!is_full_axis && abs(value) > half_axis_ceil)
                    || (is_full_axis && value > full_axis_ceil))
            {
                bool sign = (value < 0);
                pkey = axis_to_key(is_full_axis, sign, i);

                return true;
            }
        }
    }

    return false;
}
Esempio n. 4
0
bool JoystickInfo::PollHats(u32 &pkey)
{
    for (int i = 0; i < GetNumHats(); ++i)
    {
        int value = SDL_JoystickGetHat(GetJoy(), i);

        if ((value != GetHatState(i)) && (value != SDL_HAT_CENTERED))
        {
            switch (value)
            {
            case SDL_HAT_UP:
            case SDL_HAT_RIGHT:
            case SDL_HAT_DOWN:
            case SDL_HAT_LEFT:
                pkey = hat_to_key(value, i);
                PAD_LOG("Hat Pressed!");
                return true;
            default:
                break;
            }
        }
    }
    return false;
}
Esempio n. 5
0
int JoystickInfo::GetAxisFromKey(int pad, int index)
{
    return SDL_JoystickGetAxis(GetJoy(), key_to_axis(pad, index));
}
Esempio n. 6
0
int JoystickInfo::GetButton(int key_to_button)
{
    return SDL_JoystickGetButton(GetJoy(),key_to_button);
}
Esempio n. 7
0
int JoystickInfo::GetHat(int key_to_axis)
{
    return SDL_JoystickGetHat(GetJoy(),key_to_axis);
}
Esempio n. 8
0
u32 systemReadJoypad(int which)
{
	if(which == -1) which = 0; // default joypad
	return GetJoy(which);
}
Esempio n. 9
0
// main interface to FCE Ultra
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int32 Count)
{
    PlaySound(Buffer, Count); // play sound
    RenderFrame(XBuf); // output video frame
    GetJoy(); // check controller input
}