Skip to content

Commit adc9439

Browse files
committed
More work on controllers refactor.
1 parent 1a3775e commit adc9439

31 files changed

+105
-55
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,9 @@ file(GLOB MAIN_SOURCES
600600
Source/ComputerPrograms/Framework/ComputerProgramSession.h
601601
Source/ComputerPrograms/Framework/ComputerProgramWidget.cpp
602602
Source/ComputerPrograms/Framework/ComputerProgramWidget.h
603-
Source/Controllers/ControllerCapabilities.h
604-
Source/Controllers/Controllers.cpp
605-
Source/Controllers/Controllers.h
603+
Source/Controllers/ControllerCapability.h
604+
Source/Controllers/ControllerDescriptor.cpp
605+
Source/Controllers/ControllerDescriptor.h
606606
Source/Controllers/ControllerConnection.cpp
607607
Source/Controllers/ControllerConnection.h
608608
Source/Controllers/ControllerSession.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ SOURCES += \
308308
Source/Controllers/ControllerConnection.cpp \
309309
Source/Controllers/ControllerSelectorWidget.cpp \
310310
Source/Controllers/ControllerSession.cpp \
311-
Source/Controllers/Controllers.cpp \
311+
Source/Controllers/ControllerDescriptor.cpp \
312312
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp \
313313
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.cpp \
314314
Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp \
@@ -1419,11 +1419,11 @@ HEADERS += \
14191419
Source/ComputerPrograms/Framework/ComputerProgramOption.h \
14201420
Source/ComputerPrograms/Framework/ComputerProgramSession.h \
14211421
Source/ComputerPrograms/Framework/ComputerProgramWidget.h \
1422-
Source/Controllers/ControllerCapabilities.h \
1422+
Source/Controllers/ControllerCapability.h \
14231423
Source/Controllers/ControllerConnection.h \
14241424
Source/Controllers/ControllerSelectorWidget.h \
14251425
Source/Controllers/ControllerSession.h \
1426-
Source/Controllers/Controllers.h \
1426+
Source/Controllers/ControllerDescriptor.h \
14271427
Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h \
14281428
Source/Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h \
14291429
Source/Controllers/SerialPABotBase/SerialPABotBase_Globals.h \

SerialPrograms/Source/CommonFramework/Panels/ProgramDescriptor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ namespace PokemonAutomation{
1414
class StatsTracker;
1515

1616

17+
18+
enum class AllowCommandsWhenRunning{
19+
DISABLE_COMMANDS,
20+
ENABLE_COMMANDS,
21+
};
22+
23+
1724
class ProgramDescriptor : public PanelDescriptor{
1825
public:
1926
using PanelDescriptor::PanelDescriptor;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <QLabel>
1212
#include "Common/Qt/CollapsibleGroupBox.h"
1313
#include "CommonFramework/Globals.h"
14-
#include "Controllers/SerialPABotBase/SerialPABotBase_Globals.h"
1514

1615
class QPushButton;
1716

SerialPrograms/Source/Controllers/ControllerCapabilities.h renamed to SerialPrograms/Source/Controllers/ControllerCapability.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
*
33
* From: https://github.com/PokemonAutomation/Arduino-Source
44
*
5+
* Represents optional features that each controller
6+
* interface may have.
7+
*
8+
* For example, PABotBase has 3 different levels:
9+
* - Not PABotBase (protocol only, no commands)
10+
* - PABotBase-12KB (basic commands only)
11+
* - PABotBase-31KB (basic commands + advanced RPC)
12+
*
13+
* This class allows programs to declare required features so that the
14+
* controller interface can error if it lacks them.
15+
*
516
*/
617

718
#ifndef PokemonAutomation_Controllers_ControllerCapabilities_H
@@ -19,7 +30,18 @@
1930
namespace PokemonAutomation{
2031

2132

22-
33+
//
34+
// This class is a double map.
35+
// The first level is keyed on a string representing the interface type. (serial, bluetooth, etc...)
36+
// The second level is a set of features for that interface type.
37+
//
38+
// Programs will specify which interfaces they support and which features are
39+
// required for each interface.
40+
//
41+
// The list of interfaces will filter which connections are shown in the UI
42+
// dropdown. The feature set will be enforced after connecting since you won't
43+
// know the feature set until after talking to the controller.
44+
//
2345
class ControllerRequirements{
2446
public:
2547
#if 0

SerialPrograms/Source/Controllers/ControllerConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "Common/Cpp/ListenerSet.h"
1111
#include "Common/Cpp/Concurrency/SpinLock.h"
12-
#include "Controllers.h"
12+
#include "ControllerDescriptor.h"
1313

1414
namespace PokemonAutomation{
1515

SerialPrograms/Source/Controllers/Controllers.cpp renamed to SerialPrograms/Source/Controllers/ControllerDescriptor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include "Common/Cpp/Json/JsonValue.h"
88
#include "Common/Cpp/Json/JsonObject.h"
9-
#include "Controllers.h"
9+
#include "ControllerDescriptor.h"
1010

1111
#include "Controllers/SerialPABotBase/SerialPABotBase_Descriptor.h"
1212
#include "ControllerConnection.h"
File renamed without changes.

SerialPrograms/Source/Controllers/ControllerSelectorWidget.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ void ControllerSelectorWidget::refresh(){
8181
m_devices_dropdown->clear();
8282

8383
m_device_list.emplace_back(new NullControllerDescriptor());
84+
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.
8488
if (true){
8589
std::vector<std::unique_ptr<const ControllerDescriptor>> serial = SerialPABotBase::get_all_devices();
8690
std::move(serial.begin(), serial.end(), std::back_inserter(m_device_list));
@@ -102,7 +106,9 @@ void ControllerSelectorWidget::refresh(){
102106

103107

104108
void ControllerSelectorWidget::controller_changed(const std::shared_ptr<const ControllerDescriptor>& descriptor){
105-
refresh();
109+
QMetaObject::invokeMethod(this, [this]{
110+
refresh();
111+
});
106112
}
107113
void ControllerSelectorWidget::status_text_changed(const std::string& text){
108114
// cout << "ControllerSelectorWidget::status_text_changed(): " << text << endl;

SerialPrograms/Source/Controllers/ControllerSession.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
*/
66

7+
#include "Common/Cpp/Exceptions.h"
78
#include "ControllerSession.h"
89

910
//#include <iostream>
@@ -82,6 +83,12 @@ std::string ControllerSession::status_text() const{
8283
}
8384
return m_connection->status_text();
8485
}
86+
ControllerConnection& ControllerSession::controller() const{
87+
if (m_connection){
88+
return *m_connection;
89+
}
90+
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Controller is null.");
91+
}
8592

8693

8794

0 commit comments

Comments
 (0)