Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions SerialPrograms/Source/CommandLine/CommandLine_Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <iostream>
#include "Common/Cpp/Color.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/Logging/Logger.h"
// #include "CommonFramework/Logging/OutputRedirector.h"
#include "Integrations/PybindSwitchController.h"
Expand All @@ -16,6 +17,10 @@
using namespace PokemonAutomation;
using namespace PokemonAutomation::NintendoSwitch;

namespace PokemonAutomation{
bool USE_QT_UI = false;
}

int main(int argc, char* argv[]){
// // Set up output redirection for logging
// OutputRedirector redirect_stdout(std::cout, "stdout", Color());
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/Source/CommonFramework/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern const std::string COMPILER_VERSION;

extern const size_t LOG_HISTORY_LINES;

extern bool USE_QT_UI;

// Set a profile for program settings (/UserSettings/PROFILE_NAME/) on MacOS.
// Have to run the program with command-line argument "open -n PATH_TO_APP --args --profile PROFILE_NAME" to set the profile and launch a new window.
// This allows multiple instances of the program to run since settings are no longer shared.
Expand Down
4 changes: 4 additions & 0 deletions SerialPrograms/Source/CommonFramework/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ using std::endl;

using namespace PokemonAutomation;

namespace PokemonAutomation{
bool USE_QT_UI = true;
}

Q_DECLARE_METATYPE(std::string)

void set_working_directory(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,38 @@ bool SerialPABotBase2_Connection::open_serial_port(){
return false;
}

QSerialPortInfo info = SerialPortPoller::instance().get_port(m_device_name);

// Port is invalid.
if (info.isNull()){
std::string text = "Serial port " + m_device_name + " is invalid.";
m_logger.log(text, COLOR_RED);
set_status_line0(text, COLOR_RED);
return false;
QSerialPortInfo info;
if(USE_QT_UI){
info = SerialPortPoller::instance().get_port(m_device_name);
}else{
info = QSerialPortInfo(QString::fromStdString(m_device_name));
}

// Prolific is banned
if (info.description().indexOf("Prolific") != -1){
QMessageBox box;
box.critical(
nullptr,
"Error",
"Cannot select Prolific controller.<br><br>"
"Prolific controllers do not work for Arduino and similar microcontrollers.<br>"
"You were warned of this in the setup instructions. Please buy a CP210x controller instead."
);
std::string text = "Cannot connect to Prolific controller.";
m_logger.log(text, COLOR_RED);
set_status_line0(text, COLOR_RED);
return false;

if(USE_QT_UI){
// Port is invalid.
if (info.isNull()){
std::string text = "Serial port " + m_device_name + " is invalid.";
m_logger.log(text, COLOR_RED);
set_status_line0(text, COLOR_RED);
return false;
}

// Prolific is banned
if (info.description().indexOf("Prolific") != -1){
QMessageBox box;
box.critical(
nullptr,
"Error",
"Cannot select Prolific controller.<br><br>"
"Prolific controllers do not work for Arduino and similar microcontrollers.<br>"
"You were warned of this in the setup instructions. Please buy a CP210x controller instead."
);
std::string text = "Cannot connect to Prolific controller.";
m_logger.log(text, COLOR_RED);
set_status_line0(text, COLOR_RED);
return false;
}
}

if (cancelled()){
Expand Down
6 changes: 3 additions & 3 deletions SerialPrograms/Source/Integrations/PybindSwitchController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Common/Cpp/Logging/TaggedLogger.h"
#include "CommonFramework/Logging/Logger.h"
#include "Controllers/ControllerConnection.h"
#include "Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h"
#include "Controllers/PABotBase2/SerialPABotBase2_Descriptor.h"
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
#include "PybindSwitchController.h"

Expand All @@ -25,7 +25,7 @@ namespace NintendoSwitch{
class PybindSwitchProControllerInternal final : public ControllerConnection::StatusListener{
public:
PybindSwitchProControllerInternal(const std::string& name)
: m_logger(global_logger_raw(), "Pybind")
: m_logger(global_logger_command_line(), "Pybind")
, m_descriptor(name)
, m_connection(m_descriptor.open_connection(m_logger))
{
Expand Down Expand Up @@ -75,7 +75,7 @@ class PybindSwitchProControllerInternal final : public ControllerConnection::Sta

public:
TaggedLogger m_logger;
SerialPABotBase::SerialPABotBase_Descriptor m_descriptor;
SerialPABotBase::SerialPABotBase2_Descriptor m_descriptor;
std::unique_ptr<ControllerConnection> m_connection;
std::unique_ptr<AbstractController> m_controller;
std::atomic<ProController*> m_procon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
#include "Common/Cpp/StreamConnections/MockDevice.h"
#include "CommonTools/Random.h"
#include "CommonTools/OCR/OCR_TextMatcher.h"

#include "Integrations/PybindSwitchController.h"

//#include <opencv2/core.hpp>
#include <onnxruntime_cxx_api.h>
Expand Down Expand Up @@ -386,6 +386,12 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco

cout << OCR::random_match_probability(10, 1, 0.5) << endl;

#if 0
PybindSwitchProController controller("COM3");
controller.wait_for_ready(5000);
controller.push_button(1000, 200, 800, BUTTON_X);
controller.wait_for_all_requests();
#endif

#if 0
ImageRGB32 image(IMAGE_PATH);
Expand Down
Loading