Skip to content

Commit 52b4510

Browse files
committed
Allow start program checks to be overridden.
1 parent 21e0cd9 commit 52b4510

11 files changed

+151
-42
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,8 @@ file(GLOB MAIN_SOURCES
579579
Source/CommonTools/TrendInference/TimeWindowStatTracker.h
580580
Source/CommonTools/Resources/SpriteDatabase.cpp
581581
Source/CommonTools/Resources/SpriteDatabase.h
582-
Source/CommonTools/StartupChecks/BlackBorderCheck.cpp
583-
Source/CommonTools/StartupChecks/BlackBorderCheck.h
582+
Source/CommonTools/StartupChecks/StartProgramChecks.cpp
583+
Source/CommonTools/StartupChecks/StartProgramChecks.h
584584
Source/CommonTools/StartupChecks/VideoResolutionCheck.cpp
585585
Source/CommonTools/StartupChecks/VideoResolutionCheck.h
586586
Source/CommonTools/VisualDetector.h

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ SOURCES += \
295295
Source/CommonTools/Options/ScreenWatchOption.cpp \
296296
Source/CommonTools/Options/StringSelectOption.cpp \
297297
Source/CommonTools/Resources/SpriteDatabase.cpp \
298-
Source/CommonTools/StartupChecks/BlackBorderCheck.cpp \
298+
Source/CommonTools/StartupChecks/StartProgramChecks.cpp \
299299
Source/CommonTools/StartupChecks/VideoResolutionCheck.cpp \
300300
Source/CommonTools/TrendInference/AnomalyDetector.cpp \
301301
Source/CommonTools/VisualDetectors/BlackBorderDetector.cpp \
@@ -1408,7 +1408,7 @@ HEADERS += \
14081408
Source/CommonTools/Options/StringSelectTableOption.h \
14091409
Source/CommonTools/Options/TrainOCRModeOption.h \
14101410
Source/CommonTools/Resources/SpriteDatabase.h \
1411-
Source/CommonTools/StartupChecks/BlackBorderCheck.h \
1411+
Source/CommonTools/StartupChecks/StartProgramChecks.h \
14121412
Source/CommonTools/StartupChecks/VideoResolutionCheck.h \
14131413
Source/CommonTools/TrendInference/AnomalyDetector.h \
14141414
Source/CommonTools/TrendInference/TimeWindowStatTracker.h \

SerialPrograms/Source/CommonTools/StartupChecks/BlackBorderCheck.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

SerialPrograms/Source/CommonTools/StartupChecks/BlackBorderCheck.cpp renamed to SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Black Border Check
1+
/* Start Program Checks
22
*
33
* From: https://github.com/PokemonAutomation/Arduino-Source
44
*
@@ -10,34 +10,37 @@
1010
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
1111
#include "CommonFramework/Tools/VideoStream.h"
1212
#include "CommonTools/VisualDetectors/BlackBorderDetector.h"
13-
#include "BlackBorderCheck.h"
13+
#include "StartProgramChecks.h"
1414

1515
namespace PokemonAutomation{
16+
namespace StartProgramChecks{
1617

1718

18-
void start_program_video_check(VideoStream& stream, FeedbackType feedback){
19+
void check_feedback(VideoStream& stream, FeedbackType feedback){
1920
if (feedback == FeedbackType::NONE){
2021
return;
2122
}
22-
2323
VideoSnapshot screen = stream.video().snapshot();
24-
2524
if (!screen){
2625
if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO){
2726
throw UserSetupError(stream.logger(), "This program requires video feedback. Please make sure the video is working.");
2827
}
2928
return;
3029
}
30+
}
3131

32+
void check_border(VideoStream& stream){
3233
BlackBorderDetector detector;
3334
VideoOverlaySet set(stream.overlay());
3435
detector.make_overlays(set);
35-
36+
VideoSnapshot screen = stream.video().snapshot();
3637
if (detector.detect(screen)){
3738
throw UserSetupError(stream.logger(), "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch.");
3839
}
40+
3941
}
4042

4143

4244

45+
}
4346
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* Start Program Checks
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_CommonTools_StartProgramChecks_H
8+
#define PokemonAutomation_CommonTools_StartProgramChecks_H
9+
10+
#include "CommonFramework/Globals.h"
11+
12+
namespace PokemonAutomation{
13+
class VideoStream;
14+
namespace StartProgramChecks{
15+
16+
17+
18+
void check_feedback(VideoStream& stream, FeedbackType feedback);
19+
void check_border(VideoStream& stream);
20+
21+
22+
23+
}
24+
}
25+
#endif

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "CommonFramework/Notifications/ProgramNotifications.h"
1414
#include "CommonFramework/Options/Environment/SleepSuppressOption.h"
1515
#include "CommonFramework/Options/Environment/PerformanceOptions.h"
16-
#include "CommonTools/StartupChecks/BlackBorderCheck.h"
1716
#include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h"
1817
#include "NintendoSwitch_MultiSwitchProgramOption.h"
1918
#include "NintendoSwitch_MultiSwitchProgramSession.h"
@@ -84,12 +83,22 @@ void MultiSwitchProgramSession::run_program_instance(MultiSwitchProgramEnvironme
8483
}
8584
}
8685

86+
// Startup Checks
8787
size_t consoles = m_system.count();
8888
for (size_t c = 0; c < consoles; c++){
89-
if (!m_system[c].controller_session().ready()){
90-
throw UserSetupError(m_system[c].logger(), "Cannot Start: Serial connection not ready.");
91-
}
92-
start_program_video_check(env.consoles[c], m_option.descriptor().feedback());
89+
m_option.instance().start_program_controller_check(
90+
scope,
91+
m_system[c].controller_session(), c
92+
);
93+
m_option.instance().start_program_feedback_check(
94+
scope,
95+
env.consoles[c], c,
96+
m_option.descriptor().feedback()
97+
);
98+
m_option.instance().start_program_border_check(
99+
scope,
100+
env.consoles[c], c
101+
);
93102
}
94103

95104
m_scope.store(&scope, std::memory_order_release);
@@ -165,6 +174,7 @@ void MultiSwitchProgramSession::internal_run_program(){
165174
}
166175

167176

177+
168178
CancellableHolder<CancellableScope> scope;
169179
MultiSwitchProgramEnvironment env(
170180
program_info,

SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "CommonFramework/Options/Environment/PerformanceOptions.h"
1313
#include "CommonFramework/Notifications/ProgramInfo.h"
1414
#include "CommonFramework/Notifications/ProgramNotifications.h"
15-
#include "CommonTools/StartupChecks/BlackBorderCheck.h"
1615
#include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h"
1716
#include "NintendoSwitch_SingleSwitchProgramOption.h"
1817
#include "NintendoSwitch_SingleSwitchProgramSession.h"
@@ -59,11 +58,10 @@ void SingleSwitchProgramSession::run_program_instance(SingleSwitchProgramEnviron
5958
}
6059
}
6160

62-
if (!m_system.controller_session().ready()){
63-
throw UserSetupError(m_system.logger(), "Cannot Start: Serial connection not ready.");
64-
}
65-
66-
start_program_video_check(env.console, m_option.descriptor().feedback());
61+
// Startup Checks
62+
m_option.instance().start_program_controller_check(scope, m_system.controller_session());
63+
m_option.instance().start_program_feedback_check(scope, env.console, m_option.descriptor().feedback());
64+
m_option.instance().start_program_border_check(scope, env.console);
6765

6866
m_scope.store(&scope, std::memory_order_release);
6967

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "Common/Cpp/Concurrency/AsyncDispatcher.h"
1010
#include "CommonFramework/VideoPipeline/VideoOverlay.h"
1111
#include "CommonFramework/VideoPipeline/Stats/ThreadUtilizationStats.h"
12+
#include "CommonTools/StartupChecks/StartProgramChecks.h"
13+
#include "Controllers/ControllerSession.h"
1214
#include "NintendoSwitch_MultiSwitchProgram.h"
1315
#include "Framework/NintendoSwitch_MultiSwitchProgramOption.h"
1416

@@ -121,6 +123,31 @@ MultiSwitchProgramInstance::MultiSwitchProgramInstance(
121123
error_notification_tags
122124
)
123125
{}
126+
127+
128+
void MultiSwitchProgramInstance::start_program_controller_check(
129+
CancellableScope& scope,
130+
ControllerSession& session, size_t console_index
131+
){
132+
if (!session.ready()){
133+
throw UserSetupError(session.logger(), "Cannot Start: Controller is not ready.");
134+
}
135+
}
136+
void MultiSwitchProgramInstance::start_program_feedback_check(
137+
CancellableScope& scope,
138+
VideoStream& stream, size_t console_index,
139+
FeedbackType feedback_type
140+
){
141+
StartProgramChecks::check_feedback(stream, feedback_type);
142+
}
143+
void MultiSwitchProgramInstance::start_program_border_check(
144+
CancellableScope& scope,
145+
VideoStream& stream, size_t console_index
146+
){
147+
StartProgramChecks::check_border(stream);
148+
}
149+
150+
124151
void MultiSwitchProgramInstance::add_option(ConfigOption& option, std::string serialization_string){
125152
m_options.add_option(option, std::move(serialization_string));
126153
}

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
2121

2222
namespace PokemonAutomation{
23+
class ControllerSession;
2324
namespace NintendoSwitch{
2425

2526

@@ -129,6 +130,24 @@ class MultiSwitchProgramInstance{
129130
virtual void program(MultiSwitchProgramEnvironment& env, CancellableScope& scope) = 0;
130131

131132

133+
public:
134+
// Startup Checks: Feel free to override to change behavior.
135+
136+
virtual void start_program_controller_check(
137+
CancellableScope& scope,
138+
ControllerSession& session, size_t console_index
139+
);
140+
virtual void start_program_feedback_check(
141+
CancellableScope& scope,
142+
VideoStream& stream, size_t console_index,
143+
FeedbackType feedback_type
144+
);
145+
virtual void start_program_border_check(
146+
CancellableScope& scope,
147+
VideoStream& stream, size_t console_index
148+
);
149+
150+
132151
public:
133152
// Settings
134153

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*/
66

77
#include "Common/Cpp/Json/JsonValue.h"
8+
//#include "CommonFramework/VideoPipeline/VideoFeed.h"
9+
//#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
10+
#include "CommonTools/StartupChecks/StartProgramChecks.h"
11+
#include "Controllers/ControllerSession.h"
812
#include "NintendoSwitch_SingleSwitchProgram.h"
913
#include "Framework/NintendoSwitch_SingleSwitchProgramOption.h"
1014

@@ -64,6 +68,31 @@ SingleSwitchProgramInstance::SingleSwitchProgramInstance(
6468
error_notification_tags
6569
)
6670
{}
71+
72+
73+
void SingleSwitchProgramInstance::start_program_controller_check(
74+
CancellableScope& scope,
75+
ControllerSession& session
76+
){
77+
if (!session.ready()){
78+
throw UserSetupError(session.logger(), "Cannot Start: Controller is not ready.");
79+
}
80+
}
81+
void SingleSwitchProgramInstance::start_program_feedback_check(
82+
CancellableScope& scope,
83+
VideoStream& stream,
84+
FeedbackType feedback_type
85+
){
86+
StartProgramChecks::check_feedback(stream, feedback_type);
87+
}
88+
void SingleSwitchProgramInstance::start_program_border_check(
89+
CancellableScope& scope,
90+
VideoStream& stream
91+
){
92+
StartProgramChecks::check_border(stream);
93+
}
94+
95+
6796
void SingleSwitchProgramInstance::add_option(ConfigOption& option, std::string serialization_string){
6897
m_options.add_option(option, std::move(serialization_string));
6998
}

0 commit comments

Comments
 (0)