Skip to content

Commit 9fd132e

Browse files
committed
More SBB3 support.
1 parent 89aed6a commit 9fd132e

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

SerialPrograms/Source/ML/Programs/ML_LabelImages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void DrawnBoundingBox::on_mouse_release(double, double){
7373

7474
const size_t source_width = m_program.source_image_width;
7575
const size_t source_height = m_program.source_image_height;
76-
76+
7777
const int box_x = int(m_program.X * source_width + 0.5);
7878
const int box_y = int(m_program.Y * source_height + 0.5);
7979
const int box_width = int(m_program.WIDTH * source_width + 0.5);

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ProController.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ ProController_SysbotBase3::~ProController_SysbotBase3(){
3636

3737
const ControllerFeatures& ProController_SysbotBase3::controller_features() const{
3838
static const ControllerFeatures features{
39-
// ControllerFeature::TickPrecise, // TODO: Prove it is tick precise.
39+
ControllerFeature::TickPrecise, // TODO: Prove it is tick precise.
4040
ControllerFeature::TimingFlexibleMilliseconds,
4141
ControllerFeature::NintendoSwitch_ProController,
42-
// ControllerFeature::NintendoSwitch_DateSkip, // TODO: Prove this works
42+
ControllerFeature::NintendoSwitch_DateSkip, // TODO: Prove this works
4343
};
4444
return features;
4545
}
@@ -90,9 +90,9 @@ void ProController_SysbotBase3::wait_for_all(const Cancellable* cancellable){
9090
}
9191
}
9292

93-
void ProController_SysbotBase3::on_receive_data(const void* data, size_t bytes){
93+
94+
void ProController_SysbotBase3::on_message(const std::string& message){
9495
const std::string TOKEN = "cqCommandFinished";
95-
std::string message((const char*)data, bytes);
9696
auto pos = message.find(TOKEN);
9797
if (pos == std::string::npos){
9898
return;
@@ -165,7 +165,7 @@ void ProController_SysbotBase3::push_state(const Cancellable* cancellable, WallD
165165
if (m_buttons[14].is_busy()) nx_button |= (uint64_t)1 << 13; // Up
166166
if (m_buttons[15].is_busy()) nx_button |= (uint64_t)1 << 14; // Right
167167
if (m_buttons[16].is_busy()) nx_button |= (uint64_t)1 << 15; // Down
168-
if (m_buttons[17].is_busy()) nx_button |= (uint64_t)1 << 16; // Left
168+
if (m_buttons[17].is_busy()) nx_button |= (uint64_t)1 << 12; // Left
169169
#if 0 // Don't exist on pro controller.
170170
if (m_buttons[18].is_busy()) nx_button |= (uint64_t)1 << 24; // Left SL
171171
if (m_buttons[19].is_busy()) nx_button |= (uint64_t)1 << 25; // Left SR
@@ -179,7 +179,7 @@ void ProController_SysbotBase3::push_state(const Cancellable* cancellable, WallD
179179
if (split_dpad.up) nx_button |= (uint64_t)1 << 13;
180180
if (split_dpad.right) nx_button |= (uint64_t)1 << 14;
181181
if (split_dpad.down) nx_button |= (uint64_t)1 << 15;
182-
if (split_dpad.left) nx_button |= (uint64_t)1 << 16;
182+
if (split_dpad.left) nx_button |= (uint64_t)1 << 12;
183183
}
184184

185185
int16_t left_x = 0;
@@ -228,6 +228,7 @@ void ProController_SysbotBase3::push_state(const Cancellable* cancellable, WallD
228228
message.resize(64);
229229
command.write_to_hex(message.data());
230230
message = "cqControllerState " + message + "\r\n";
231+
231232
m_connection.write_data(message);
232233

233234
if (GlobalSettings::instance().LOG_EVERYTHING){

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ProController.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define PokemonAutomation_NintendoSwitch_ProController_SysbotBase3_H
1010

1111
#include "NintendoSwitch/NintendoSwitch_Settings.h"
12-
#include "NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h"
12+
//#include "NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h"
1313
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
1414
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h"
1515
#include "SysbotBase_Connection.h"
@@ -22,12 +22,12 @@ namespace NintendoSwitch{
2222
class ProController_SysbotBase3 final :
2323
public ProController,
2424
public ControllerWithScheduler,
25-
private ClientSocket::Listener
25+
private SysbotBase::TcpSysbotBase_Connection::Listener
2626
{
2727
public:
2828
using ContextType = ProControllerContext;
2929

30-
static constexpr size_t QUEUE_SIZE = 16;
30+
static constexpr size_t QUEUE_SIZE = 128;
3131

3232

3333
public:
@@ -45,7 +45,8 @@ class ProController_SysbotBase3 final :
4545
virtual const ControllerFeatures& controller_features() const override;
4646
virtual ControllerPerformanceClass performance_class() const override{
4747
// TODO: Change to SerialPABotBase_Wired_125Hz when we prove it is stable.
48-
return ControllerPerformanceClass::SysbotBase;
48+
return ControllerPerformanceClass::SerialPABotBase_Wired_125Hz;
49+
// return ControllerPerformanceClass::SysbotBase;
4950
}
5051

5152
virtual Milliseconds ticksize() const override{
@@ -218,7 +219,7 @@ class ProController_SysbotBase3 final :
218219

219220

220221
private:
221-
virtual void on_receive_data(const void* data, size_t bytes) override;
222+
virtual void on_message(const std::string& message) override;
222223
virtual void push_state(const Cancellable* cancellable, WallDuration duration) override;
223224

224225

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef PokemonAutomation_Controllers_SysbotBase_Connection_H
88
#define PokemonAutomation_Controllers_SysbotBase_Connection_H
99

10+
#include <deque>
1011
#include <mutex>
1112
#include <condition_variable>
1213
#include <thread>
@@ -23,6 +24,10 @@ namespace SysbotBase{
2324

2425
class TcpSysbotBase_Connection : public ControllerConnection, private ClientSocket::Listener{
2526
public:
27+
struct Listener{
28+
virtual void on_message(const std::string& message) = 0;
29+
};
30+
2631
void add_listener(Listener& listener){
2732
m_listeners.add(listener);
2833
}
@@ -50,6 +55,9 @@ class TcpSysbotBase_Connection : public ControllerConnection, private ClientSock
5055
virtual void on_connect_finished(const std::string& error_message) override;
5156
virtual void on_receive_data(const void* data, size_t bytes) override;
5257

58+
void process_message(const std::string& message);
59+
void set_mode(const std::string& sbb_version);
60+
5361
private:
5462
Logger& m_logger;
5563
ClientSocket m_socket;
@@ -59,6 +67,7 @@ class TcpSysbotBase_Connection : public ControllerConnection, private ClientSock
5967
std::string m_connecting_message;
6068
// std::string m_version;
6169
WallClock m_last_receive;
70+
std::deque<char> m_receive_buffer;
6271

6372
SpinLock m_send_lock;
6473
std::mutex m_lock;

0 commit comments

Comments
 (0)