@@ -142,7 +142,7 @@ void ensure_at_home(ConsoleHandle& console, ControllerContext& context, size_t r
142142 }
143143
144144 for (size_t attempts = 0 ; attempts < retries; attempts++){
145- HomeMenuWatcher home_menu (console, 100ms);
145+ HomeMenuWatcher home_menu (console, false , COLOR_RED , 100ms);
146146 context.wait_for_all_requests ();
147147 int ret = wait_until (
148148 console, context, 5000ms,
@@ -335,33 +335,37 @@ void resume_game_from_home(
335335 context.wait_for_all_requests ();
336336
337337 while (true ){
338- {
339- UpdateMenuWatcher update_detector (console);
340- int ret = wait_until (
341- console, context,
342- std::chrono::milliseconds (1000 ),
343- { update_detector }
344- );
345- if (ret == 0 ){
346- console.log (" Detected update window." , COLOR_RED );
347-
348- pbf_press_dpad (context, DPAD_UP , 40ms, 40ms);
349- pbf_press_dpad (context, DPAD_UP , 40ms, 40ms);
350- pbf_press_button (context, BUTTON_A , 80ms, 4000ms);
351- context.wait_for_all_requests ();
352- continue ;
338+ UpdateMenuWatcher update_detector (console);
339+ HomeMenuWatcher home_menu (console, false , COLOR_RED , std::chrono::milliseconds (5000 ));
340+ HomeMenuWatcher no_home_menu (console, true , COLOR_RED , std::chrono::milliseconds (1000 ));
341+ int ret = wait_until (
342+ console, context,
343+ std::chrono::milliseconds (30000 ),
344+ {
345+ update_detector,
346+ home_menu,
347+ no_home_menu,
353348 }
354- }
355-
356- // In case we failed to enter the game.
357- HomeMenuWatcher home_detector ( console);
358- auto snapshot = console. video (). snapshot ( );
359- if (home_detector. detect (snapshot)){
360- console. log ( " Failed to re-enter game. Trying again... " , COLOR_RED );
361- pbf_press_button ( context, BUTTON_HOME , 80ms, 80ms );
349+ );
350+ switch (ret){
351+ case 0 :
352+ console. log ( " Detected update window. " , COLOR_RED );
353+ pbf_press_dpad (context, DPAD_UP , 40ms, 40ms );
354+ pbf_press_dpad (context, DPAD_UP , 40ms, 40ms);
355+ pbf_press_button (context, BUTTON_A , 80ms, 4000ms );
356+ context. wait_for_all_requests ( );
362357 continue ;
363- }else {
364- break ;
358+ case 1 :
359+ console.log (" Detected HOME menu. (unexpected)" , COLOR_RED );
360+ pbf_press_button (context, BUTTON_HOME , 160ms, 5000ms);
361+ context.wait_for_all_requests ();
362+ continue ;
363+ case 2 :
364+ console.log (" No HOME detected. Assume entered game." , COLOR_BLUE );
365+ return ;
366+ default :
367+ console.log (" resume_game_from_home(): No recognized state after 30 seconds. Assume entered game." , COLOR_RED );
368+ return ;
365369 }
366370 }
367371}
@@ -555,7 +559,7 @@ void start_game_from_home_with_inference(
555559
556560 WallClock deadline = current_time () + std::chrono::minutes (5 );
557561 while (current_time () < deadline){
558- HomeMenuWatcher home (console, std::chrono::milliseconds (2000 ));
562+ HomeMenuWatcher home (console, false , COLOR_RED , std::chrono::milliseconds (2000 ));
559563 StartGameUserSelectWatcher user_select (console, COLOR_GREEN );
560564 UpdateMenuWatcher update_menu (console, COLOR_PURPLE );
561565 CheckOnlineWatcher check_online (COLOR_CYAN );
0 commit comments