int main() {

struct gamepad_t players[4];
//initialize all values
int i=0, j=0;
for (i=0; i<4; i++) {
players[i].fd = 0;
for (j=0; j<MAX_BTN; j++) {
strcpy(players[i].buttonMap[j], "");
}
}



char temp[MAX_STR_LEN];

printf("Gamepad emulator booting up!\n"); 

while(1) {
//printf("In the while loop.\n");
scanf("%s",temp);

//printf("You entered: %s.\n", temp);

if (!strcmp(temp, "config")) {
//do config for a button mapping for a specified gamepad id
gamepad_config(players);
}
else if (!strcmp(temp, "create")) {
//create a new gamepad in the array index specified by user id
gamepad_create(players);
}
else if (!strcmp(temp, "remove")) {
//remove the specified gamepad id.
//if all are removed, exit this while loop
gamepad_remove(players);
}
else if (!strcmp(temp, "btn_press")) {
//button press event
gamepad_btn_press(players);
}
else if (!strcmp(temp, "btn_release")) {
//button release event
gamepad_btn_release(players);
}
else if (!strcmp(temp, "joystick_event")) {
//joystick event. Add this later
gamepad_joystick_event(players);
}
else {
fprintf(stderr, "Unrecognized input\n");
exit(-1);
}
}

printf("Gamepad emulator ending.\n");

}
Beispiel #2
0
void Dialog::OnButtonClicked(wxCommandEvent &event)
{
    // Affichage d'un message à chaque clic sur le bouton
    wxButton *bt_tmp = (wxButton *)event.GetEventObject(); // get the button object
    int bt_id = bt_tmp->GetId() - wxID_HIGHEST - 1;        // get the real ID
    int gamepad_id = m_tab_gamepad->GetSelection();        // get the tab ID (equivalent to the gamepad id)
    if (bt_id >= 0 && bt_id <= PAD_R_LEFT) {               // if the button ID is a gamepad button
        bt_tmp->Disable();                                 // switch the button state to "Disable"
        config_key(gamepad_id, bt_id);
        bt_tmp->Enable();                 // switch the button state to "Enable"
    } else if (bt_id == Gamepad_config) { // If the button ID is equals to the Gamepad_config button ID
        GamepadConfiguration gamepad_config(gamepad_id, this);

        gamepad_config.InitGamepadConfiguration();
        gamepad_config.ShowModal();
    } else if (bt_id == JoyL_config) { // If the button ID is equals to the JoyL_config button ID
        JoystickConfiguration joystick_config(gamepad_id, true, this);

        joystick_config.InitJoystickConfiguration();
        joystick_config.ShowModal();
    } else if (bt_id == JoyR_config) { // If the button ID is equals to the JoyR_config button ID
        JoystickConfiguration joystick_config(gamepad_id, false, this);

        joystick_config.InitJoystickConfiguration();
        joystick_config.ShowModal();
    } else if (bt_id == Set_all) { // If the button ID is equals to the Set_all button ID
        for (int i = 0; i < MAX_KEYS; ++i) {
            bt_tmp = m_bt_gamepad[gamepad_id][i];
            switch (i) {
                case PAD_L_UP: // Left joystick (Up) ↑
                    m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_up);
                    break;
                case PAD_L_RIGHT: // Left joystick (Right) →
                    m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_right);
                    break;
                case PAD_L_DOWN: // Left joystick (Down) ↓
                    m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_bottom);
                    break;
                case PAD_L_LEFT: // Left joystick (Left) ←
                    m_pan_tabs[gamepad_id]->ShowImg(img_l_arrow_left);
                    break;
                case PAD_R_UP: // Right joystick (Up) ↑
                    m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_up);
                    break;
                case PAD_R_RIGHT: // Right joystick (Right) →
                    m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_right);
                    break;
                case PAD_R_DOWN: // Right joystick (Down) ↓
                    m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_bottom);
                    break;
                case PAD_R_LEFT: // Right joystick (Left) ←
                    m_pan_tabs[gamepad_id]->ShowImg(img_r_arrow_left);
                    break;
                default:
                    m_pan_tabs[gamepad_id]->ShowImg(i);
                    break;
            }
            m_pan_tabs[gamepad_id]->Refresh();
            m_pan_tabs[gamepad_id]->Update();
            config_key(gamepad_id, i);
            switch (i) {
                case PAD_L_UP: // Left joystick (Up) ↑
                    m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_up);
                    break;
                case PAD_L_RIGHT: // Left joystick (Right) →
                    m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_right);
                    break;
                case PAD_L_DOWN: // Left joystick (Down) ↓
                    m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_bottom);
                    break;
                case PAD_L_LEFT: // Left joystick (Left) ←
                    m_pan_tabs[gamepad_id]->HideImg(img_l_arrow_left);
                    break;
                case PAD_R_UP: // Right joystick (Up) ↑
                    m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_up);
                    break;
                case PAD_R_RIGHT: // Right joystick (Right) →
                    m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_right);
                    break;
                case PAD_R_DOWN: // Right joystick (Down) ↓
                    m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_bottom);
                    break;
                case PAD_R_LEFT: // Right joystick (Left) ←
                    m_pan_tabs[gamepad_id]->HideImg(img_r_arrow_left);
                    break;
                default:
                    m_pan_tabs[gamepad_id]->HideImg(i);
                    break;
            }
            m_pan_tabs[gamepad_id]->Refresh();
            m_pan_tabs[gamepad_id]->Update();
            usleep(500000); // give enough time to the user to release the button
        }
    } else if (bt_id == Ok) {     // If the button ID is equals to the Ok button ID
        SaveConfig();             // Save the configuration
        Close();                  // Close the window
    } else if (bt_id == Apply) {  // If the button ID is equals to the Apply button ID
        SaveConfig();             // Save the configuration
    } else if (bt_id == Cancel) { // If the button ID is equals to the cancel button ID
        Close();                  // Close the window
    }
}