Skip to content

Commit

Permalink
Post-refactor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Jan 26, 2025
1 parent 1da599e commit df72127
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 29 deletions.
37 changes: 19 additions & 18 deletions SerialPrograms/Source/Controllers/ControllerSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
#include "Common/Cpp/Exceptions.h"
#include "ControllerSession.h"

// REMOVE
#include <iostream>
using std::cout;
using std::endl;
//#include <iostream>
//using std::cout;
//using std::endl;

namespace PokemonAutomation{

Expand Down Expand Up @@ -160,22 +159,24 @@ bool ControllerSession::set_device(const std::shared_ptr<const ControllerDescrip


std::string ControllerSession::reset(){
std::lock_guard<std::mutex> lg(m_state_lock);
if (!m_connection){
return "No controller set.";
}
if (m_options_locked){
return "Options are locked.";
}
{
std::lock_guard<std::mutex> lg(m_state_lock);
if (!m_connection){
return "No controller set.";
}
if (m_options_locked){
return "Options are locked.";
}

m_connection.reset();
m_connection = m_descriptor->open(m_logger, m_requirements);
if (m_connection){
m_listeners.run_lambda_with_duplicates([&](Listener& listener){
m_connection->add_status_listener(listener);
});
m_connection.reset();
m_connection = m_descriptor->open(m_logger, m_requirements);
if (m_connection){
m_listeners.run_lambda_with_duplicates([&](Listener& listener){
m_connection->add_status_listener(listener);
});
}
}

signal_status_text_changed(status_text());
return "";
}

Expand Down
4 changes: 2 additions & 2 deletions SerialPrograms/Source/Integrations/ProgramTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ std::string ProgramTracker::reset_serial(uint64_t console_id){
global_logger_tagged().log("SwitchProgramTracker::" + error, COLOR_RED);
return error;
}
const char* msg = iter->second.first->sender().try_reset();
return msg == nullptr ? "Serial connection was reset." : msg;
std::string error = iter->second.first->controller().reset();
return error.empty() ? "Serial connection was reset." : error;
}
std::string ProgramTracker::start_program(uint64_t program_id){
std::lock_guard<std::mutex> lg(m_lock);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class BotBaseHandle;

class TrackableConsole{
public:
virtual BotBaseHandle& sender() = 0;
virtual VideoFeed& video() = 0;
virtual AudioFeed& audio() = 0;
virtual ControllerSession& controller() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class SwitchController_SerialPABotBase :
virtual Logger& logger() override{
return m_serial.logger();
}
BotBaseHandle& handle(){ return m_handle; } // REMOVE


public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "CommonFramework/VideoPipeline/Backends/CameraImplementations.h"
#include "Integrations/ProgramTracker.h"
#include "NintendoSwitch/NintendoSwitch_Settings.h"
#include "NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.h"
#include "NintendoSwitch_SwitchSystemOption.h"
#include "NintendoSwitch_SwitchSystemSession.h"

Expand Down Expand Up @@ -70,11 +69,6 @@ SwitchSystemSession::SwitchSystemSession(
}


BotBaseHandle& SwitchSystemSession::sender(){
// TODO: Don't do this. REMOVE
return static_cast<SwitchController_SerialPABotBase&>(m_controller.connection()).handle();
}

void SwitchSystemSession::get(SwitchSystemOption& option){
m_controller.get(option.m_controller);
m_camera->get(option.m_camera);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class SwitchSystemSession final : public TrackableConsole{
Logger& logger(){ return m_logger; }
virtual VideoFeed& video() override{ return *m_camera; }
virtual AudioFeed& audio() override{ return m_audio; }
virtual BotBaseHandle& sender() override;
virtual ControllerSession& controller() override{ return m_controller; };
VideoOverlay& overlay(){ return m_overlay; }
const StreamHistorySession& stream_history() const{ return m_history; }
Expand Down

0 comments on commit df72127

Please sign in to comment.