Skip to content

Commit 1153f36

Browse files
committed
Refactor.
1 parent e3a48b0 commit 1153f36

File tree

6 files changed

+365
-317
lines changed

6 files changed

+365
-317
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/NintendoSwitch1_HomeToDateTime.cpp
10131014
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch2_HomeToDateTime.cpp
10141015
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.cpp
10151016
Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.h

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ namespace NintendoSwitch{
1818

1919
SelectedSettingWatcher::~SelectedSettingWatcher() = default;
2020

21-
SelectedSettingWatcher::SelectedSettingWatcher(ImageFloatBox selected_box, ImageFloatBox not_selected_box1, ImageFloatBox not_selected_box2)
21+
SelectedSettingWatcher::SelectedSettingWatcher(
22+
ImageFloatBox selected_box,
23+
ImageFloatBox not_selected_box1,
24+
ImageFloatBox not_selected_box2
25+
)
2226
: VisualInferenceCallback("SelectedSettingWatcher")
2327
, m_selected_box(selected_box)
2428
, m_not_selected_box1(not_selected_box1)

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#ifndef PokemonAutomation_NintendoSwitch_SelectedSettingDetector_H
88
#define PokemonAutomation_NintendoSwitch_SelectedSettingDetector_H
99

10-
#include "Common/Cpp/Color.h"
1110
#include "CommonFramework/ImageTools/ImageBoxes.h"
1211
#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h"
1312
#include "CommonTools/VisualDetector.h"
@@ -18,7 +17,11 @@ namespace NintendoSwitch{
1817

1918
class SelectedSettingWatcher : public VisualInferenceCallback{
2019
public:
21-
SelectedSettingWatcher(ImageFloatBox selected_box, ImageFloatBox not_selected_box1, ImageFloatBox not_selected_box2);
20+
SelectedSettingWatcher(
21+
ImageFloatBox selected_box,
22+
ImageFloatBox not_selected_box1,
23+
ImageFloatBox not_selected_box2
24+
);
2225
virtual ~SelectedSettingWatcher();
2326

2427
virtual void make_overlays(VideoOverlaySet& items) const override;
Lines changed: 337 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,337 @@
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/ImageTools/ImageBoxes.h"
9+
//#include "CommonFramework/VideoPipeline/VideoFeed.h"
10+
//#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
11+
#include "CommonTools/Async/InferenceRoutines.h"
12+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
13+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h"
14+
//#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
15+
#include "NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h"
16+
17+
namespace PokemonAutomation{
18+
namespace NintendoSwitch{
19+
20+
21+
22+
23+
void home_to_date_time_Switch1_wired_blind(
24+
Logger& logger, ProControllerContext& context, bool to_date_change
25+
){
26+
logger.log("home_to_date_time_Switch1_wired_blind()");
27+
28+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
29+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
30+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
31+
32+
// Down twice in case we drop one.
33+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
34+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 4);
35+
36+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0);
37+
38+
// Two A presses in case we drop the 1st one.
39+
ssf_press_button(context, BUTTON_A, 3);
40+
ssf_press_button(context, BUTTON_A, 3);
41+
42+
// Just button mash it. lol
43+
{
44+
auto iterations = Milliseconds(1200) / 24ms + 1;
45+
do{
46+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
47+
}while (--iterations);
48+
}
49+
50+
// Scroll left and press A to exit the sleep menu if we happened to
51+
// land there.
52+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 3);
53+
ssf_press_button(context, BUTTON_A, 3);
54+
55+
{
56+
auto iterations = Milliseconds(312) / 24ms + 1;
57+
do{
58+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 24ms);
59+
}while (--iterations);
60+
}
61+
62+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
63+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
64+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 10);
65+
ssf_press_dpad(context, DPAD_DOWN, 45, 40);
66+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
67+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
68+
69+
if (!to_date_change){
70+
// Triple up this A press to make sure it gets through.
71+
ssf_press_button(context, BUTTON_A, 3);
72+
ssf_press_button(context, BUTTON_A, 3);
73+
ssf_press_button(context, BUTTON_A, 45);
74+
return;
75+
}
76+
77+
// Triple up this A press to make sure it gets through.
78+
ssf_press_button(context, BUTTON_A, 3);
79+
ssf_press_button(context, BUTTON_A, 3);
80+
ssf_press_button(context, BUTTON_A, 3);
81+
{
82+
auto iterations = Milliseconds(250) / 24ms + 1;
83+
do{
84+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
85+
}while (--iterations);
86+
}
87+
// ssf_issue_scroll(context, SSF_SCROLL_DOWN, 0);
88+
89+
// Left scroll in case we missed and landed in the language change or sleep
90+
// confirmation menus.
91+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0ms);
92+
}
93+
void home_to_date_time_Switch1_wireless_esp32_blind(
94+
Logger& logger, ProControllerContext& context, bool to_date_change
95+
){
96+
logger.log("home_to_date_time_Switch1_wireless_esp32_blind()");
97+
98+
Milliseconds tv = context->timing_variation();
99+
Milliseconds unit = 24ms + tv;
100+
101+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, unit);
102+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, unit);
103+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, unit);
104+
105+
// Down twice in case we drop one.
106+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, unit);
107+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, unit);
108+
109+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0ms, 2*unit, unit);
110+
111+
// Press A multiple times to make sure one goes through.
112+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
113+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
114+
pbf_press_button(context, BUTTON_A, 2*unit, unit);
115+
116+
// Just button mash it. lol
117+
{
118+
auto iterations = Milliseconds(1100) / unit + 1;
119+
do{
120+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, unit);
121+
}while (--iterations);
122+
}
123+
124+
// Scroll left and press A to exit the sleep menu if we happened to
125+
// land there.
126+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, unit);
127+
ssf_press_button(context, BUTTON_A, unit, 2*unit, unit);
128+
129+
{
130+
auto iterations = Milliseconds(312) / unit + 1;
131+
do{
132+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, unit);
133+
}while (--iterations);
134+
}
135+
136+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, unit);
137+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, unit);
138+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 400ms, 2*unit, unit);
139+
ssf_press_dpad(context, DPAD_DOWN, 360ms, 304ms);
140+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, unit);
141+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, unit);
142+
143+
if (!to_date_change){
144+
// Triple up this A press to make sure it gets through.
145+
ssf_press_button(context, BUTTON_A, unit);
146+
ssf_press_button(context, BUTTON_A, unit);
147+
ssf_press_button(context, BUTTON_A, 360ms, 2*unit, unit);
148+
return;
149+
}
150+
151+
// Triple up this A press to make sure it gets through.
152+
ssf_press_button(context, BUTTON_A, unit);
153+
ssf_press_button(context, BUTTON_A, unit);
154+
ssf_press_button(context, BUTTON_A, unit);
155+
{
156+
auto iterations = Milliseconds(250) / unit + 1;
157+
do{
158+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, unit);
159+
}while (--iterations);
160+
}
161+
162+
// Left scroll in case we missed landed in the language change or sleep
163+
// confirmation menus.
164+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0ms, 2*unit, unit);
165+
166+
}
167+
void home_to_date_time_Switch1_sbb_blind(
168+
Logger& logger, ProControllerContext& context, bool to_date_change
169+
){
170+
logger.log("home_to_date_time_Switch1_sbb_blind()");
171+
172+
Milliseconds tv = context->timing_variation();
173+
// ssf_do_nothing(context, 1500ms);
174+
175+
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);
176+
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);
177+
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT);
178+
179+
// Down twice in case we drop one.
180+
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
181+
// ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
182+
183+
ssf_issue_scroll_ptv(context, SSF_SCROLL_LEFT);
184+
185+
// Press A multiple times to make sure one goes through.
186+
ssf_mash1_button(context, BUTTON_A, 200ms);
187+
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN, 2500ms, 2500ms);
188+
ssf_issue_scroll_ptv(context, SSF_SCROLL_RIGHT, 500ms, 500ms);
189+
190+
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
191+
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
192+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 500ms, tv, tv);
193+
ssf_press_right_joystick(context, 128, 224, 1000ms, 300ms, tv);
194+
// ssf_issue_scroll(context, SSF_SCROLL_DOWN, 1000ms, 250ms, tv); // Scroll down
195+
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
196+
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
197+
198+
if (!to_date_change){
199+
ssf_press_button_ptv(context, BUTTON_A);
200+
return;
201+
}
202+
203+
ssf_press_button_ptv(context, BUTTON_A, 1000ms);
204+
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
205+
ssf_issue_scroll_ptv(context, SSF_SCROLL_DOWN);
206+
}
207+
208+
209+
210+
211+
212+
void home_to_date_time_Switch1_wired_feedback(
213+
VideoStream& stream, ProControllerContext& context, bool to_date_change
214+
){
215+
stream.log("home_to_date_time_Switch1_wired_with_feedback()");
216+
217+
size_t max_attempts = 5;
218+
for (size_t i = 0; i < max_attempts; i++){
219+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
220+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
221+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
222+
223+
// Down twice in case we drop one.
224+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
225+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 4);
226+
227+
// if (i > 0){ // intentionally create a failure, for testing
228+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0);
229+
// }
230+
231+
232+
// ImageFloatBox system_icon(0.685, 0.69, 0.05, 0.03);
233+
// ImageFloatBox other_setting1(0.615, 0.69, 0.05, 0.03);
234+
// ImageFloatBox other_setting2(0.545, 0.69, 0.05, 0.03);
235+
236+
// Two A presses in case we drop the 1st one.
237+
// the program can self recover even if the second button press is registered.
238+
ssf_press_button(context, BUTTON_A, 3);
239+
ssf_press_button(context, BUTTON_A, 3);
240+
241+
// Just button mash it. lol
242+
{
243+
auto iterations = Milliseconds(1200) / 24ms + 1;
244+
do{
245+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
246+
}while (--iterations);
247+
}
248+
249+
context.wait_for_all_requests();
250+
// Should now be in System Settings, with System highlighted
251+
ImageFloatBox system_setting_box(0.056, 0.74, 0.01, 0.1);
252+
ImageFloatBox other_setting1(0.04, 0.74, 0.01, 0.1);
253+
ImageFloatBox other_setting2(0.02, 0.74, 0.01, 0.1);
254+
SelectedSettingWatcher system_setting_selected(system_setting_box, other_setting1, other_setting2);
255+
int ret = run_until<ProControllerContext>(
256+
stream, context,
257+
[](ProControllerContext& context){
258+
for (int i = 0; i < 10; i++){
259+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
260+
}
261+
},
262+
{system_setting_selected}
263+
);
264+
if (ret < 0){ // failed to detect "System" being highlighted. press home and re-try
265+
pbf_press_button(context, BUTTON_HOME, 100ms, 2000ms);
266+
continue;
267+
}
268+
269+
270+
{
271+
auto iterations = Milliseconds(312) / 24ms + 1;
272+
do{
273+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 24ms);
274+
}while (--iterations);
275+
}
276+
277+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
278+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
279+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 10);
280+
ssf_press_dpad(context, DPAD_DOWN, 45, 40);
281+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
282+
// if (i > 1){ // intentionally create a failure, for testing
283+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
284+
// }
285+
286+
// only one ButtonA press since the program can self-recover if the button is dropped.
287+
// furthermore, the program can't self-recover if a second button press is registered.
288+
ssf_press_button(context, BUTTON_A, 3);
289+
290+
context.wait_for_all_requests();
291+
context.wait_for(Milliseconds(300));
292+
// we expect to be within "Date and Time", with "Synchronize Clock via Internet" being highlighted
293+
ImageFloatBox sync_clock_box(0.168, 0.185, 0.01, 0.1);
294+
ImageFloatBox other_setting3(0.1, 0.185, 0.01, 0.1);
295+
ImageFloatBox other_setting4(0.05, 0.185, 0.01, 0.1);
296+
SelectedSettingWatcher sync_clock_selected(sync_clock_box, other_setting3, other_setting4);
297+
ret = wait_until(
298+
stream, context,
299+
Milliseconds(2000),
300+
{sync_clock_selected}
301+
);
302+
if (ret < 0){ // failed to detect "Synchronize clock" being highlighted. press home and re-try
303+
pbf_press_button(context, BUTTON_HOME, 100ms, 2000ms);
304+
continue;
305+
}
306+
307+
308+
if (!to_date_change){
309+
return;
310+
}
311+
312+
{
313+
auto iterations = Milliseconds(250) / 24ms + 1;
314+
do{
315+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
316+
}while (--iterations);
317+
}
318+
319+
// Left scroll in case we missed landed in the language change or sleep
320+
// confirmation menus.
321+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0ms);
322+
323+
return;
324+
}
325+
326+
OperationFailedException::fire(
327+
ErrorReport::SEND_ERROR_REPORT,
328+
"home_to_date_time(): Failed to reach Date and Time after several attempts.",
329+
stream
330+
);
331+
332+
}
333+
334+
335+
336+
}
337+
}

0 commit comments

Comments
 (0)