Skip to content

Commit 9169c2a

Browse files
committed
Improve reliability of connect_to_internet(). Fix incorrect controller message.
1 parent ee5caca commit 9169c2a

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

SerialPrograms/Source/CommonFramework/Panels/UI/PanelElements.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,29 @@ CollapsibleGroupBox* make_panel_header(
6363
std::string text;
6464
switch (color_class){
6565
case ProgramControllerClass::StandardController_NoRestrictions:
66+
return header;
67+
6668
case ProgramControllerClass::StandardController_PerformanceClassSensitive:
6769
text = html_color_text(
6870
"(This program is sensitive to the performance of the controller. "
6971
"Wired controllers are better than wireless. "
7072
"And wireless is better than tick-imprecise controller.)",
7173
COLOR_DARKGREEN
7274
);
73-
break;
75+
break;
76+
7477
case ProgramControllerClass::StandardController_RequiresPrecision:
7578
text = html_color_text("(This program requires a tick-precise controller.)", COLOR_PURPLE);
7679
break;
80+
7781
case ProgramControllerClass::StandardController_WithRestrictions:
7882
text = html_color_text("(This program may require a specific controller in a specific environment.)", COLOR_RED);
7983
break;
84+
8085
case ProgramControllerClass::SpecializedController:
8186
text = html_color_text("(This program requires a specific type of controller.)", COLOR_MAGENTA);
8287
break;
88+
8389
}
8490

8591
QLabel* label = new QLabel(QString::fromStdString(text), header);

SerialPrograms/Source/PokemonSwSh/Programs/PokemonSwSh_Internet.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,35 @@ bool connect_to_internet_with_inference(
2727
// Enter Y-COMM.
2828
bool ok = true;
2929
// cout << "Waiting for Y-COMM to open..." << endl;
30-
{
30+
for (size_t attempts = 0;;){
3131
YCommMenuDetector detector(true);
32-
if (!detector.detect(stream.video().snapshot())){
33-
pbf_press_button(context, BUTTON_Y, 10, TICKS_PER_SECOND);
34-
context.wait_for_all_requests();
32+
if (detector.detect(stream.video().snapshot())){
33+
stream.log("Y-COMM detected.");
34+
break;
3535
}
36-
int result = wait_until(
36+
37+
int result = run_until<ProControllerContext>(
3738
stream, context,
38-
std::chrono::seconds(10),
39-
{{detector}}
39+
[](ProControllerContext& context){
40+
pbf_press_button(context, BUTTON_Y, 200ms, 4800ms);
41+
},
42+
{detector}
4043
);
4144
if (result == 0){
4245
stream.log("Y-COMM detected.");
43-
}else{
44-
stream.log("Failed to detect Y-COMM after timeout.", COLOR_RED);
45-
dump_image(stream.logger(), info, "connect_to_internet_with_inference", stream.video().snapshot());
46+
break;
47+
}
48+
stream.log("Failed to detect Y-COMM.", COLOR_RED);
49+
50+
attempts++;
51+
if (attempts >= 9){
52+
dump_image(
53+
stream.logger(), info,
54+
"connect_to_internet_with_inference",
55+
stream.video().snapshot()
56+
);
4657
ok = false;
58+
break;
4759
}
4860
}
4961

0 commit comments

Comments
 (0)