@@ -22,126 +22,6 @@ namespace PokemonAutomation{
2222namespace 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
14626void 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.
461455bool 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-
493484void 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:
0 commit comments