Skip to content

Commit cf5d17b

Browse files
committed
Switch 2 C button.
1 parent 5ee2176 commit cf5d17b

15 files changed

+65
-55
lines changed

ClientSource/Connection/MessageLogger.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ void MessageLogger::on_send(const BotBaseMessage& message, bool is_retransmit){
5353
return;
5454
}
5555
if (is_retransmit){
56-
log("Re-Send: " + str);
56+
log("Re-Send: " + str, COLOR_DARKGREEN);
5757
}else{
58-
log("Sending: " + str);
58+
log("Sending: " + str, COLOR_DARKGREEN);
5959
}
6060
}
6161
void MessageLogger::on_recv(const BotBaseMessage& message){
@@ -76,7 +76,7 @@ void MessageLogger::on_recv(const BotBaseMessage& message){
7676
if (!print){
7777
return;
7878
}
79-
log("Receive: " + message_to_string(message));
79+
log("Receive: " + message_to_string(message), COLOR_DARKGREEN);
8080
}
8181

8282

Common/SerialPABotBase/SerialPABotBase_Messages_NS1_WiredController.h renamed to Common/SerialPABotBase/SerialPABotBase_Messages_NS2_WiredController.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
/* SerialPABotBase Messages (Nintendo Switch 1 Wired Controller)
1+
/* SerialPABotBase Messages (Nintendo Switch 2 Wired Controller)
22
*
33
* From: https://github.com/PokemonAutomation/
44
*
55
*/
66

7-
#ifndef PokemonAutomation_SerialPABotBase_Messages_NS1_WiredController_H
8-
#define PokemonAutomation_SerialPABotBase_Messages_NS1_WiredController_H
7+
#ifndef PokemonAutomation_SerialPABotBase_Messages_NS2_WiredController_H
8+
#define PokemonAutomation_SerialPABotBase_Messages_NS2_WiredController_H
99

1010
#include "SerialPABotBase_Protocol.h"
1111

@@ -25,21 +25,21 @@ namespace SerialPABotBase{
2525
#endif
2626

2727

28-
#define PABB_MSG_REPORT_NS1_WIRED_CONTROLLER 0x90
28+
#define PABB_MSG_REPORT_NS2_WIRED_CONTROLLER 0x90
2929
typedef struct{
3030
uint8_t buttons0;
3131
uint8_t buttons1;
32-
uint8_t dpad;
32+
uint8_t dpad_byte;
3333
uint8_t left_joystick_x;
3434
uint8_t left_joystick_y;
3535
uint8_t right_joystick_x;
3636
uint8_t right_joystick_y;
37-
} pabb_Report_NS1_WiredController;
37+
} pabb_Report_NS2_WiredController;
3838
typedef struct{
3939
seqnum_t seqnum;
4040
uint16_t milliseconds;
41-
pabb_Report_NS1_WiredController report;
42-
} PABB_PACK pabb_Message_Report_NS1_WiredController;
41+
pabb_Report_NS2_WiredController report;
42+
} PABB_PACK pabb_Message_Report_NS2_WiredController;
4343

4444

4545

SerialPrograms/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ file(GLOB MAIN_SOURCES
280280
../Common/Qt/WidgetStackFixedAspectRatio.cpp
281281
../Common/Qt/WidgetStackFixedAspectRatio.h
282282
../Common/SerialPABotBase/SerialPABotBase_Messages_ESP32.h
283-
../Common/SerialPABotBase/SerialPABotBase_Messages_NS1_WiredController.h
283+
../Common/SerialPABotBase/SerialPABotBase_Messages_NS2_WiredController.h
284284
../Common/SerialPABotBase/SerialPABotBase_Protocol.h
285285
../Common/SerialPABotBase/SerialPABotBase_Protocol_IDs.h
286286
../IconResource/IconResource.rc
@@ -693,8 +693,8 @@ file(GLOB MAIN_SOURCES
693693
Source/Controllers/SerialPABotBase/SerialPABotBase_PostConnectActions.h
694694
Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_ESP32.cpp
695695
Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_ESP32.h
696-
Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_NS1_WiredController.cpp
697-
Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_NS1_WiredController.h
696+
Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_NS2_WiredController.cpp
697+
Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_NS2_WiredController.h
698698
Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.cpp
699699
Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_Protocol.h
700700
Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h

SerialPrograms/Source/Controllers/ControllerTypeStrings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const EnumStringMap<ControllerInterface> CONTROLLER_INTERFACE_STRINGS{
1919

2020
const EnumStringMap<ControllerType> CONTROLLER_TYPE_STRINGS{
2121
{ControllerType::None, "None"},
22-
{ControllerType::NintendoSwitch_WiredController, "NS1: Wired Controller"},
22+
{ControllerType::NintendoSwitch_WiredController, "NS2: Wired Controller"},
2323
{ControllerType::NintendoSwitch_WirelessProController, "NS1: Wireless Pro Controller"},
2424
{ControllerType::NintendoSwitch_LeftJoycon, "NS1: Left Joycon"},
2525
{ControllerType::NintendoSwitch_RightJoycon, "NS1: Right Joycon"},

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const std::map<
108108
}},
109109
}},
110110
}},
111-
{2025061307, {
111+
{2025061308, {
112112
{PABB_PID_PABOTBASE_ESP32S3, {
113113
{ControllerType::NintendoSwitch_WiredController, {
114114
ControllerFeature::TickPrecise,
@@ -117,7 +117,7 @@ const std::map<
117117
}},
118118
}},
119119
}},
120-
{2025061406, {
120+
{2025061407, {
121121
{PABB_PID_PABOTBASE_ArduinoUnoR3, {
122122
{ControllerType::NintendoSwitch_WiredController, {
123123
ControllerFeature::TickPrecise,

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_NS1_WiredController.cpp renamed to SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_NS2_WiredController.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
#include <sstream>
8-
#include "Common/SerialPABotBase/SerialPABotBase_Messages_NS1_WiredController.h"
8+
#include "Common/SerialPABotBase/SerialPABotBase_Messages_NS2_WiredController.h"
99
#include "ClientSource/Libraries/MessageConverter.h"
1010
#include "CommonFramework/GlobalSettingsPanel.h"
1111
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerState.h"
@@ -17,23 +17,26 @@ namespace SerialPABotBase{
1717

1818
int register_message_converters_push_button_framework(){
1919
register_message_converter(
20-
PABB_MSG_REPORT_NS1_WIRED_CONTROLLER,
20+
PABB_MSG_REPORT_NS2_WIRED_CONTROLLER,
2121
[](const std::string& body){
2222
// Disable this by default since it's very spammy.
2323
if (!GlobalSettings::instance().LOG_EVERYTHING){
2424
return std::string();
2525
}
2626
std::ostringstream ss;
27-
ss << "PABB_MSG_REPORT_NS1_WIRED_CONTROLLER: ";
28-
if (body.size() != sizeof(pabb_Message_Report_NS1_WiredController)){ ss << "(invalid size)" << std::endl; return ss.str(); }
29-
const auto* params = (const pabb_Message_Report_NS1_WiredController*)body.c_str();
27+
ss << "PABB_MSG_REPORT_NS2_WIRED_CONTROLLER: ";
28+
if (body.size() != sizeof(pabb_Message_Report_NS2_WiredController)){ ss << "(invalid size)" << std::endl; return ss.str(); }
29+
const auto* params = (const pabb_Message_Report_NS2_WiredController*)body.c_str();
3030
ss << "seqnum = " << (uint64_t)params->seqnum;
3131

32-
uint16_t buttons = params->report.buttons0;
33-
buttons |= (uint16_t)params->report.buttons1 << 8;
32+
uint32_t buttons = params->report.buttons0;
33+
buttons |= (uint32_t)params->report.buttons1 << 8;
34+
if (params->report.dpad_byte & 0x80){
35+
buttons |= NintendoSwitch::BUTTON_C;
36+
}
3437
ss << ", buttons = " << buttons << " (" << button_to_string((NintendoSwitch::Button)buttons) << ")";
38+
ss << ", dpad = " << dpad_to_string((NintendoSwitch::DpadPosition)(params->report.dpad_byte & 0x0f));
3539

36-
ss << ", dpad = " << dpad_to_string((NintendoSwitch::DpadPosition)params->report.dpad);
3740
ss << ", LJ = (" << (int)params->report.left_joystick_x << "," << (int)params->report.left_joystick_y << ")";
3841
ss << ", RJ = (" << (int)params->report.right_joystick_x << "," << (int)params->report.right_joystick_y << ")";
3942
ss << ", milliseconds = " << params->milliseconds;

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_NS1_WiredController.h renamed to SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_NS2_WiredController.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
/* SerialPABotBase (Nintendo Switch 1 Wired Controller)
1+
/* SerialPABotBase (Nintendo Switch 2 Wired Controller)
22
*
33
* From: https://github.com/PokemonAutomation/
44
*
55
*/
66

7-
#ifndef PokemonAutomation_SerialPABotBase_NS1_WiredController_H
8-
#define PokemonAutomation_SerialPABotBase_NS1_WiredController_H
7+
#ifndef PokemonAutomation_SerialPABotBase_NS2_WiredController_H
8+
#define PokemonAutomation_SerialPABotBase_NS2_WiredController_H
99

10-
#include "Common/SerialPABotBase/SerialPABotBase_Messages_NS1_WiredController.h"
10+
#include "Common/SerialPABotBase/SerialPABotBase_Messages_NS2_WiredController.h"
1111
#include "ClientSource/Connection/BotBaseMessage.h"
1212

1313
namespace PokemonAutomation{
1414
namespace SerialPABotBase{
1515

1616

17-
class DeviceRequest_NS1_WiredController_ControllerStateMs : public BotBaseRequest{
17+
class DeviceRequest_NS2_WiredController_ControllerStateMs : public BotBaseRequest{
1818
public:
19-
pabb_Message_Report_NS1_WiredController params;
20-
DeviceRequest_NS1_WiredController_ControllerStateMs(
19+
pabb_Message_Report_NS2_WiredController params;
20+
DeviceRequest_NS2_WiredController_ControllerStateMs(
2121
uint16_t milliseconds,
2222
uint16_t buttons,
23-
uint8_t dpad,
23+
uint8_t dpad_byte,
2424
uint8_t left_joystick_x,
2525
uint8_t left_joystick_y,
2626
uint8_t right_joystick_x,
@@ -35,17 +35,14 @@ class DeviceRequest_NS1_WiredController_ControllerStateMs : public BotBaseReques
3535

3636
params.report.buttons0 = (uint8_t)buttons;
3737
params.report.buttons1 = (uint8_t)(buttons >> 8);
38-
// params.report.buttons2 = 0;
39-
// params.report.buttons3 = 0;
40-
41-
params.report.dpad = dpad;
38+
params.report.dpad_byte = dpad_byte;
4239
params.report.left_joystick_x = left_joystick_x;
4340
params.report.left_joystick_y = left_joystick_y;
4441
params.report.right_joystick_x = right_joystick_x;
4542
params.report.right_joystick_y = right_joystick_y;
4643
}
4744
virtual BotBaseMessage message() const override{
48-
return BotBaseMessage(PABB_MSG_REPORT_NS1_WIRED_CONTROLLER, params);
45+
return BotBaseMessage(PABB_MSG_REPORT_NS2_WIRED_CONTROLLER, params);
4946
}
5047
};
5148

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerState.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ std::string button_to_string(Button button){
3232
if (button & BUTTON_RIGHT) str += "Right ";
3333
if (button & BUTTON_DOWN) str += "Down ";
3434
if (button & BUTTON_LEFT) str += "Left ";
35-
if (button & BUTTON_LEFT_SL) str += "Left-SL";
36-
if (button & BUTTON_LEFT_SR) str += "Left-SR";
37-
if (button & BUTTON_RIGHT_SL) str += "Right-SL";
38-
if (button & BUTTON_RIGHT_SR) str += "Right-SR";
35+
if (button & BUTTON_LEFT_SL) str += "Left-SL ";
36+
if (button & BUTTON_LEFT_SR) str += "Left-SR ";
37+
if (button & BUTTON_RIGHT_SL) str += "Right-SL ";
38+
if (button & BUTTON_RIGHT_SR) str += "Right-SR ";
39+
if (button & BUTTON_C) str += "C ";
3940
if (str.empty()){
4041
str = "none";
4142
}

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerState.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ constexpr uint16_t TICKS_PER_SECOND = 125;
2020

2121

2222
// Buttons
23-
constexpr size_t TOTAL_BUTTONS = 24;
23+
constexpr size_t TOTAL_BUTTONS = 25;
2424
using ButtonFlagType = uint32_t;
2525
enum Button : ButtonFlagType{
2626
BUTTON_NONE = 0,
@@ -48,6 +48,7 @@ enum Button : ButtonFlagType{
4848
BUTTON_LEFT_SR = ((uint32_t)1 << 21),
4949
BUTTON_RIGHT_SL = ((uint32_t)1 << 22),
5050
BUTTON_RIGHT_SR = ((uint32_t)1 << 23),
51+
BUTTON_C = ((uint32_t)1 << 24),
5152
};
5253
inline constexpr Button operator|(Button x, Button y){
5354
return (Button)((ButtonFlagType)x | (ButtonFlagType)y);

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ std::vector<std::unique_ptr<EditableTableRow>> ProControllerKeyboardMappingTable
196196
ret.emplace_back(make_mapping("ZR", Qt::Key::Key_Backslash, ProControllerDeltas{.buttons = BUTTON_ZR}));
197197
ret.emplace_back(make_mapping("ZR", Qt::Key::Key_Bar, ProControllerDeltas{.buttons = BUTTON_ZR}));
198198

199-
ret.emplace_back(make_mapping("GL (Switch 2)", Qt::Key::Key_V, ProControllerDeltas{.buttons = BUTTON_GL}));
200-
ret.emplace_back(make_mapping("GR (Switch 2)", Qt::Key::Key_Period, ProControllerDeltas{.buttons = BUTTON_GR}));
201-
ret.emplace_back(make_mapping("GR (Switch 2)", Qt::Key::Key_Greater, ProControllerDeltas{.buttons = BUTTON_GR}));
202-
203199
ret.emplace_back(make_mapping("-", Qt::Key::Key_Minus, ProControllerDeltas{.buttons = BUTTON_MINUS}));
204200
ret.emplace_back(make_mapping("-", Qt::Key::Key_Underscore, ProControllerDeltas{.buttons = BUTTON_MINUS}));
205201
ret.emplace_back(make_mapping("+", Qt::Key::Key_Plus, ProControllerDeltas{.buttons = BUTTON_PLUS}));
@@ -214,6 +210,11 @@ std::vector<std::unique_ptr<EditableTableRow>> ProControllerKeyboardMappingTable
214210

215211
ret.emplace_back(make_mapping("Capture", Qt::Key::Key_Insert, ProControllerDeltas{.buttons = BUTTON_CAPTURE}));
216212

213+
ret.emplace_back(make_mapping("C (Switch 2)", Qt::Key::Key_B, ProControllerDeltas{.buttons = BUTTON_C}));
214+
ret.emplace_back(make_mapping("GL (Switch 2)", Qt::Key::Key_V, ProControllerDeltas{.buttons = BUTTON_GL}));
215+
ret.emplace_back(make_mapping("GR (Switch 2)", Qt::Key::Key_Period, ProControllerDeltas{.buttons = BUTTON_GR}));
216+
ret.emplace_back(make_mapping("GR (Switch 2)", Qt::Key::Key_Greater, ProControllerDeltas{.buttons = BUTTON_GR}));
217+
217218
ret.emplace_back(make_mapping("A+R (for CFW)", Qt::Key::Key_Y, ProControllerDeltas{.buttons = BUTTON_A | BUTTON_R}));
218219

219220
return ret;
@@ -475,7 +476,7 @@ KeyboardMappingOption::KeyboardMappingOption()
475476
{
476477
PA_ADD_STATIC(DESCRIPTION);
477478
PA_ADD_OPTION(ADVANCED_MODE);
478-
PA_ADD_OPTION(PRO_CONTROLLER0);
479+
PA_ADD_OPTION(PRO_CONTROLLER1);
479480
PA_ADD_OPTION(LEFT_JOYCON0);
480481
PA_ADD_OPTION(RIGHT_JOYCON0);
481482
ADVANCED_MODE.add_listener(*this);
@@ -487,7 +488,7 @@ void KeyboardMappingOption::load_json(const JsonValue& json){
487488
KeyboardMappingOption::on_config_value_changed(this);
488489
}
489490
void KeyboardMappingOption::on_config_value_changed(void* object){
490-
PRO_CONTROLLER0.set_advanced_mode(ADVANCED_MODE);
491+
PRO_CONTROLLER1.set_advanced_mode(ADVANCED_MODE);
491492
LEFT_JOYCON0.set_advanced_mode(ADVANCED_MODE);
492493
RIGHT_JOYCON0.set_advanced_mode(ADVANCED_MODE);
493494
}

0 commit comments

Comments
 (0)