Skip to content

Commit e3a48b0

Browse files
committed
Refactor
1 parent 36b3c67 commit e3a48b0

File tree

4 files changed

+216
-141
lines changed

4 files changed

+216
-141
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,7 @@ file(GLOB MAIN_SOURCES
10101010
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateBackwardN.h
10111011
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateForward1.cpp
10121012
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateForward1.h
1013+
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch2_HomeToDateTime.cpp
10131014
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.cpp
10141015
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.h
10151016
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.cpp
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
/* Nintendo Switch 2 Home To Date-Time
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/Exceptions/OperationFailedException.h"
8+
#include "CommonFramework/VideoPipeline/VideoFeed.h"
9+
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
10+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
11+
#include "NintendoSwitch/Inference/NintendoSwitch2_BinarySliderDetector.h"
12+
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
17+
18+
19+
void home_to_settings_Switch2_wired_blind(
20+
ProControllerContext& context
21+
){
22+
Milliseconds delay = 24ms;
23+
Milliseconds hold = 48ms;
24+
Milliseconds cool = 24ms;
25+
26+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, delay, hold, cool);
27+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, delay, hold, cool);
28+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, delay, hold, cool);
29+
30+
// Down twice in case we drop one.
31+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, delay, hold, cool);
32+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, delay, hold, cool);
33+
34+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, delay, hold, cool);
35+
36+
// Two A presses in case we drop the 1st one.
37+
ssf_press_button(context, BUTTON_A, delay, hold, cool);
38+
ssf_press_button(context, BUTTON_A, delay, hold, cool);
39+
40+
for (size_t c = 0; c < 40; c++){
41+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, delay, hold, cool);
42+
}
43+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 1000ms, 1000ms, cool);
44+
45+
// Scroll left and press A to exit the sleep menu if we happened to
46+
// land there.
47+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, delay, hold, cool);
48+
ssf_press_button(context, BUTTON_A, 3);
49+
50+
for (size_t c = 0; c < 2; c++){
51+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, delay, hold, cool);
52+
}
53+
}
54+
void settings_to_date_time_Switch2_wired_blind(
55+
Logger& logger, ProControllerContext& context,
56+
ConsoleType console_type, bool to_date_change
57+
){
58+
Milliseconds delay = 24ms;
59+
Milliseconds hold = 48ms;
60+
Milliseconds cool = 24ms;
61+
62+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, delay, hold, cool);
63+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, delay, hold, cool);
64+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 192ms, hold, cool);
65+
66+
67+
switch (console_type){
68+
case ConsoleType::Switch2_FW19_International:
69+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
70+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
71+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
72+
break;
73+
case ConsoleType::Switch2_FW19_JapanLocked:
74+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
75+
break;
76+
case ConsoleType::Switch2_FW20_International:
77+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
78+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
79+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
80+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
81+
break;
82+
case ConsoleType::Switch2_FW20_JapanLocked:
83+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
84+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 128ms, hold, cool);
85+
break;
86+
default:
87+
throw UserSetupError(
88+
logger,
89+
"You need to specify a specific Switch 2 model."
90+
);
91+
}
92+
93+
94+
if (!to_date_change){
95+
// Triple up this A press to make sure it gets through.
96+
ssf_press_button(context, BUTTON_A, delay, hold, cool);
97+
ssf_press_button(context, BUTTON_A, delay, hold, cool);
98+
ssf_press_button(context, BUTTON_A, 360ms, hold, cool);
99+
return;
100+
}
101+
102+
// Triple up this A press to make sure it gets through.
103+
ssf_press_button(context, BUTTON_A, delay, hold, cool);
104+
ssf_press_button(context, BUTTON_A, delay, hold, cool);
105+
ssf_press_button(context, BUTTON_A, delay, hold, cool);
106+
107+
for (size_t c = 0; c < 5; c++){
108+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, delay, hold, cool);
109+
}
110+
111+
// Left scroll in case we missed and landed in the language change or sleep
112+
// confirmation menus.
113+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, delay, hold, cool);
114+
}
115+
ConsoleType settings_detect_console_type(
116+
ConsoleHandle& console, ProControllerContext& context
117+
){
118+
ConsoleType console_type = console.state().console_type();
119+
console.log(std::string("Console Type: ") + ConsoleType_strings(console_type));
120+
121+
// We already know for sure the Switch type.
122+
if (console_type != ConsoleType::Switch2_Unknown &&
123+
console.state().console_type_confirmed()
124+
){
125+
return console_type;
126+
}
127+
128+
console.log("Console type unknown or not confirmed. Attempting to detect...");
129+
130+
VideoOverlaySet overlays(console.overlay());
131+
BinarySliderDetector detector(COLOR_BLUE, {0.836431, 0.097521, 0.069703, 0.796694});
132+
detector.make_overlays(overlays);
133+
134+
ssf_do_nothing(context, 500ms);
135+
for (size_t c = 0; c < 5; c++){
136+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 200ms, 100ms, 100ms);
137+
}
138+
ssf_do_nothing(context, 500ms);
139+
context.wait_for_all_requests();
140+
141+
auto snapshot = console.video().snapshot();
142+
size_t sliders = detector.detect(snapshot).size();
143+
switch (sliders){
144+
case 2:
145+
console.state().set_console_type(console, ConsoleType::Switch2_FW20_International);
146+
break;
147+
case 3:
148+
console.state().set_console_type(console, ConsoleType::Switch2_FW20_JapanLocked);
149+
break;
150+
default:
151+
OperationFailedException::fire(
152+
ErrorReport::SEND_ERROR_REPORT,
153+
"Unable to detect if this Switch 2 model is international or Japan-locked.",
154+
console, std::move(snapshot)
155+
);
156+
}
157+
console_type = console.state().console_type();
158+
console.log(std::string("Detected console type as: ") + ConsoleType_strings(console_type));
159+
160+
// Scroll back up.
161+
for (size_t c = 0; c < 6; c++){
162+
ssf_issue_scroll(context, SSF_SCROLL_UP, 200ms, 100ms, 100ms);
163+
}
164+
ssf_do_nothing(context, 500ms);
165+
166+
return console_type;
167+
}
168+
169+
void home_to_date_time_Switch2_wired_blind(
170+
Logger& logger, ProControllerContext& context,
171+
ConsoleType console_type, bool to_date_change
172+
){
173+
logger.log("home_to_date_time_Switch2_wired_blind()");
174+
home_to_settings_Switch2_wired_blind(context);
175+
settings_to_date_time_Switch2_wired_blind(logger, context, console_type, to_date_change);
176+
}
177+
void home_to_date_time_Switch2_wired_feedback(
178+
ConsoleHandle& console, ProControllerContext& context,
179+
bool to_date_change
180+
){
181+
console.log("home_to_date_time_Switch2_wired_feedback()");
182+
home_to_settings_Switch2_wired_blind(context);
183+
ConsoleType console_type = settings_detect_console_type(console, context);
184+
settings_to_date_time_Switch2_wired_blind(console, context, console_type, to_date_change);
185+
}
186+
187+
188+
189+
}
190+
}

0 commit comments

Comments
 (0)