1313#include " SerialPABotBase.h"
1414#include " SerialPABotBase_PostConnectActions.h"
1515
16+ // #include <iostream>
17+ // using std::cout;
18+ // using std::endl;
19+
1620namespace PokemonAutomation {
1721namespace SerialPABotBase {
1822
@@ -58,7 +62,7 @@ void post_connect_read_switch1_wireless(
5862 ControllerModeStatus& status,
5963 const std::string& device_name,
6064 PABotBase& botbase,
61- ControllerType controller_type , uint32_t controller_id
65+ ControllerType desired_controller , uint32_t controller_id
6266){
6367 Logger& logger = botbase.logger ();
6468
@@ -86,7 +90,7 @@ void post_connect_read_switch1_wireless(
8690 PokemonAutomation::NintendoSwitch::ConsoleSettings::instance ().CONTROLLER_SETTINGS .get_or_make_profile (
8791 controller_mac_address,
8892 device_name,
89- controller_type
93+ desired_controller
9094 );
9195
9296 PABB_NintendoSwitch_ControllerColors colors;
@@ -117,28 +121,12 @@ void post_connect_read_switch1_wireless(
117121
118122 botbase.issue_request_and_wait (
119123 MessageControllerWriteSpi (
120- controller_type ,
124+ desired_controller ,
121125 0x00006050 , sizeof (PABB_NintendoSwitch_ControllerColors),
122126 &colors
123127 ),
124128 nullptr
125129 );
126-
127-
128- uint32_t native_controller_id = controller_type_to_id (controller_type);
129- botbase.issue_request_and_wait (
130- DeviceRequest_change_controller_mode (native_controller_id),
131- nullptr
132- );
133-
134- // Re-read the controller.
135- logger.log (" Reading Controller Mode..." );
136- uint32_t type_id = read_controller_mode (botbase);
137- status.current_controller = id_to_controller_type (type_id);
138- logger.log (
139- " Reading Controller Mode... Mode = " +
140- CONTROLLER_TYPE_STRINGS.get_string (status.current_controller )
141- );
142130}
143131
144132void run_post_connect_actions_ESP32 (
@@ -159,24 +147,40 @@ void run_post_connect_actions_ESP32(
159147 status, device_name, botbase, desired_controller,
160148 PABB_CID_NintendoSwitch_WirelessProController
161149 );
162- return ;
150+ break ;
163151
164152 case ControllerType::NintendoSwitch_LeftJoycon:
165153 post_connect_read_switch1_wireless (
166154 status, device_name, botbase, desired_controller,
167155 PABB_CID_NintendoSwitch_LeftJoycon
168156 );
169- return ;
157+ break ;
170158
171159 case ControllerType::NintendoSwitch_RightJoycon:
172160 post_connect_read_switch1_wireless (
173161 status, device_name, botbase, desired_controller,
174162 PABB_CID_NintendoSwitch_RightJoycon
175163 );
176- return ;
164+ break ;
177165
178166 default :;
179167 }
168+
169+ uint32_t native_controller_id = controller_type_to_id (desired_controller);
170+ botbase.issue_request_and_wait (
171+ DeviceRequest_change_controller_mode (native_controller_id),
172+ nullptr
173+ );
174+
175+ // Re-read the controller.
176+ Logger& logger = botbase.logger ();
177+ logger.log (" Reading Controller Mode..." );
178+ uint32_t type_id = read_controller_mode (botbase);
179+ status.current_controller = id_to_controller_type (type_id);
180+ logger.log (
181+ " Reading Controller Mode... Mode = " +
182+ CONTROLLER_TYPE_STRINGS.get_string (status.current_controller )
183+ );
180184}
181185
182186
0 commit comments