Skip to content

Commit 3c90ca2

Browse files
committed
Migrate to the new capabilities implementation.
1 parent dd02ec9 commit 3c90ca2

File tree

209 files changed

+381
-1057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+381
-1057
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,12 +609,13 @@ file(GLOB MAIN_SOURCES
609609
Source/Controllers/ControllerSession.h
610610
Source/Controllers/ControllerSelectorWidget.cpp
611611
Source/Controllers/ControllerSelectorWidget.h
612+
Source/Controllers/SerialPABotBase/SerialPABotBase.cpp
613+
Source/Controllers/SerialPABotBase/SerialPABotBase.h
612614
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp
613615
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h
614616
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp
615617
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h
616618
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp
617-
Source/Controllers/SerialPABotBase/SerialPABotBase_Globals.h
618619
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp
619620
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.h
620621
Source/Integrations/DiscordIntegrationSettings.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ SOURCES += \
309309
Source/Controllers/ControllerSelectorWidget.cpp \
310310
Source/Controllers/ControllerSession.cpp \
311311
Source/Controllers/ControllerDescriptor.cpp \
312+
Source/Controllers/SerialPABotBase/SerialPABotBase.cpp \
312313
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp \
313314
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp \
314315
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp \
@@ -1425,9 +1426,9 @@ HEADERS += \
14251426
Source/Controllers/ControllerSelectorWidget.h \
14261427
Source/Controllers/ControllerSession.h \
14271428
Source/Controllers/ControllerDescriptor.h \
1429+
Source/Controllers/SerialPABotBase/SerialPABotBase.h \
14281430
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h \
14291431
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h \
1430-
Source/Controllers/SerialPABotBase/SerialPABotBase_Globals.h \
14311432
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.h \
14321433
Source/Integrations/DiscordIntegrationSettings.h \
14331434
Source/Integrations/DiscordIntegrationTable.h \

SerialPrograms/Source/CommonFramework/Panels/UI/PanelElements.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,31 +90,6 @@ CollapsibleGroupBox* make_panel_header(
9090
text->setWordWrap(true);
9191
layout->addWidget(text);
9292

93-
#if 0
94-
switch (serial_level){
95-
case PABotBaseLevel::NOT_PABOTBASE:
96-
break;
97-
case PABotBaseLevel::PABOTBASE_12KB:{
98-
#if 0
99-
QLabel* text = new QLabel(
100-
"<font color=\"blue\">(This program will run on both Arduino Uno R3 and Teensy 2.0.</font>)",
101-
header
102-
);
103-
text->setWordWrap(true);
104-
layout->addWidget(text);
105-
#endif
106-
break;
107-
}case PABotBaseLevel::PABOTBASE_31KB:{
108-
QLabel* label = new QLabel(
109-
"<font color=\"red\">(This program requires a Teensy or higher. PABotBase for Arduino Uno R3 does not have all the features required by this program.)</font>",
110-
header
111-
);
112-
label->setWordWrap(true);
113-
layout->addWidget(label);
114-
break;
115-
}
116-
}
117-
#endif
11893
return header;
11994
}
12095

SerialPrograms/Source/Controllers/ControllerCapability.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,28 @@ class ControllerRequirements{
6161
return m_map;
6262
}
6363

64-
bool is_compatible_with(const std::string& device, const std::set<std::string>& features) const{
64+
bool contains_device(const std::string& device) const{
65+
auto scope_check = m_sanitizer.check_scope();
66+
return m_map.find(device) != m_map.end();
67+
}
68+
69+
// Check compatibility. If compatible, returns empty string. Otherwise
70+
// returns one of the missing features.
71+
std::string check_compatibility(const std::string& device, const std::set<std::string>& features) const{
6572
auto scope_check = m_sanitizer.check_scope();
6673

6774
auto iter0 = m_map.find(device);
6875
if (iter0 == m_map.end()){
69-
return false;
76+
return device;
7077
}
7178

7279
const std::set<std::string>& required = iter0->second;
7380
for (const std::string& feature : required){
7481
if (features.find(feature) == features.end()){
75-
return false;
82+
return feature;
7683
}
7784
}
78-
return true;
85+
return "";
7986
}
8087

8188

SerialPrograms/Source/Controllers/ControllerDescriptor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Common/Cpp/Json/JsonObject.h"
99
#include "ControllerDescriptor.h"
1010

11+
#include "Controllers/SerialPABotBase/SerialPABotBase.h"
1112
#include "Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h"
1213
#include "ControllerConnection.h"
1314

@@ -59,14 +60,14 @@ void ControllerOption::load_json(const JsonValue& json){
5960
m_current = std::move(descriptor);
6061
return;
6162
}
62-
if (type == SerialPABotBase::SerialDescriptor::TYPENAME){
63+
if (type == SerialPABotBase::INTERFACE_NAME){
6364
auto descriptor = std::make_unique<SerialPABotBase::SerialDescriptor>();
6465
descriptor->load_json(params);
6566
m_current = std::move(descriptor);
6667
return;
6768
}
6869

69-
throw ParseException("Invalid Device Connection Type: " + type);
70+
m_current.reset(new NullControllerDescriptor());
7071
}
7172
JsonValue ControllerOption::to_json() const{
7273
if (!m_current){

SerialPrograms/Source/Controllers/ControllerSelectorWidget.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
#include <QHBoxLayout>
88
#include "Common/Qt/NoWheelComboBox.h"
9+
#include "Controllers/ControllerCapability.h"
910
#include "ControllerSelectorWidget.h"
11+
#include "SerialPABotBase/SerialPABotBase.h"
1012
#include "SerialPABotBase/SerialPABotBase_Descriptor.h"
1113

1214
//#include <iostream>
@@ -80,16 +82,20 @@ void ControllerSelectorWidget::refresh(){
8082
m_device_list.clear();
8183
m_devices_dropdown->clear();
8284

85+
86+
// Add the "no selection" option.
8387
m_device_list.emplace_back(new NullControllerDescriptor());
8488

85-
// TODO: Apply the requirements filter here to decide which set of devices
86-
// to actually add to the list.
87-
// Also, move this logic into ControllerSession since it isn't UI.
88-
if (true){
89+
// If SerialPABotBase is supported, add them to the list.
90+
if (m_session.requirements().contains_device(SerialPABotBase::INTERFACE_NAME)){
8991
std::vector<std::unique_ptr<const ControllerDescriptor>> serial = SerialPABotBase::get_all_devices();
9092
std::move(serial.begin(), serial.end(), std::back_inserter(m_device_list));
9193
}
9294

95+
// If we add new interfaces, add them here.
96+
97+
98+
9399
std::shared_ptr<const ControllerDescriptor> current = m_session.descriptor();
94100

95101
size_t index = 0;

SerialPrograms/Source/Controllers/ControllerSession.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ std::string ControllerSession::status_text() const{
8383
}
8484
return m_connection->status_text();
8585
}
86-
ControllerConnection& ControllerSession::controller() const{
86+
ControllerConnection& ControllerSession::connection() const{
8787
if (m_connection){
8888
return *m_connection;
8989
}
90-
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Controller is null.");
90+
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Connection is null.");
9191
}
9292

9393

SerialPrograms/Source/Controllers/ControllerSession.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class ControllerSession{
3737
const ControllerRequirements& requirements
3838
);
3939

40+
const ControllerRequirements& requirements(){
41+
return m_requirements;
42+
}
43+
4044
void get(ControllerOption& option);
4145
void set(const ControllerOption& option);
4246

@@ -47,7 +51,7 @@ class ControllerSession{
4751
const ControllerOption& option() const{
4852
return m_option;
4953
}
50-
ControllerConnection& controller() const;
54+
ControllerConnection& connection() const;
5155

5256

5357
public:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* Serial Port (PABotBase)
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "SerialPABotBase.h"
8+
9+
namespace PokemonAutomation{
10+
namespace SerialPABotBase{
11+
12+
13+
const char INTERFACE_NAME[] = "SerialPABotBase";
14+
15+
16+
const char* to_string(Features feature){
17+
switch (feature){
18+
case Features::TickPrecise: return "TickPrecise";
19+
case Features::NintendoSwitch_Basic: return "NintendoSwitch_Basic";
20+
case Features::NintendoSwitch_Macros: return "NintendoSwitch_Macros";
21+
case Features::NintendoSwitch_DateSkip: return "NintendoSwitch_DateSkip";
22+
}
23+
return nullptr;
24+
}
25+
26+
27+
28+
std::set<std::string> program_id_to_features(uint8_t id){
29+
switch (id){
30+
case PABB_PID_PABOTBASE_12KB:
31+
case PABB_PID_PABOTBASE_31KB:
32+
return {
33+
to_string(Features::TickPrecise),
34+
to_string(Features::NintendoSwitch_Basic),
35+
to_string(Features::NintendoSwitch_Macros),
36+
to_string(Features::NintendoSwitch_DateSkip),
37+
};
38+
}
39+
return {};
40+
}
41+
42+
43+
const std::pair<std::string, std::set<std::string>> OLD_SERIAL_DEFAULT{
44+
SerialPABotBase::INTERFACE_NAME,
45+
{
46+
to_string(SerialPABotBase::Features::TickPrecise),
47+
to_string(SerialPABotBase::Features::NintendoSwitch_Basic),
48+
to_string(SerialPABotBase::Features::NintendoSwitch_Macros),
49+
to_string(SerialPABotBase::Features::NintendoSwitch_DateSkip),
50+
}
51+
};
52+
53+
54+
55+
56+
57+
58+
59+
}
60+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/* Serial Port (PABotBase)
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_Controllers_SerialPABotBase_H
8+
#define PokemonAutomation_Controllers_SerialPABotBase_H
9+
10+
#include <stdint.h>
11+
#include <string>
12+
#include <set>
13+
#include "Common/PokemonSwSh/PokemonProgramIDs.h"
14+
15+
namespace PokemonAutomation{
16+
namespace SerialPABotBase{
17+
18+
19+
extern const char INTERFACE_NAME[];
20+
21+
22+
enum class Features{
23+
TickPrecise,
24+
NintendoSwitch_Basic,
25+
NintendoSwitch_Macros,
26+
NintendoSwitch_DateSkip,
27+
};
28+
29+
30+
const char* to_string(Features feature);
31+
32+
33+
std::set<std::string> program_id_to_features(uint8_t id);
34+
35+
extern const std::pair<std::string, std::set<std::string>> OLD_SERIAL_DEFAULT;
36+
37+
38+
39+
40+
41+
};
42+
43+
44+
45+
46+
47+
}
48+
#endif

0 commit comments

Comments
 (0)