Skip to content

Commit d828dca

Browse files
committed
Fix some hangs in changing serial ports. Preliminary (experimental) infra work for SBB.
1 parent 4e14d4f commit d828dca

25 files changed

+844
-159
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ file(GLOB MAIN_SOURCES
638638
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h
639639
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp
640640
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h
641+
Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h
641642
Source/Integrations/DiscordIntegrationSettings.cpp
642643
Source/Integrations/DiscordIntegrationSettings.h
643644
Source/Integrations/DiscordIntegrationTable.cpp
@@ -829,6 +830,11 @@ file(GLOB MAIN_SOURCES
829830
Source/NintendoSwitch/Controllers/NintendoSwitch_ProController_SerialPABotBase.h
830831
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.cpp
831832
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h
833+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.cpp
834+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h
835+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.cpp
836+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.h
837+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_SelectorWidget.h
832838
Source/NintendoSwitch/DevPrograms/BoxDraw.cpp
833839
Source/NintendoSwitch/DevPrograms/BoxDraw.h
834840
Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ SOURCES += \
411411
Source/NintendoSwitch/Controllers/NintendoSwitch_ProController_SerialPABotBase.cpp \
412412
Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.cpp \
413413
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.cpp \
414+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.cpp \
415+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.cpp \
414416
Source/NintendoSwitch/DevPrograms/BoxDraw.cpp \
415417
Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp \
416418
Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp \
@@ -1459,6 +1461,7 @@ HEADERS += \
14591461
Source/Controllers/SerialPABotBase/SerialPABotBase.h \
14601462
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h \
14611463
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h \
1464+
Source/Controllers/SerialPABotBase/SerialPABotBase_SelectorWidget.h \
14621465
Source/Controllers/SuperscalarScheduler.h \
14631466
Source/Integrations/DiscordIntegrationSettings.h \
14641467
Source/Integrations/DiscordIntegrationTable.h \
@@ -1563,6 +1566,9 @@ HEADERS += \
15631566
Source/NintendoSwitch/Controllers/NintendoSwitch_ProController_SerialPABotBase.h \
15641567
Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.h \
15651568
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h \
1569+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h \
1570+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.h \
1571+
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_SelectorWidget.h \
15661572
Source/NintendoSwitch/DevPrograms/BoxDraw.h \
15671573
Source/NintendoSwitch/DevPrograms/TestProgramComputer.h \
15681574
Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h \

SerialPrograms/Source/Controllers/ControllerCapability.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ namespace PokemonAutomation{
1212

1313
const EnumStringMap<ControllerInterface> CONTROLLER_INTERFACE_STRINGS{
1414
{ControllerInterface::None, "None"},
15-
{ControllerInterface::SerialPABotBase, "SerialPABotBase"},
15+
{ControllerInterface::SerialPABotBase, "Serial PABotBase"},
16+
{ControllerInterface::SysbotBaseNetwork, "sys-botbase Network"},
17+
{ControllerInterface::SysbotBaseUSB, "sys-botbase USB"},
1618
};
1719

1820
const EnumStringMap<ControllerType> CONTROLLER_TYPE_STRINGS{

SerialPrograms/Source/Controllers/ControllerCapability.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace PokemonAutomation{
3535
enum class ControllerInterface{
3636
None,
3737
SerialPABotBase,
38+
SysbotBaseNetwork,
39+
SysbotBaseUSB,
3840
};
3941
extern const EnumStringMap<ControllerInterface> CONTROLLER_INTERFACE_STRINGS;
4042

SerialPrograms/Source/Controllers/ControllerConnection.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace PokemonAutomation{
1717
void ControllerConnection::add_status_listener(StatusListener& listener){
1818
m_status_listeners.add(listener);
1919
if (m_ready.load(std::memory_order_acquire)){
20-
listener.post_ready(supported_controllers());
20+
listener.post_connection_ready(*this, supported_controllers());
2121
}
2222
}
2323
void ControllerConnection::remove_status_listener(StatusListener& listener){
@@ -37,17 +37,24 @@ void ControllerConnection::set_status(const std::string& text){
3737
}
3838
signal_status_text_changed(text);
3939
}
40+
void ControllerConnection::declare_ready(const std::map<ControllerType, std::set<ControllerFeature>>& controllers){
41+
m_ready.store(true, std::memory_order_release);
42+
signal_post_ready(controllers);
43+
}
4044

4145

42-
void ControllerConnection::signal_pre_not_ready(){
43-
m_status_listeners.run_method_unique(&StatusListener::pre_not_ready);
44-
}
46+
//void ControllerConnection::signal_pre_not_ready(){
47+
// m_status_listeners.run_method_unique(&StatusListener::pre_connection_not_ready, *this);
48+
//}
4549
void ControllerConnection::signal_post_ready(const std::map<ControllerType, std::set<ControllerFeature>>& controllers){
46-
m_status_listeners.run_method_unique(&StatusListener::post_ready, controllers);
50+
m_status_listeners.run_method_unique(&StatusListener::post_connection_ready, *this, controllers);
4751
}
4852
void ControllerConnection::signal_status_text_changed(const std::string& text){
4953
// cout << "m_status_listeners.size() = " << m_status_listeners.count_unique() << endl;
50-
m_status_listeners.run_method_unique(&StatusListener::post_status_text_changed, text);
54+
m_status_listeners.run_method_unique(&StatusListener::status_text_changed, *this, text);
55+
}
56+
void ControllerConnection::signal_error(const std::string& text){
57+
m_status_listeners.run_method_unique(&StatusListener::on_error, *this, text);
5158
}
5259

5360

SerialPrograms/Source/Controllers/ControllerConnection.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,30 @@ namespace PokemonAutomation{
1818
class ControllerConnection{
1919
public:
2020
struct StatusListener{
21-
virtual void pre_not_ready(){}
22-
virtual void post_ready(const std::map<ControllerType, std::set<ControllerFeature>>& controllers){}
23-
virtual void post_status_text_changed(const std::string& text){}
21+
// virtual void pre_connection_not_ready(ControllerConnection& connection){}
22+
virtual void post_connection_ready(
23+
ControllerConnection& connection,
24+
const std::map<ControllerType, std::set<ControllerFeature>>& controllers
25+
){}
26+
virtual void status_text_changed(
27+
ControllerConnection& connection, const std::string& text
28+
){}
29+
virtual void on_error(
30+
ControllerConnection& connection, const std::string& text
31+
){};
2432
};
2533

2634
void add_status_listener(StatusListener& listener);
2735
void remove_status_listener(StatusListener& listener);
2836

2937

3038
public:
39+
ControllerConnection(uint64_t sequence_number)
40+
: m_sequence_number(sequence_number)
41+
{}
3142
virtual ~ControllerConnection() = default;
3243

44+
uint64_t sequence_number() const{ return m_sequence_number; }
3345
bool is_ready() const{ return m_ready.load(std::memory_order_acquire); }
3446
std::string status_text() const;
3547

@@ -38,13 +50,17 @@ class ControllerConnection{
3850

3951
protected:
4052
void set_status(const std::string& text);
53+
void declare_ready(const std::map<ControllerType, std::set<ControllerFeature>>& controllers);
4154

42-
void signal_pre_not_ready();
55+
private:
56+
// void signal_pre_not_ready();
4357
void signal_post_ready(const std::map<ControllerType, std::set<ControllerFeature>>& controllers);
4458
void signal_status_text_changed(const std::string& text);
59+
void signal_error(const std::string& text);
4560

4661

4762
protected:
63+
const uint64_t m_sequence_number;
4864
std::atomic<bool> m_ready;
4965

5066
private:

SerialPrograms/Source/Controllers/ControllerDescriptor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void InterfaceType::register_factory(
4040

4141

4242

43+
#if 0
4344
std::vector<std::shared_ptr<const ControllerDescriptor>>
4445
get_compatible_descriptors(const ControllerRequirements& requirements){
4546
std::vector<std::shared_ptr<const ControllerDescriptor>> ret;
@@ -71,7 +72,7 @@ get_compatible_descriptors(const ControllerRequirements& requirements){
7172

7273
return ret;
7374
}
74-
75+
#endif
7576

7677

7778

SerialPrograms/Source/Controllers/ControllerDescriptor.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
#include "ControllerCapability.h"
1414
#include "Controller.h"
1515

16+
class QWidget;
17+
1618
namespace PokemonAutomation{
1719

1820
class JsonValue;
1921
class InterfaceType;
2022
class ControllerDescriptor;
2123
class ControllerConnection;
24+
class ControllerSelectorWidget;
2225

2326

2427
//
@@ -35,9 +38,6 @@ class InterfaceType{
3538
public:
3639
virtual ~InterfaceType() = default;
3740

38-
// Returns a list of all available descriptors for this interface type.
39-
virtual std::vector<std::shared_ptr<const ControllerDescriptor>> list() const = 0;
40-
4141
// Construct a descriptor from a JSON config. (reloading saved controller settings)
4242
virtual std::unique_ptr<ControllerDescriptor> make(const JsonValue& json) const = 0;
4343

@@ -55,10 +55,6 @@ class InterfaceType{
5555
template <typename DescriptorType>
5656
class InterfaceType_t : public InterfaceType{
5757
public:
58-
// Subclasses must implement this function.
59-
virtual std::vector<std::shared_ptr<const ControllerDescriptor>> list() const override;
60-
61-
// This function is provided for you.
6258
virtual std::unique_ptr<ControllerDescriptor> make(const JsonValue& json) const override{
6359
std::unique_ptr<DescriptorType> ptr(new DescriptorType());
6460
ptr->load_json(json);
@@ -102,7 +98,7 @@ class ControllerDescriptor{
10298
virtual JsonValue to_json() const = 0;
10399

104100
virtual std::unique_ptr<ControllerConnection> open_connection(
105-
Logger& logger
101+
uint64_t sequence_number, Logger& logger
106102
) const = 0;
107103
virtual std::unique_ptr<AbstractController> make_controller(
108104
Logger& logger,
@@ -113,14 +109,15 @@ class ControllerDescriptor{
113109
return nullptr;
114110
}
115111

112+
virtual QWidget* make_selector_QtWidget(ControllerSelectorWidget& parent) const = 0;
116113
};
117114

118115

119116

120-
117+
#if 0
121118
std::vector<std::shared_ptr<const ControllerDescriptor>>
122119
get_compatible_descriptors(const ControllerRequirements& requirements);
123-
120+
#endif
124121

125122

126123

0 commit comments

Comments
 (0)