Skip to content

Commit db6c330

Browse files
committed
More fixes to date spam.
1 parent 1c4be1f commit db6c330

File tree

37 files changed

+363
-205
lines changed

37 files changed

+363
-205
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,8 @@ file(GLOB MAIN_SOURCES
992992
Source/NintendoSwitch/Options/UI/NintendoSwitch_FriendCodeListWidget.h
993993
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_HomeToDateTime.cpp
994994
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_HomeToDateTime.h
995+
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_NeutralDateSkip.cpp
996+
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_NeutralDateSkip.h
995997
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateBackwardN.cpp
996998
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateBackwardN.h
997999
Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_RollDateForward1.cpp

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_DateReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ void change_date(
567567
);
568568
switch (ret){
569569
case 0:
570-
home_to_date_time(env.logger(), context, true);
570+
home_to_date_time(env.console, context, true);
571571
pbf_press_button(context, BUTTON_A, 80ms + timing_variation, 240ms + timing_variation);
572572
context.wait_for_all_requests();
573573
continue;

SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ void HomeMenuDetector::make_overlays(VideoOverlaySet& items) const{
3838
// This miraculously works on both Switch 1 and Switch 2.
3939
//
4040
bool HomeMenuDetector::detect(const ImageViewRGB32& screen){
41-
m_console_type.detect(screen);
42-
4341
ImageStats stats_bottom_row = image_stats(extract_box_reference(screen, m_bottom_row));
4442
// cout << stats_bottom_row.average << stats_bottom_row.stddev << endl;
4543
bool white;
@@ -103,6 +101,9 @@ bool HomeMenuDetector::detect(const ImageViewRGB32& screen){
103101
return false;
104102
}
105103

104+
// Read the console type only when we have confirmed the home menu.
105+
m_console_type.detect(screen);
106+
106107
return true;
107108
}
108109

SerialPrograms/Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_HomeToDateTime.cpp

Lines changed: 137 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -22,126 +22,6 @@ namespace PokemonAutomation{
2222
namespace NintendoSwitch{
2323

2424

25-
void home_to_date_time_Switch1_wired_with_feedback(VideoStream& stream, ProControllerContext& context, bool to_date_change){
26-
stream.log("home_to_date_time_Switch1_wired_with_feedback()");
27-
28-
size_t max_attempts = 5;
29-
for (size_t i = 0; i < max_attempts; i++){
30-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
31-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
32-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
33-
34-
// Down twice in case we drop one.
35-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
36-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 4);
37-
38-
// if (i > 0){ // intentionally create a failure, for testing
39-
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0);
40-
// }
41-
42-
43-
// ImageFloatBox system_icon(0.685, 0.69, 0.05, 0.03);
44-
// ImageFloatBox other_setting1(0.615, 0.69, 0.05, 0.03);
45-
// ImageFloatBox other_setting2(0.545, 0.69, 0.05, 0.03);
46-
47-
// Two A presses in case we drop the 1st one.
48-
// the program can self recover even if the second button press is registered.
49-
ssf_press_button(context, BUTTON_A, 3);
50-
ssf_press_button(context, BUTTON_A, 3);
51-
52-
// Just button mash it. lol
53-
{
54-
auto iterations = Milliseconds(1200) / 24ms + 1;
55-
do{
56-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
57-
}while (--iterations);
58-
}
59-
60-
context.wait_for_all_requests();
61-
// Should now be in System Settings, with System highlighted
62-
ImageFloatBox system_setting_box(0.056, 0.74, 0.01, 0.1);
63-
ImageFloatBox other_setting1(0.04, 0.74, 0.01, 0.1);
64-
ImageFloatBox other_setting2(0.02, 0.74, 0.01, 0.1);
65-
SelectedSettingWatcher system_setting_selected(system_setting_box, other_setting1, other_setting2);
66-
int ret = run_until<ProControllerContext>(
67-
stream, context,
68-
[](ProControllerContext& context){
69-
for (int i = 0; i < 10; i++){
70-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
71-
}
72-
},
73-
{system_setting_selected}
74-
);
75-
if (ret < 0){ // failed to detect "System" being highlighted. press home and re-try
76-
pbf_press_button(context, BUTTON_HOME, 100ms, 2000ms);
77-
continue;
78-
}
79-
80-
81-
{
82-
auto iterations = Milliseconds(312) / 24ms + 1;
83-
do{
84-
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 24ms);
85-
}while (--iterations);
86-
}
87-
88-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
89-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
90-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 10);
91-
ssf_press_dpad(context, DPAD_DOWN, 45, 40);
92-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
93-
// if (i > 1){ // intentionally create a failure, for testing
94-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
95-
// }
96-
97-
// only one ButtonA press since the program can self-recover if the button is dropped.
98-
// furthermore, the program can't self-recover if a second button press is registered.
99-
ssf_press_button(context, BUTTON_A, 3);
100-
101-
context.wait_for_all_requests();
102-
context.wait_for(Milliseconds(300));
103-
// we expect to be within "Date and Time", with "Synchronize Clock via Internet" being highlighted
104-
ImageFloatBox sync_clock_box(0.168, 0.185, 0.01, 0.1);
105-
ImageFloatBox other_setting3(0.1, 0.185, 0.01, 0.1);
106-
ImageFloatBox other_setting4(0.05, 0.185, 0.01, 0.1);
107-
SelectedSettingWatcher sync_clock_selected(sync_clock_box, other_setting3, other_setting4);
108-
ret = wait_until(
109-
stream, context,
110-
Milliseconds(2000),
111-
{sync_clock_selected}
112-
);
113-
if (ret < 0){ // failed to detect "Synchronize clock" being highlighted. press home and re-try
114-
pbf_press_button(context, BUTTON_HOME, 100ms, 2000ms);
115-
continue;
116-
}
117-
118-
119-
if (!to_date_change){
120-
return;
121-
}
122-
123-
{
124-
auto iterations = Milliseconds(250) / 24ms + 1;
125-
do{
126-
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
127-
}while (--iterations);
128-
}
129-
130-
// Left scroll in case we missed landed in the language change or sleep
131-
// confirmation menus.
132-
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0ms);
133-
134-
return;
135-
}
136-
137-
OperationFailedException::fire(
138-
ErrorReport::SEND_ERROR_REPORT,
139-
"home_to_date_time(): Failed to reach Date and Time after several attempts.",
140-
stream
141-
);
142-
143-
}
144-
14525

14626
void home_to_date_time_Switch1_wired_blind(
14727
Logger& logger, ProControllerContext& context, bool to_date_change
@@ -420,43 +300,157 @@ void home_to_date_time_Switch2_wired_blind(
420300
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 24ms, 48ms, 24ms);
421301
}
422302

303+
void home_to_date_time_Switch1_wired_with_feedback(VideoStream& stream, ProControllerContext& context, bool to_date_change){
304+
stream.log("home_to_date_time_Switch1_wired_with_feedback()");
423305

306+
size_t max_attempts = 5;
307+
for (size_t i = 0; i < max_attempts; i++){
308+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
309+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
310+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 4);
424311

312+
// Down twice in case we drop one.
313+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
314+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 4);
425315

426-
void home_to_date_time(VideoStream& stream, ProControllerContext& context, bool to_date_change){
427-
switch (context->performance_class()){
428-
case ControllerPerformanceClass::SerialPABotBase_Wired_125Hz:{
429-
home_to_date_time_Switch1_wired_with_feedback(stream, context, to_date_change);
430-
break;
316+
// if (i > 0){ // intentionally create a failure, for testing
317+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0);
318+
// }
319+
320+
321+
// ImageFloatBox system_icon(0.685, 0.69, 0.05, 0.03);
322+
// ImageFloatBox other_setting1(0.615, 0.69, 0.05, 0.03);
323+
// ImageFloatBox other_setting2(0.545, 0.69, 0.05, 0.03);
324+
325+
// Two A presses in case we drop the 1st one.
326+
// the program can self recover even if the second button press is registered.
327+
ssf_press_button(context, BUTTON_A, 3);
328+
ssf_press_button(context, BUTTON_A, 3);
329+
330+
// Just button mash it. lol
331+
{
332+
auto iterations = Milliseconds(1200) / 24ms + 1;
333+
do{
334+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
335+
}while (--iterations);
431336
}
432-
default:{
433-
// Slow version for tick-imprecise controllers. Blind.
434-
home_to_date_time_Switch1_sbb_blind(stream.logger(), context, to_date_change);
337+
338+
context.wait_for_all_requests();
339+
// Should now be in System Settings, with System highlighted
340+
ImageFloatBox system_setting_box(0.056, 0.74, 0.01, 0.1);
341+
ImageFloatBox other_setting1(0.04, 0.74, 0.01, 0.1);
342+
ImageFloatBox other_setting2(0.02, 0.74, 0.01, 0.1);
343+
SelectedSettingWatcher system_setting_selected(system_setting_box, other_setting1, other_setting2);
344+
int ret = run_until<ProControllerContext>(
345+
stream, context,
346+
[](ProControllerContext& context){
347+
for (int i = 0; i < 10; i++){
348+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
349+
}
350+
},
351+
{system_setting_selected}
352+
);
353+
if (ret < 0){ // failed to detect "System" being highlighted. press home and re-try
354+
pbf_press_button(context, BUTTON_HOME, 100ms, 2000ms);
355+
continue;
435356
}
436-
}
437-
}
438357

439-
void home_to_date_time(Logger& logger, ProControllerContext& context, bool to_date_change){
440-
switch (context->performance_class()){
441-
case ControllerPerformanceClass::SerialPABotBase_Wired_125Hz:{
442-
home_to_date_time_Switch1_wired_blind(logger, context, to_date_change);
443-
break;
358+
359+
{
360+
auto iterations = Milliseconds(312) / 24ms + 1;
361+
do{
362+
ssf_issue_scroll(context, SSF_SCROLL_RIGHT, 24ms);
363+
}while (--iterations);
444364
}
445-
case ControllerPerformanceClass::SerialPABotBase_Wireless_ESP32:{
446-
home_to_date_time_Switch1_wireless_esp32_blind(logger, context, to_date_change);
447-
break;
365+
366+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
367+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
368+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 10);
369+
ssf_press_dpad(context, DPAD_DOWN, 45, 40);
370+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
371+
// if (i > 1){ // intentionally create a failure, for testing
372+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 3);
373+
// }
374+
375+
// only one ButtonA press since the program can self-recover if the button is dropped.
376+
// furthermore, the program can't self-recover if a second button press is registered.
377+
ssf_press_button(context, BUTTON_A, 3);
378+
379+
context.wait_for_all_requests();
380+
context.wait_for(Milliseconds(300));
381+
// we expect to be within "Date and Time", with "Synchronize Clock via Internet" being highlighted
382+
ImageFloatBox sync_clock_box(0.168, 0.185, 0.01, 0.1);
383+
ImageFloatBox other_setting3(0.1, 0.185, 0.01, 0.1);
384+
ImageFloatBox other_setting4(0.05, 0.185, 0.01, 0.1);
385+
SelectedSettingWatcher sync_clock_selected(sync_clock_box, other_setting3, other_setting4);
386+
ret = wait_until(
387+
stream, context,
388+
Milliseconds(2000),
389+
{sync_clock_selected}
390+
);
391+
if (ret < 0){ // failed to detect "Synchronize clock" being highlighted. press home and re-try
392+
pbf_press_button(context, BUTTON_HOME, 100ms, 2000ms);
393+
continue;
394+
}
395+
396+
397+
if (!to_date_change){
398+
return;
448399
}
449-
default:{
450-
// Slow version for tick-imprecise controllers.
451-
home_to_date_time_Switch1_sbb_blind(logger, context, to_date_change);
400+
401+
{
402+
auto iterations = Milliseconds(250) / 24ms + 1;
403+
do{
404+
ssf_issue_scroll(context, SSF_SCROLL_DOWN, 24ms);
405+
}while (--iterations);
452406
}
407+
408+
// Left scroll in case we missed landed in the language change or sleep
409+
// confirmation menus.
410+
ssf_issue_scroll(context, SSF_SCROLL_LEFT, 0ms);
411+
412+
return;
453413
}
414+
415+
OperationFailedException::fire(
416+
ErrorReport::SEND_ERROR_REPORT,
417+
"home_to_date_time(): Failed to reach Date and Time after several attempts.",
418+
stream
419+
);
420+
454421
}
455422

456423

457424

458425

459426

427+
void home_to_date_time_switch1_blind(Logger& logger, ProControllerContext& context, bool to_date_change){
428+
switch (context->performance_class()){
429+
case ControllerPerformanceClass::SerialPABotBase_Wired_125Hz:
430+
home_to_date_time_Switch1_wired_blind(logger, context, to_date_change);
431+
return;
432+
case ControllerPerformanceClass::SerialPABotBase_Wireless_ESP32:
433+
home_to_date_time_Switch1_wireless_esp32_blind(logger, context, to_date_change);
434+
return;
435+
default:
436+
// Slow version for tick-imprecise controllers.
437+
home_to_date_time_Switch1_sbb_blind(logger, context, to_date_change);
438+
return;
439+
}
440+
}
441+
bool home_to_date_time_switch1_feedback(ConsoleHandle& console, ProControllerContext& context, bool to_date_change){
442+
switch (context->performance_class()){
443+
case ControllerPerformanceClass::SerialPABotBase_Wired_125Hz:
444+
home_to_date_time_Switch1_wired_with_feedback(console, context, to_date_change);
445+
return true;
446+
default:;
447+
return false;
448+
}
449+
}
450+
451+
452+
453+
460454
// Returns true if success. False if not supported.
461455
bool home_to_date_time_with_feedback(ConsoleHandle& console, ProControllerContext& context, bool to_date_change){
462456
for (size_t attempts = 0;; attempts++){
@@ -481,15 +475,12 @@ bool home_to_date_time_with_feedback(ConsoleHandle& console, ProControllerContex
481475
ConsoleType console_type = detector.detect(console.video().snapshot());
482476
switch (console_type){
483477
case ConsoleType::Switch1:
484-
home_to_date_time_Switch1_wired_with_feedback(console, context, to_date_change);
485-
return true;
478+
return home_to_date_time_switch1_feedback(console, context, to_date_change);
486479
default:;
487480
}
488481

489482
return false;
490483
}
491-
492-
493484
void home_to_date_time(ConsoleHandle& console, ProControllerContext& context, bool to_date_change){
494485
if (console.video().snapshot() && home_to_date_time_with_feedback(console, context, to_date_change)){
495486
return;
@@ -503,7 +494,7 @@ void home_to_date_time(ConsoleHandle& console, ProControllerContext& context, bo
503494
case ConsoleType::Unknown:
504495
throw UserSetupError(console, "Switch type is not specified and feedback is not available.");
505496
case ConsoleType::Switch1:
506-
home_to_date_time(console, context, to_date_change);
497+
home_to_date_time_switch1_blind(console, context, to_date_change);
507498
return;
508499
case ConsoleType::Switch2_Unknown:
509500
case ConsoleType::Switch2_FW19_International:

SerialPrograms/Source/NintendoSwitch/Programs/DateSpam/NintendoSwitch_HomeToDateTime.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ namespace PokemonAutomation{
1717
namespace NintendoSwitch{
1818

1919

20-
// Navigates from Home screen to the Date and Time screen. Using visual inference.
21-
void home_to_date_time(VideoStream& stream, ProControllerContext& context, bool to_date_change);
22-
// Navigates from Home screen to the Date and Time screen. Done blind, without inference.
23-
void home_to_date_time(Logger& logger, ProControllerContext& context, bool to_date_change);
20+
//// Navigates from Home screen to the Date and Time screen. Using visual inference.
21+
//void home_to_date_time(VideoStream& stream, ProControllerContext& context, bool to_date_change);
22+
23+
//// Navigates from Home screen to the Date and Time screen. Done blind, without inference.
24+
//void home_to_date_time(Logger& logger, ProControllerContext& context, bool to_date_change);
2425

2526
void home_to_date_time(ConsoleHandle& console, ProControllerContext& context, bool to_date_change);
2627

0 commit comments

Comments
 (0)