diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index d2d5b6af0..5f13681a6 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -579,8 +579,8 @@ file(GLOB MAIN_SOURCES Source/CommonTools/TrendInference/TimeWindowStatTracker.h Source/CommonTools/Resources/SpriteDatabase.cpp Source/CommonTools/Resources/SpriteDatabase.h - Source/CommonTools/StartupChecks/BlackBorderCheck.cpp - Source/CommonTools/StartupChecks/BlackBorderCheck.h + Source/CommonTools/StartupChecks/StartProgramChecks.cpp + Source/CommonTools/StartupChecks/StartProgramChecks.h Source/CommonTools/StartupChecks/VideoResolutionCheck.cpp Source/CommonTools/StartupChecks/VideoResolutionCheck.h Source/CommonTools/VisualDetector.h diff --git a/SerialPrograms/SerialPrograms.pro b/SerialPrograms/SerialPrograms.pro index 24c5c8143..8c38a17b3 100644 --- a/SerialPrograms/SerialPrograms.pro +++ b/SerialPrograms/SerialPrograms.pro @@ -295,7 +295,7 @@ SOURCES += \ Source/CommonTools/Options/ScreenWatchOption.cpp \ Source/CommonTools/Options/StringSelectOption.cpp \ Source/CommonTools/Resources/SpriteDatabase.cpp \ - Source/CommonTools/StartupChecks/BlackBorderCheck.cpp \ + Source/CommonTools/StartupChecks/StartProgramChecks.cpp \ Source/CommonTools/StartupChecks/VideoResolutionCheck.cpp \ Source/CommonTools/TrendInference/AnomalyDetector.cpp \ Source/CommonTools/VisualDetectors/BlackBorderDetector.cpp \ @@ -1408,7 +1408,7 @@ HEADERS += \ Source/CommonTools/Options/StringSelectTableOption.h \ Source/CommonTools/Options/TrainOCRModeOption.h \ Source/CommonTools/Resources/SpriteDatabase.h \ - Source/CommonTools/StartupChecks/BlackBorderCheck.h \ + Source/CommonTools/StartupChecks/StartProgramChecks.h \ Source/CommonTools/StartupChecks/VideoResolutionCheck.h \ Source/CommonTools/TrendInference/AnomalyDetector.h \ Source/CommonTools/TrendInference/TimeWindowStatTracker.h \ diff --git a/SerialPrograms/Source/CommonTools/StartupChecks/BlackBorderCheck.h b/SerialPrograms/Source/CommonTools/StartupChecks/BlackBorderCheck.h deleted file mode 100644 index 3d1f43691..000000000 --- a/SerialPrograms/Source/CommonTools/StartupChecks/BlackBorderCheck.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Black Border Check - * - * From: https://github.com/PokemonAutomation/Arduino-Source - * - */ - -#ifndef PokemonAutomation_CommonTools_BlackBorderCheck_H -#define PokemonAutomation_CommonTools_BlackBorderCheck_H - -#include "CommonFramework/Globals.h" - -namespace PokemonAutomation{ - -class VideoStream; - - -void start_program_video_check(VideoStream& stream, FeedbackType feedback); - - -} -#endif diff --git a/SerialPrograms/Source/CommonTools/StartupChecks/BlackBorderCheck.cpp b/SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.cpp similarity index 81% rename from SerialPrograms/Source/CommonTools/StartupChecks/BlackBorderCheck.cpp rename to SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.cpp index 10ddc499b..ef507571d 100644 --- a/SerialPrograms/Source/CommonTools/StartupChecks/BlackBorderCheck.cpp +++ b/SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.cpp @@ -1,4 +1,4 @@ -/* Black Border Check +/* Start Program Checks * * From: https://github.com/PokemonAutomation/Arduino-Source * @@ -10,34 +10,37 @@ #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" #include "CommonFramework/Tools/VideoStream.h" #include "CommonTools/VisualDetectors/BlackBorderDetector.h" -#include "BlackBorderCheck.h" +#include "StartProgramChecks.h" namespace PokemonAutomation{ +namespace StartProgramChecks{ -void start_program_video_check(VideoStream& stream, FeedbackType feedback){ +void check_feedback(VideoStream& stream, FeedbackType feedback){ if (feedback == FeedbackType::NONE){ return; } - VideoSnapshot screen = stream.video().snapshot(); - if (!screen){ if (feedback == FeedbackType::REQUIRED || feedback == FeedbackType::VIDEO_AUDIO){ throw UserSetupError(stream.logger(), "This program requires video feedback. Please make sure the video is working."); } return; } +} +void check_border(VideoStream& stream){ BlackBorderDetector detector; VideoOverlaySet set(stream.overlay()); detector.make_overlays(set); - + VideoSnapshot screen = stream.video().snapshot(); if (detector.detect(screen)){ throw UserSetupError(stream.logger(), "Black border detected! Please set your screen size to 100% in the TV Settings on your Nintendo Switch."); } + } +} } diff --git a/SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.h b/SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.h new file mode 100644 index 000000000..fb2fffe4a --- /dev/null +++ b/SerialPrograms/Source/CommonTools/StartupChecks/StartProgramChecks.h @@ -0,0 +1,25 @@ +/* Start Program Checks + * + * From: https://github.com/PokemonAutomation/Arduino-Source + * + */ + +#ifndef PokemonAutomation_CommonTools_StartProgramChecks_H +#define PokemonAutomation_CommonTools_StartProgramChecks_H + +#include "CommonFramework/Globals.h" + +namespace PokemonAutomation{ + class VideoStream; +namespace StartProgramChecks{ + + + +void check_feedback(VideoStream& stream, FeedbackType feedback); +void check_border(VideoStream& stream); + + + +} +} +#endif diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp index 7633b5360..8c8c6f642 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramSession.cpp @@ -13,7 +13,6 @@ #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/Options/Environment/SleepSuppressOption.h" #include "CommonFramework/Options/Environment/PerformanceOptions.h" -#include "CommonTools/StartupChecks/BlackBorderCheck.h" #include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h" #include "NintendoSwitch_MultiSwitchProgramOption.h" #include "NintendoSwitch_MultiSwitchProgramSession.h" @@ -84,12 +83,22 @@ void MultiSwitchProgramSession::run_program_instance(MultiSwitchProgramEnvironme } } + // Startup Checks size_t consoles = m_system.count(); for (size_t c = 0; c < consoles; c++){ - if (!m_system[c].controller_session().ready()){ - throw UserSetupError(m_system[c].logger(), "Cannot Start: Serial connection not ready."); - } - start_program_video_check(env.consoles[c], m_option.descriptor().feedback()); + m_option.instance().start_program_controller_check( + scope, + m_system[c].controller_session(), c + ); + m_option.instance().start_program_feedback_check( + scope, + env.consoles[c], c, + m_option.descriptor().feedback() + ); + m_option.instance().start_program_border_check( + scope, + env.consoles[c], c + ); } m_scope.store(&scope, std::memory_order_release); @@ -165,6 +174,7 @@ void MultiSwitchProgramSession::internal_run_program(){ } + CancellableHolder scope; MultiSwitchProgramEnvironment env( program_info, diff --git a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp index 5f470d3b2..7a4a8e760 100644 --- a/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Framework/NintendoSwitch_SingleSwitchProgramSession.cpp @@ -12,7 +12,6 @@ #include "CommonFramework/Options/Environment/PerformanceOptions.h" #include "CommonFramework/Notifications/ProgramInfo.h" #include "CommonFramework/Notifications/ProgramNotifications.h" -#include "CommonTools/StartupChecks/BlackBorderCheck.h" #include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h" #include "NintendoSwitch_SingleSwitchProgramOption.h" #include "NintendoSwitch_SingleSwitchProgramSession.h" @@ -59,11 +58,10 @@ void SingleSwitchProgramSession::run_program_instance(SingleSwitchProgramEnviron } } - if (!m_system.controller_session().ready()){ - throw UserSetupError(m_system.logger(), "Cannot Start: Serial connection not ready."); - } - - start_program_video_check(env.console, m_option.descriptor().feedback()); + // Startup Checks + m_option.instance().start_program_controller_check(scope, m_system.controller_session()); + m_option.instance().start_program_feedback_check(scope, env.console, m_option.descriptor().feedback()); + m_option.instance().start_program_border_check(scope, env.console); m_scope.store(&scope, std::memory_order_release); diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp index f1bbf131c..015aa6789 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.cpp @@ -9,6 +9,8 @@ #include "Common/Cpp/Concurrency/AsyncDispatcher.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "CommonFramework/VideoPipeline/Stats/ThreadUtilizationStats.h" +#include "CommonTools/StartupChecks/StartProgramChecks.h" +#include "Controllers/ControllerSession.h" #include "NintendoSwitch_MultiSwitchProgram.h" #include "Framework/NintendoSwitch_MultiSwitchProgramOption.h" @@ -121,6 +123,31 @@ MultiSwitchProgramInstance::MultiSwitchProgramInstance( error_notification_tags ) {} + + +void MultiSwitchProgramInstance::start_program_controller_check( + CancellableScope& scope, + ControllerSession& session, size_t console_index +){ + if (!session.ready()){ + throw UserSetupError(session.logger(), "Cannot Start: Controller is not ready."); + } +} +void MultiSwitchProgramInstance::start_program_feedback_check( + CancellableScope& scope, + VideoStream& stream, size_t console_index, + FeedbackType feedback_type +){ + StartProgramChecks::check_feedback(stream, feedback_type); +} +void MultiSwitchProgramInstance::start_program_border_check( + CancellableScope& scope, + VideoStream& stream, size_t console_index +){ + StartProgramChecks::check_border(stream); +} + + void MultiSwitchProgramInstance::add_option(ConfigOption& option, std::string serialization_string){ m_options.add_option(option, std::move(serialization_string)); } diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h index f1d5597e5..f62f279dc 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h @@ -20,6 +20,7 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" namespace PokemonAutomation{ + class ControllerSession; namespace NintendoSwitch{ @@ -129,6 +130,24 @@ class MultiSwitchProgramInstance{ virtual void program(MultiSwitchProgramEnvironment& env, CancellableScope& scope) = 0; +public: + // Startup Checks: Feel free to override to change behavior. + + virtual void start_program_controller_check( + CancellableScope& scope, + ControllerSession& session, size_t console_index + ); + virtual void start_program_feedback_check( + CancellableScope& scope, + VideoStream& stream, size_t console_index, + FeedbackType feedback_type + ); + virtual void start_program_border_check( + CancellableScope& scope, + VideoStream& stream, size_t console_index + ); + + public: // Settings diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp index 3efd04517..af863e6a0 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp @@ -5,6 +5,10 @@ */ #include "Common/Cpp/Json/JsonValue.h" +//#include "CommonFramework/VideoPipeline/VideoFeed.h" +//#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonTools/StartupChecks/StartProgramChecks.h" +#include "Controllers/ControllerSession.h" #include "NintendoSwitch_SingleSwitchProgram.h" #include "Framework/NintendoSwitch_SingleSwitchProgramOption.h" @@ -64,6 +68,31 @@ SingleSwitchProgramInstance::SingleSwitchProgramInstance( error_notification_tags ) {} + + +void SingleSwitchProgramInstance::start_program_controller_check( + CancellableScope& scope, + ControllerSession& session +){ + if (!session.ready()){ + throw UserSetupError(session.logger(), "Cannot Start: Controller is not ready."); + } +} +void SingleSwitchProgramInstance::start_program_feedback_check( + CancellableScope& scope, + VideoStream& stream, + FeedbackType feedback_type +){ + StartProgramChecks::check_feedback(stream, feedback_type); +} +void SingleSwitchProgramInstance::start_program_border_check( + CancellableScope& scope, + VideoStream& stream +){ + StartProgramChecks::check_border(stream); +} + + void SingleSwitchProgramInstance::add_option(ConfigOption& option, std::string serialization_string){ m_options.add_option(option, std::move(serialization_string)); } diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h index ebb6e52b1..7b456e339 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h @@ -18,6 +18,7 @@ #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" namespace PokemonAutomation{ + class ControllerSession; namespace NintendoSwitch{ @@ -112,6 +113,24 @@ class SingleSwitchProgramInstance{ virtual void program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context) = 0; +public: + // Startup Checks: Feel free to override to change behavior. + + virtual void start_program_controller_check( + CancellableScope& scope, + ControllerSession& session + ); + virtual void start_program_feedback_check( + CancellableScope& scope, + VideoStream& stream, + FeedbackType feedback_type + ); + virtual void start_program_border_check( + CancellableScope& scope, + VideoStream& stream + ); + + public: // Settings