Skip to content

Commit 6ac37b9

Browse files
jw098Developer-Butters
authored andcommitted
update Pybind for PABB2 (PokemonAutomation#1318)
* change PybindSwitchController to PABB2 * updated SerialPABotBase2_Connection::open_serial_port. QSerialPortInfo is initialized based on whether the QT UI is available.
1 parent d637428 commit 6ac37b9

6 files changed

Lines changed: 51 additions & 26 deletions

File tree

SerialPrograms/Source/CommandLine/CommandLine_Main.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <iostream>
1010
#include "Common/Cpp/Color.h"
11+
#include "CommonFramework/Globals.h"
1112
#include "CommonFramework/Logging/Logger.h"
1213
// #include "CommonFramework/Logging/OutputRedirector.h"
1314
#include "Integrations/PybindSwitchController.h"
@@ -16,6 +17,10 @@
1617
using namespace PokemonAutomation;
1718
using namespace PokemonAutomation::NintendoSwitch;
1819

20+
namespace PokemonAutomation{
21+
bool USE_QT_UI = false;
22+
}
23+
1924
int main(int argc, char* argv[]){
2025
// // Set up output redirection for logging
2126
// OutputRedirector redirect_stdout(std::cout, "stdout", Color());

SerialPrograms/Source/CommonFramework/Globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extern const std::string COMPILER_VERSION;
4343

4444
extern const size_t LOG_HISTORY_LINES;
4545

46+
extern bool USE_QT_UI;
47+
4648
// Set a profile for program settings (/UserSettings/PROFILE_NAME/) on MacOS.
4749
// 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.
4850
// This allows multiple instances of the program to run since settings are no longer shared.

SerialPrograms/Source/CommonFramework/Main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ using std::endl;
4848

4949
using namespace PokemonAutomation;
5050

51+
namespace PokemonAutomation{
52+
bool USE_QT_UI = true;
53+
}
54+
5155
Q_DECLARE_METATYPE(std::string)
5256

5357
void set_working_directory(){

SerialPrograms/Source/Controllers/PABotBase2/SerialPABotBase2_Connection.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,38 @@ bool SerialPABotBase2_Connection::open_serial_port(){
118118
return false;
119119
}
120120

121-
QSerialPortInfo info = SerialPortPoller::instance().get_port(m_device_name);
122-
123-
// Port is invalid.
124-
if (info.isNull()){
125-
std::string text = "Serial port " + m_device_name + " is invalid.";
126-
m_logger.log(text, COLOR_RED);
127-
set_status_line0(text, COLOR_RED);
128-
return false;
121+
QSerialPortInfo info;
122+
if(USE_QT_UI){
123+
info = SerialPortPoller::instance().get_port(m_device_name);
124+
}else{
125+
info = QSerialPortInfo(QString::fromStdString(m_device_name));
129126
}
130127

131-
// Prolific is banned
132-
if (info.description().indexOf("Prolific") != -1){
133-
QMessageBox box;
134-
box.critical(
135-
nullptr,
136-
"Error",
137-
"Cannot select Prolific controller.<br><br>"
138-
"Prolific controllers do not work for Arduino and similar microcontrollers.<br>"
139-
"You were warned of this in the setup instructions. Please buy a CP210x controller instead."
140-
);
141-
std::string text = "Cannot connect to Prolific controller.";
142-
m_logger.log(text, COLOR_RED);
143-
set_status_line0(text, COLOR_RED);
144-
return false;
128+
129+
if(USE_QT_UI){
130+
// Port is invalid.
131+
if (info.isNull()){
132+
std::string text = "Serial port " + m_device_name + " is invalid.";
133+
m_logger.log(text, COLOR_RED);
134+
set_status_line0(text, COLOR_RED);
135+
return false;
136+
}
137+
138+
// Prolific is banned
139+
if (info.description().indexOf("Prolific") != -1){
140+
QMessageBox box;
141+
box.critical(
142+
nullptr,
143+
"Error",
144+
"Cannot select Prolific controller.<br><br>"
145+
"Prolific controllers do not work for Arduino and similar microcontrollers.<br>"
146+
"You were warned of this in the setup instructions. Please buy a CP210x controller instead."
147+
);
148+
std::string text = "Cannot connect to Prolific controller.";
149+
m_logger.log(text, COLOR_RED);
150+
set_status_line0(text, COLOR_RED);
151+
return false;
152+
}
145153
}
146154

147155
if (cancelled()){

SerialPrograms/Source/Integrations/PybindSwitchController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "Common/Cpp/Logging/TaggedLogger.h"
1010
#include "CommonFramework/Logging/Logger.h"
1111
#include "Controllers/ControllerConnection.h"
12-
#include "Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h"
12+
#include "Controllers/PABotBase2/SerialPABotBase2_Descriptor.h"
1313
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
1414
#include "PybindSwitchController.h"
1515

@@ -25,7 +25,7 @@ namespace NintendoSwitch{
2525
class PybindSwitchProControllerInternal final : public ControllerConnection::StatusListener{
2626
public:
2727
PybindSwitchProControllerInternal(const std::string& name)
28-
: m_logger(global_logger_raw(), "Pybind")
28+
: m_logger(global_logger_command_line(), "Pybind")
2929
, m_descriptor(name)
3030
, m_connection(m_descriptor.open_connection(m_logger))
3131
{
@@ -75,7 +75,7 @@ class PybindSwitchProControllerInternal final : public ControllerConnection::Sta
7575

7676
public:
7777
TaggedLogger m_logger;
78-
SerialPABotBase::SerialPABotBase_Descriptor m_descriptor;
78+
SerialPABotBase::SerialPABotBase2_Descriptor m_descriptor;
7979
std::unique_ptr<ControllerConnection> m_connection;
8080
std::unique_ptr<AbstractController> m_controller;
8181
std::atomic<ProController*> m_procon;

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
#include "Common/Cpp/StreamConnections/MockDevice.h"
148148
#include "CommonTools/Random.h"
149149
#include "CommonTools/OCR/OCR_TextMatcher.h"
150-
150+
#include "Integrations/PybindSwitchController.h"
151151

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

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

389+
#if 0
390+
PybindSwitchProController controller("COM3");
391+
controller.wait_for_ready(5000);
392+
controller.push_button(1000, 200, 800, BUTTON_X);
393+
controller.wait_for_all_requests();
394+
#endif
389395

390396
#if 0
391397
ImageRGB32 image(IMAGE_PATH);

0 commit comments

Comments
 (0)