Skip to content

Commit 96bef6f

Browse files
committed
input: console:
- add support for switch joystick, by adding the guid - also add guid and name in default settings
1 parent 4bd7b8d commit 96bef6f

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

settings.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@
3434
"open_settings": "SELECT"
3535
}
3636
},
37+
{
38+
"type": "joystick",
39+
"identification": {
40+
"guid": "00:00:38:f8:53:77:69:74:63:68:20:43:6f:6e:74:00",
41+
"name": "Switch Controller"
42+
},
43+
"drop": "X",
44+
"hold": "B",
45+
"move_down": "LPAD_DOWN",
46+
"move_left": "LPAD_LEFT",
47+
"move_right": "LPAD_RIGHT",
48+
"rotate_left": "DPAD_LEFT",
49+
"rotate_right": "DPAD_RIGHT",
50+
"menu": {
51+
"pause": "MINUS",
52+
"open_settings": "PLUS"
53+
}
54+
},
3755
{
3856
"type": "touch",
3957
"move_x_threshold": 0.07,

src/input/joystick_input.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,19 @@ input::SwitchJoystickInput_Type1::SwitchJoystickInput_Type1(
376376
[[nodiscard]] input::AbstractJoystickSettings<input::console::SettingsType>
377377
input::SwitchJoystickInput_Type1::default_settings_raw() const {
378378
const AbstractJoystickSettings<console::SettingsType> settings = //
379-
{ .identification = JoystickIdentification{},
380-
.rotate_left = JOYCON_DPAD_LEFT,
381-
.rotate_right = JOYCON_DPAD_RIGHT,
382-
.move_left = JOYCON_LDPAD_LEFT,
383-
.move_right = JOYCON_LDPAD_RIGHT,
384-
.move_down = JOYCON_LDPAD_DOWN,
385-
.drop = JOYCON_X,
386-
.hold = JOYCON_B,
387-
.pause = JOYCON_MINUS,
388-
.open_settings = JOYCON_PLUS };
379+
{
380+
.identification =
381+
JoystickIdentification{ .guid = SwitchJoystickInput_Type1::guid, .name = "Switch Controller" },
382+
.rotate_left = JOYCON_DPAD_LEFT,
383+
.rotate_right = JOYCON_DPAD_RIGHT,
384+
.move_left = JOYCON_LDPAD_LEFT,
385+
.move_right = JOYCON_LDPAD_RIGHT,
386+
.move_down = JOYCON_LDPAD_DOWN,
387+
.drop = JOYCON_X,
388+
.hold = JOYCON_B,
389+
.pause = JOYCON_MINUS,
390+
.open_settings = JOYCON_PLUS
391+
};
389392

390393
return settings;
391394
}
@@ -534,16 +537,19 @@ input::_3DSJoystickInput_Type1::_3DSJoystickInput_Type1(
534537
[[nodiscard]] input::AbstractJoystickSettings<input::console::SettingsType>
535538
input::_3DSJoystickInput_Type1::default_settings_raw() const {
536539
const AbstractJoystickSettings<console::SettingsType> settings = //
537-
{ .identification = JoystickIdentification{},
538-
.rotate_left = JOYCON_L,
539-
.rotate_right = JOYCON_R,
540-
.move_left = JOYCON_DPAD_LEFT,
541-
.move_right = JOYCON_DPAD_RIGHT,
542-
.move_down = JOYCON_DPAD_DOWN,
543-
.drop = JOYCON_X,
544-
.hold = JOYCON_B,
545-
.pause = JOYCON_START,
546-
.open_settings = JOYCON_SELECT };
540+
{
541+
.identification =
542+
JoystickIdentification{ .guid = _3DSJoystickInput_Type1::guid, .name = "Nintendo 3DS" },
543+
.rotate_left = JOYCON_L,
544+
.rotate_right = JOYCON_R,
545+
.move_left = JOYCON_DPAD_LEFT,
546+
.move_right = JOYCON_DPAD_RIGHT,
547+
.move_down = JOYCON_DPAD_DOWN,
548+
.drop = JOYCON_X,
549+
.hold = JOYCON_B,
550+
.pause = JOYCON_START,
551+
.open_settings = JOYCON_SELECT
552+
};
547553

548554
return settings;
549555
}

src/input/joystick_input.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ namespace input {
143143

144144
#if defined(__SWITCH__)
145145
struct SwitchJoystickInput_Type1 : ConsoleJoystickInput {
146-
//TODO
147-
static constexpr sdl::GUID guid{};
146+
static constexpr sdl::GUID guid{
147+
sdl::GUID::ArrayType{ 0x00, 0x00, 0x38, 0xf8, 0x53, 0x77, 0x69, 0x74, 0x63, 0x68, 0x20, 0x43, 0x6f, 0x6e,
148+
0x74, 0x00 }
149+
};
148150
SwitchJoystickInput_Type1(SDL_Joystick* joystick, SDL_JoystickID instance_id, const std::string& name);
149151

150152
[[nodiscard]] helper::optional<NavigationEvent> get_navigation_event(const SDL_Event& event) const override;
@@ -165,7 +167,6 @@ namespace input {
165167

166168
struct _3DSJoystickInput_Type1 : ConsoleJoystickInput {
167169

168-
//TODO
169170
static constexpr sdl::GUID guid{
170171
sdl::GUID::ArrayType{ 0x00, 0x00, 0x10, 0x32, 0x4e, 0x69, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x6f, 0x20, 0x33,
171172
0x44, 0x00 }

0 commit comments

Comments
 (0)