示例#1
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;
}
示例#2
0
void Dialog::JoystickEvent(wxTimerEvent &event)
{
#ifdef SDL_BUILD
    u32 key;
    int map;
    std::map<u32, int>::iterator it;
    std::map<u32, int>::iterator it2;
    SDL_JoystickEventState(SDL_ENABLE);
    SDL_Event events;
    while (SDL_PollEvent(&events)) {
        switch (events.type) {
            case SDL_KEYDOWN:
            case SDL_KEYUP:
                break;
            case SDL_JOYAXISMOTION:
                if (events.jaxis.which < GAMEPAD_NUMBER) {
                    key = axis_to_key(false, (events.jaxis.value < 0), events.jaxis.axis);
                    it = m_map_images[events.jaxis.which].find(key);
                    if (it != m_map_images[events.jaxis.which].end()) {
                        map = m_map_images[events.jaxis.which][key];
                        if (events.jaxis.value == 0) {
                            if (map >= PAD_L_UP && map <= PAD_L_LEFT)
                                m_pan_tabs[events.jaxis.which]->HideImg(img_left_cursor);
                            else if (map >= PAD_R_UP && map <= PAD_R_LEFT)
                                m_pan_tabs[events.jaxis.which]->HideImg(img_right_cursor);
                            else if (map < PAD_L_UP)
                                m_pan_tabs[events.jaxis.which]->HideImg(map);
                        } else {
                            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]->ShowImg(img_left_cursor);
                            } 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]->ShowImg(img_right_cursor);
                            } else if (map < PAD_L_UP) { // if this is not a joystick
                                m_pan_tabs[events.jaxis.which]->ShowImg(map);
                            }
                        }
                        break;
                    }
                    // Hack Dualshock 4 (L2, R2)
                    key = axis_to_key(false, (events.jaxis.value > 0), events.jaxis.axis);
                    it2 = m_map_images[events.jaxis.which].find(key);
                    if (it2 != m_map_images[events.jaxis.which].end()) {
                        map = m_map_images[events.jaxis.which][key];
                        if (map < PAD_L_UP) { // if this is not a joystick
                            m_pan_tabs[events.jaxis.which]->HideImg(map);
                        }
                        break;
                    }
                }
                break;
            case SDL_JOYBUTTONDOWN:
                if (events.jbutton.which < GAMEPAD_NUMBER) {
                    key = button_to_key(events.jbutton.button);
                    it = m_map_images[events.jbutton.which].find(key);
                    if (it != m_map_images[events.jbutton.which].end()) {
                        map = m_map_images[events.jbutton.which][key];
                        m_pan_tabs[events.jbutton.which]->ShowImg(map);
                    }
                }
                break;
            case SDL_JOYBUTTONUP:
                if (events.jbutton.which < GAMEPAD_NUMBER) {
                    key = button_to_key(events.jbutton.button);
                    it = m_map_images[events.jbutton.which].find(key);
                    if (it != m_map_images[events.jbutton.which].end()) {
                        map = m_map_images[events.jbutton.which][key];
                        m_pan_tabs[events.jbutton.which]->HideImg(map);
                    }
                }
                break;
            case SDL_JOYHATMOTION:
                if (events.jhat.which < GAMEPAD_NUMBER) {
                    switch (events.jhat.value) {
                        case SDL_HAT_UP:
                            key = hat_to_key(events.jhat.value, events.jhat.hat);
                            it = m_map_images[events.jhat.which].find(key);
                            if (it != m_map_images[events.jhat.which].end()) {
                                m_pan_tabs[events.jhat.which]->ShowImg(img_dp_up);
                            }
                            break;
                        case SDL_HAT_DOWN:
                            key = hat_to_key(events.jhat.value, events.jhat.hat);
                            it = m_map_images[events.jhat.which].find(key);
                            if (it != m_map_images[events.jhat.which].end()) {
                                m_pan_tabs[events.jhat.which]->ShowImg(img_dp_bottom);
                            }
                            break;
                        case SDL_HAT_RIGHT:
                            key = hat_to_key(events.jhat.value, events.jhat.hat);
                            it = m_map_images[events.jhat.which].find(key);
                            if (it != m_map_images[events.jhat.which].end()) {
                                m_pan_tabs[events.jhat.which]->ShowImg(img_dp_right);
                            }
                            break;
                        case SDL_HAT_LEFT:
                            key = hat_to_key(events.jhat.value, events.jhat.hat);
                            it = m_map_images[events.jhat.which].find(key);
                            if (it != m_map_images[events.jhat.which].end()) {
                                m_pan_tabs[events.jhat.which]->ShowImg(img_dp_left);
                            }
                            break;
                        case SDL_HAT_CENTERED:
                            m_pan_tabs[events.jhat.which]->HideImg(img_dp_up);
                            m_pan_tabs[events.jhat.which]->HideImg(img_dp_bottom);
                            m_pan_tabs[events.jhat.which]->HideImg(img_dp_right);
                            m_pan_tabs[events.jhat.which]->HideImg(img_dp_left);
                    }
                }
                break;
            default:
                break;
        }
    }
#endif // SDL_BUILD
}