Skip to content

Commit 11ea1d3

Browse files
committed
Preparations for joycon. Refactor + initial infra.
1 parent 99ba895 commit 11ea1d3

22 files changed

+1211
-473
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,14 +833,16 @@ file(GLOB MAIN_SOURCES
833833
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.h
834834
Source/NintendoSwitch/Controllers/NintendoSwitch_ProController.cpp
835835
Source/NintendoSwitch/Controllers/NintendoSwitch_ProController.h
836-
Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.cpp
837-
Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.h
836+
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.cpp
837+
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h
838838
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.cpp
839839
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h
840+
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.cpp
841+
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.h
840842
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_PokkenController.cpp
841843
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_PokkenController.h
842-
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_ProController.cpp
843-
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_ProController.h
844+
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessController.cpp
845+
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessController.h
844846
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessProController.cpp
845847
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessProController.h
846848
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,11 @@ SOURCES += \
410410
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerState.cpp \
411411
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.cpp \
412412
Source/NintendoSwitch/Controllers/NintendoSwitch_ProController.cpp \
413-
Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.cpp \
413+
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.cpp \
414414
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.cpp \
415+
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.cpp \
415416
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_PokkenController.cpp \
416-
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_ProController.cpp \
417+
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessController.cpp \
417418
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessProController.cpp \
418419
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.cpp \
419420
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.cpp \
@@ -1579,10 +1580,11 @@ HEADERS += \
15791580
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerState.h \
15801581
Source/NintendoSwitch/Controllers/NintendoSwitch_KeyboardMapping.h \
15811582
Source/NintendoSwitch/Controllers/NintendoSwitch_ProController.h \
1582-
Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.h \
1583+
Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h \
15831584
Source/NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h \
1585+
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Controller.h \
15841586
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_PokkenController.h \
1585-
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_ProController.h \
1587+
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessController.h \
15861588
Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessProController.h \
15871589
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h \
15881590
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.h \

SerialPrograms/Source/Controllers/Controller.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ class AbstractController{
8383
virtual void replace_on_next_command() = 0;
8484

8585

86+
public:
87+
//
88+
// Commands
89+
//
90+
// Commands are actions like button presses or joystick movements that are
91+
// eventually sent to the console.
92+
//
93+
// All commands are prefixed with "issue_".
94+
// Commands are not thread-safe with other commands.
95+
// Commands are thread-safe with the cancellation functions above.
96+
//
97+
// Commands are asynchronous. When you call a command function on this,
98+
// class it gets enqueued into a FIFO and immediately returns. It will only
99+
// block if the FIFO is full.
100+
//
101+
// If a command is called with a cancelled "cancellable" parameter, it will
102+
// throw an OperationCancelledException.
103+
// If a cancellation happens while you are inside a command function, it
104+
// will immediately stop and throw an OperationCancelledException.
105+
//
106+
107+
86108
public:
87109
//
88110
// Superscalar Commands (the "ssf" framework)

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerState.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,32 @@ constexpr uint16_t TICKS_PER_SECOND = 125;
2020

2121

2222
// Buttons
23-
constexpr size_t TOTAL_BUTTONS = 18;
23+
constexpr size_t TOTAL_BUTTONS = 22;
2424
using ButtonFlagType = uint32_t;
2525
enum Button : ButtonFlagType{
2626
BUTTON_NONE = 0,
27-
BUTTON_Y = ((uint16_t)1 << 0),
28-
BUTTON_B = ((uint16_t)1 << 1),
29-
BUTTON_A = ((uint16_t)1 << 2),
30-
BUTTON_X = ((uint16_t)1 << 3),
31-
BUTTON_L = ((uint16_t)1 << 4),
32-
BUTTON_R = ((uint16_t)1 << 5),
33-
BUTTON_ZL = ((uint16_t)1 << 6),
34-
BUTTON_ZR = ((uint16_t)1 << 7),
35-
BUTTON_MINUS = ((uint16_t)1 << 8),
36-
BUTTON_PLUS = ((uint16_t)1 << 9),
37-
BUTTON_LCLICK = ((uint16_t)1 << 10),
38-
BUTTON_RCLICK = ((uint16_t)1 << 11),
39-
BUTTON_HOME = ((uint16_t)1 << 12),
40-
BUTTON_CAPTURE = ((uint16_t)1 << 13),
41-
BUTTON_UP = ((uint16_t)1 << 14),
42-
BUTTON_RIGHT = ((uint16_t)1 << 15),
43-
BUTTON_DOWN = ((uint16_t)1 << 16),
44-
BUTTON_LEFT = ((uint16_t)1 << 17),
45-
BUTTON_LEFT_SL = ((uint16_t)1 << 18),
46-
BUTTON_LEFT_SR = ((uint16_t)1 << 19),
47-
BUTTON_RIGHT_SL = ((uint16_t)1 << 20),
48-
BUTTON_RIGHT_SR = ((uint16_t)1 << 21),
27+
BUTTON_Y = ((uint32_t)1 << 0),
28+
BUTTON_B = ((uint32_t)1 << 1),
29+
BUTTON_A = ((uint32_t)1 << 2),
30+
BUTTON_X = ((uint32_t)1 << 3),
31+
BUTTON_L = ((uint32_t)1 << 4),
32+
BUTTON_R = ((uint32_t)1 << 5),
33+
BUTTON_ZL = ((uint32_t)1 << 6),
34+
BUTTON_ZR = ((uint32_t)1 << 7),
35+
BUTTON_MINUS = ((uint32_t)1 << 8),
36+
BUTTON_PLUS = ((uint32_t)1 << 9),
37+
BUTTON_LCLICK = ((uint32_t)1 << 10),
38+
BUTTON_RCLICK = ((uint32_t)1 << 11),
39+
BUTTON_HOME = ((uint32_t)1 << 12),
40+
BUTTON_CAPTURE = ((uint32_t)1 << 13),
41+
BUTTON_UP = ((uint32_t)1 << 14),
42+
BUTTON_RIGHT = ((uint32_t)1 << 15),
43+
BUTTON_DOWN = ((uint32_t)1 << 16),
44+
BUTTON_LEFT = ((uint32_t)1 << 17),
45+
BUTTON_LEFT_SL = ((uint32_t)1 << 18),
46+
BUTTON_LEFT_SR = ((uint32_t)1 << 19),
47+
BUTTON_RIGHT_SL = ((uint32_t)1 << 20),
48+
BUTTON_RIGHT_SR = ((uint32_t)1 << 21),
4949
};
5050
inline Button operator|(Button x, Button y){
5151
return (Button)((ButtonFlagType)x | (ButtonFlagType)y);

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.cpp renamed to SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*/
99

10-
#include "NintendoSwitch_ProControllerWithScheduler.h"
10+
#include "NintendoSwitch_ControllerWithScheduler.h"
1111

1212
namespace PokemonAutomation{
1313
namespace NintendoSwitch{
@@ -17,7 +17,7 @@ using namespace std::chrono_literals;
1717

1818

1919

20-
ProControllerWithScheduler::ProControllerWithScheduler(Logger& logger)
20+
ControllerWithScheduler::ControllerWithScheduler(Logger& logger)
2121
: SuperscalarScheduler(
2222
logger, Milliseconds(4),
2323
make_resource_list()
@@ -28,15 +28,15 @@ ProControllerWithScheduler::ProControllerWithScheduler(Logger& logger)
2828

2929

3030

31-
void ProControllerWithScheduler::issue_barrier(const Cancellable* cancellable){
31+
void ControllerWithScheduler::issue_barrier(const Cancellable* cancellable){
3232
std::lock_guard<std::mutex> lg0(m_issue_lock);
3333
std::lock_guard<std::mutex> lg1(m_state_lock);
3434
this->issue_wait_for_all(cancellable);
3535
if (m_logging_suppress.load(std::memory_order_relaxed) == 0){
3636
m_logger.log("issue_barrier()", COLOR_DARKGREEN);
3737
}
3838
}
39-
void ProControllerWithScheduler::issue_nop(const Cancellable* cancellable, Milliseconds duration){
39+
void ControllerWithScheduler::issue_nop(const Cancellable* cancellable, Milliseconds duration){
4040
std::lock_guard<std::mutex> lg0(m_issue_lock);
4141
std::lock_guard<std::mutex> lg1(m_state_lock);
4242
if (cancellable){
@@ -50,7 +50,7 @@ void ProControllerWithScheduler::issue_nop(const Cancellable* cancellable, Milli
5050
);
5151
}
5252
}
53-
void ProControllerWithScheduler::issue_buttons(
53+
void ControllerWithScheduler::issue_buttons(
5454
const Cancellable* cancellable,
5555
Button button,
5656
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
@@ -88,7 +88,7 @@ void ProControllerWithScheduler::issue_buttons(
8888
);
8989
}
9090
}
91-
void ProControllerWithScheduler::issue_dpad(
91+
void ControllerWithScheduler::issue_dpad(
9292
const Cancellable* cancellable,
9393
DpadPosition position,
9494
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
@@ -113,7 +113,7 @@ void ProControllerWithScheduler::issue_dpad(
113113
);
114114
}
115115
}
116-
void ProControllerWithScheduler::issue_left_joystick(
116+
void ControllerWithScheduler::issue_left_joystick(
117117
const Cancellable* cancellable,
118118
uint8_t x, uint8_t y,
119119
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
@@ -140,7 +140,7 @@ void ProControllerWithScheduler::issue_left_joystick(
140140
);
141141
}
142142
}
143-
void ProControllerWithScheduler::issue_right_joystick(
143+
void ControllerWithScheduler::issue_right_joystick(
144144
const Cancellable* cancellable,
145145
uint8_t x, uint8_t y,
146146
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
@@ -166,7 +166,7 @@ void ProControllerWithScheduler::issue_right_joystick(
166166
);
167167
}
168168
}
169-
void ProControllerWithScheduler::issue_full_controller_state(
169+
void ControllerWithScheduler::issue_full_controller_state(
170170
const Cancellable* cancellable,
171171
Button button,
172172
DpadPosition position,
@@ -231,7 +231,7 @@ void ProControllerWithScheduler::issue_full_controller_state(
231231
}
232232

233233

234-
void ProControllerWithScheduler::issue_mash_button(
234+
void ControllerWithScheduler::issue_mash_button(
235235
const Cancellable* cancellable,
236236
Button button, Milliseconds duration
237237
){
@@ -259,7 +259,7 @@ void ProControllerWithScheduler::issue_mash_button(
259259
log = false;
260260
}
261261
}
262-
void ProControllerWithScheduler::issue_mash_button(
262+
void ControllerWithScheduler::issue_mash_button(
263263
const Cancellable* cancellable,
264264
Button button0, Button button1, Milliseconds duration
265265
){
@@ -287,7 +287,7 @@ void ProControllerWithScheduler::issue_mash_button(
287287
log = false;
288288
}
289289
}
290-
void ProControllerWithScheduler::issue_mash_AZs(
290+
void ControllerWithScheduler::issue_mash_AZs(
291291
const Cancellable* cancellable,
292292
Milliseconds duration
293293
){
@@ -327,7 +327,7 @@ void ProControllerWithScheduler::issue_mash_AZs(
327327
duration -= std::min(3*8ms, duration);
328328
}
329329
}
330-
void ProControllerWithScheduler::issue_system_scroll(
330+
void ControllerWithScheduler::issue_system_scroll(
331331
const Cancellable* cancellable,
332332
DpadPosition direction, // Diagonals not allowed.
333333
Milliseconds delay, Milliseconds hold, Milliseconds cooldown

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.h renamed to SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212

1313
#include <mutex>
1414
#include "Controllers/SuperscalarScheduler.h"
15-
#include "NintendoSwitch_ProController.h"
15+
#include "NintendoSwitch_ControllerState.h"
1616

1717
namespace PokemonAutomation{
1818
namespace NintendoSwitch{
1919

2020

2121

22-
2322
struct SwitchButton_Dpad : public ExecutionResource{
2423
DpadPosition position;
2524
};
@@ -97,74 +96,69 @@ inline SplitDpad convert_unified_to_split_dpad(DpadPosition dpad){
9796

9897

9998

100-
class ProControllerWithScheduler :
101-
public ProController,
99+
class ControllerWithScheduler :
102100
protected ProControllerSchedulerState,
103101
protected SuperscalarScheduler
104102
{
105103
public:
106-
ProControllerWithScheduler(Logger& logger);
107-
108-
virtual Logger& logger() override{
109-
return m_logger;
110-
}
104+
ControllerWithScheduler(Logger& logger);
111105

112106

113107
public:
114108
// Superscalar Commands (the "ssf" framework)
115109

116-
virtual void issue_barrier(const Cancellable* cancellable) override;
117-
virtual void issue_nop(const Cancellable* cancellable, Milliseconds duration) override;
118-
virtual void issue_buttons(
110+
void issue_barrier(const Cancellable* cancellable);
111+
void issue_nop(const Cancellable* cancellable, Milliseconds duration);
112+
void issue_buttons(
119113
const Cancellable* cancellable,
120114
Button button,
121115
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
122-
) override;
123-
virtual void issue_dpad(
116+
);
117+
void issue_dpad(
124118
const Cancellable* cancellable,
125119
DpadPosition position,
126120
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
127-
) override;
128-
virtual void issue_left_joystick(
121+
);
122+
void issue_left_joystick(
129123
const Cancellable* cancellable,
130124
uint8_t x, uint8_t y,
131125
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
132-
) override;
133-
virtual void issue_right_joystick(
126+
);
127+
void issue_right_joystick(
134128
const Cancellable* cancellable,
135129
uint8_t x, uint8_t y,
136130
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
137-
) override;
138-
virtual void issue_full_controller_state(
131+
);
132+
void issue_full_controller_state(
139133
const Cancellable* cancellable,
140134
Button button,
141135
DpadPosition position,
142136
uint8_t left_x, uint8_t left_y,
143137
uint8_t right_x, uint8_t right_y,
144138
Milliseconds hold
145-
) override;
139+
);
146140

147141

148142
public:
149143
// High speed RPCs.
150144

151-
virtual void issue_mash_button(
145+
void issue_mash_button(
152146
const Cancellable* cancellable,
153147
Button button, Milliseconds duration
154-
) override;
155-
virtual void issue_mash_button(
148+
);
149+
void issue_mash_button(
156150
const Cancellable* cancellable,
157151
Button button0, Button button1, Milliseconds duration
158-
) override;
159-
virtual void issue_mash_AZs(
152+
);
153+
void issue_mash_AZs(
160154
const Cancellable* cancellable,
161155
Milliseconds duration
162-
) override;
163-
virtual void issue_system_scroll(
156+
);
157+
void issue_system_scroll(
164158
const Cancellable* cancellable,
165159
DpadPosition direction, // Diagonals not allowed.
166160
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
167-
) override;
161+
);
168162

169163

170164
protected:

0 commit comments

Comments
 (0)