Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nintendo Switch Pro Controller Support #668

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions config/gimx-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ const long configFrame::ID_MENUITEMG29PS4 = wxNewId();
const long configFrame::ID_MENUITEMDFPS2 = wxNewId();
const long configFrame::ID_MENUITEMDFPPS2 = wxNewId();
const long configFrame::ID_MENUITEMGTFPS2 = wxNewId();
const long configFrame::ID_MENUITEMG920XONE = wxNewId();
const long configFrame::ID_MENUITEMSWITCH = wxNewId();
const long configFrame::ID_MENUITEM8 = wxNewId();
const long configFrame::ID_MENUITEM9 = wxNewId();
const long configFrame::ID_MENUITEM10 = wxNewId();
Expand Down Expand Up @@ -1333,6 +1335,10 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu
MenuType->Append(MenuItemDfpPs2);
MenuItemGtfPs2 = new wxMenuItem(MenuType, ID_MENUITEMGTFPS2, _("GT Force PS2"), wxEmptyString, wxITEM_RADIO);
MenuType->Append(MenuItemGtfPs2);
MenuItemG920XOne = new wxMenuItem(MenuType, ID_MENUITEMG920XONE, _("G920 XOne"), wxEmptyString, wxITEM_RADIO);
/* MenuType->Append(MenuItemG920XOne);*/
MenuItemSwitch = new wxMenuItem(MenuType, ID_MENUITEMSWITCH, _("Switch"), wxEmptyString, wxITEM_RADIO);
MenuType->Append(MenuItemSwitch);
MenuBar1->Append(MenuType, _("Type"));
MenuProfile = new wxMenu();
MenuProfile1 = new wxMenuItem(MenuProfile, ID_MENUITEM8, _("1"), wxEmptyString, wxITEM_RADIO);
Expand Down Expand Up @@ -1450,6 +1456,8 @@ configFrame::configFrame(wxString file,wxWindow* parent, wxWindowID id __attribu
Connect(ID_MENUITEMDFPS2,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuTypeItemSelected);
Connect(ID_MENUITEMDFPPS2,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuTypeItemSelected);
Connect(ID_MENUITEMGTFPS2,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuTypeItemSelected);
/*Connect(ID_MENUITEMG920XONE,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuTypeItemSelected);*/
Connect(ID_MENUITEMSWITCH,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuTypeItemSelected);
Connect(ID_MENUITEM8,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuItemConfiguration);
Connect(ID_MENUITEM9,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuItemConfiguration);
Connect(ID_MENUITEM10,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&configFrame::OnMenuItemConfiguration);
Expand Down Expand Up @@ -2427,6 +2435,12 @@ void configFrame::LoadControllerType()
case C_TYPE_GTF_PS2:
MenuType->Check(ID_MENUITEMGTFPS2, true);
break;
case C_TYPE_G920_XONE:
/* MenuType->Check(ID_MENUITEMG920XONE, true); */
break;
case C_TYPE_SWITCH:
MenuType->Check(ID_MENUITEMSWITCH, true);
break;
case C_TYPE_NONE:
break;
}
Expand Down Expand Up @@ -4360,6 +4374,16 @@ void configFrame::OnMenuTypeItemSelected(wxCommandEvent& event __attribute__((un
{
newType = C_TYPE_GTF_PS2;
}
/*
else if(MenuItemG920XOne->IsChecked())
{
newType = C_TYPE_G920_XONE;
}
*/
else if (MenuItemSwitch->IsChecked())
{
newType = C_TYPE_SWITCH;
}

Controller* controller = configFile.GetController(currentController);

Expand Down
6 changes: 5 additions & 1 deletion config/gimx-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ class configFrame: public wxFrame
static const long ID_MENUITEMDFPS2;
static const long ID_MENUITEMDFPPS2;
static const long ID_MENUITEMGTFPS2;
static const long ID_MENUITEMG920XONE;
static const long ID_MENUITEMSWITCH;
static const long ID_MENUITEM8;
static const long ID_MENUITEM9;
static const long ID_MENUITEM10;
Expand Down Expand Up @@ -497,6 +499,8 @@ class configFrame: public wxFrame
wxStaticText* StaticTextShapePanelAxis;
wxStaticText* MouseOptionsId;
wxMenuItem* MenuItemGtfPs2;
wxMenuItem* MenuItemG920XOne;
wxMenuItem* MenuItemSwitch;
wxStaticText* StaticText12;
wxStaticText* ButtonTabDeviceName;
wxStaticText* FFBTweaksId;
Expand Down Expand Up @@ -545,7 +549,7 @@ class configFrame: public wxFrame
unsigned int grid3mod;
unsigned int grid4mod;
unsigned int gridJoystickCorrectionsMod;

wxString default_directory;

string buttonTabDeviceName;
Expand Down
2 changes: 2 additions & 0 deletions core/connectors/usb_con.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,8 @@ int usb_forward_output(int usb_number, int joystick) {
case C_TYPE_DF_PS2:
case C_TYPE_DFP_PS2:
case C_TYPE_GTF_PS2:
case C_TYPE_G920_XONE:
case C_TYPE_SWITCH:
case C_TYPE_NONE:
break;
}
Expand Down
4 changes: 4 additions & 0 deletions shared/gimxcontroller/include/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

#define MAX_AXIS_VALUE_8BITS 255
#define MAX_AXIS_VALUE_10BITS 1023
#define MAX_AXIS_VALUE_12BITS 4095
#define MAX_AXIS_VALUE_14BITS 16383
#define MAX_AXIS_VALUE_16BITS 65535

#define CENTER_AXIS_VALUE_8BITS (MAX_AXIS_VALUE_8BITS/2+1)
#define CENTER_AXIS_VALUE_10BITS (MAX_AXIS_VALUE_10BITS/2+1)
#define CENTER_AXIS_VALUE_12BITS (MAX_AXIS_VALUE_12BITS/2+1)
#define CENTER_AXIS_VALUE_14BITS (MAX_AXIS_VALUE_14BITS/2+1)
#define CENTER_AXIS_VALUE_16BITS (MAX_AXIS_VALUE_16BITS/2+1)

Expand All @@ -37,6 +39,8 @@ typedef enum
C_TYPE_DF_PS2,
C_TYPE_DFP_PS2,
C_TYPE_GTF_PS2,
C_TYPE_G920_XONE,
C_TYPE_SWITCH,
// <- add new types here
C_TYPE_NONE,
C_TYPE_MAX = C_TYPE_NONE,
Expand Down
2 changes: 2 additions & 0 deletions shared/gimxcontroller/include/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "df_ps2.h"
#include "dfp_ps2.h"
#include "gtf_ps2.h"
#include "switch.h"

#define MAX_REPORTS 2

Expand All @@ -37,6 +38,7 @@ typedef union
s_report_dfPs2 dfPs2;
s_report_dfpPs2 dfpPs2;
s_report_gtfPs2 gtfPs2;
s_report_switch ns;
} s_report;

typedef struct GIMX_PACKED
Expand Down
80 changes: 80 additions & 0 deletions shared/gimxcontroller/include/switch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Copyright (c) 2014 Mathieu Laurendeau <[email protected]>
License: GPLv3
*/

#ifndef SWITCH_H_
#define SWITCH_H_

#include "defs.h"

// Battery levels
#define BATTERY_FULL 0x08
#define BATTERY_MEDIUM 0x06
#define BATTERY_LOW 0x04
#define BATTERY_CRITICAL 0x02
#define BATTERY_EMPTY 0x00
#define BATTERY_CHARGING 0x01 // Can be OR'ed

#define SWITCH_Y 0x01
#define SWITCH_X 0x02
#define SWITCH_B 0x04
#define SWITCH_A 0x08
#define SWITCH_R 0x40
#define SWITCH_ZR 0x80
#define SWITCH_MINUS 0x100
#define SWITCH_PLUS 0x200
#define SWITCH_RCLICK 0x400
#define SWITCH_LCLICK 0x800
#define SWITCH_HOME 0x1000
#define SWITCH_CAPTURE 0x2000
#define SWITCH_CHARGING_GRIP 0x8000
#define SWITCH_DPADDOWN 0x10000
#define SWITCH_DPADUP 0x20000
#define SWITCH_DPADRIGHT 0x40000
#define SWITCH_DPADLEFT 0x80000
#define SWITCH_L 0x400000
#define SWITCH_ZL 0x800000

typedef enum
{
switcha_lstick_x = rel_axis_lstick_x,
switcha_lstick_y = rel_axis_lstick_y,
switcha_rstick_x = rel_axis_rstick_x,
switcha_rstick_y = rel_axis_rstick_y,
switcha_minus = abs_axis_0,
switcha_plus = abs_axis_1,
switcha_home = abs_axis_2,
switcha_up = abs_axis_3,
switcha_right = abs_axis_4,
switcha_down = abs_axis_5,
switcha_left = abs_axis_6,
switcha_x = abs_axis_7,
switcha_a = abs_axis_8,
switcha_b = abs_axis_9,
switcha_y = abs_axis_10,
switcha_l = abs_axis_11,
switcha_r = abs_axis_12,
switcha_zl = abs_axis_13,
switcha_zr = abs_axis_14,
switcha_lclick = abs_axis_15,
switcha_rclick = abs_axis_16,
switcha_capture = abs_axis_17,
} e_switch_axis_index;

typedef struct GIMX_PACKED
{
unsigned long connection_info : 4;
unsigned long battery_level : 4;
unsigned long buttons: 24;
unsigned char analog[6];
unsigned char vibrator_input_report;
unsigned short imu[3 * 2 * 3]; // each axis is uint16_t, 3 axis per sensor, 2 sensors (accel and gyro), 3 reports
} s_report_switch;

typedef struct
{
// TODO MLA
} s_gc_state_switch;

#endif /* SWITCH_H_ */
8 changes: 8 additions & 0 deletions shared/gimxcontroller/src/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const char * controller_get_name(e_controller_type type)
{
if(type < C_TYPE_MAX)
{
if (controllers[type] == NULL)
{
return "none";
}
return controllers[type]->name;
}
return "none";
Expand All @@ -34,6 +38,10 @@ e_controller_type controller_get_type(const char* name)
{
int type;
for(type = 0; type < C_TYPE_MAX; ++type) {
if (controllers[type] == NULL)
{
continue;
}
if(!strcmp(controllers[type]->name, name)) {
return type;
}
Expand Down
Loading