Skip to content

Commit 2a0bbdf

Browse files
committed
Add support for joycon programs.
1 parent d50af7c commit 2a0bbdf

28 files changed

+292
-34
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,8 @@ file(GLOB MAIN_SOURCES
858858
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_SelectorWidget.h
859859
Source/NintendoSwitch/DevPrograms/BoxDraw.cpp
860860
Source/NintendoSwitch/DevPrograms/BoxDraw.h
861+
Source/NintendoSwitch/DevPrograms/JoyconProgram.cpp
862+
Source/NintendoSwitch/DevPrograms/JoyconProgram.h
861863
Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp
862864
Source/NintendoSwitch/DevPrograms/TestProgramComputer.h
863865
Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ SOURCES += \
422422
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_Descriptor.cpp \
423423
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_ProController.cpp \
424424
Source/NintendoSwitch/DevPrograms/BoxDraw.cpp \
425+
Source/NintendoSwitch/DevPrograms/JoyconProgram.cpp \
425426
Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp \
426427
Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp \
427428
Source/NintendoSwitch/Framework/NintendoSwitch_MultiSwitchProgramOption.cpp \
@@ -1595,6 +1596,7 @@ HEADERS += \
15951596
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_ProController.h \
15961597
Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_SelectorWidget.h \
15971598
Source/NintendoSwitch/DevPrograms/BoxDraw.h \
1599+
Source/NintendoSwitch/DevPrograms/JoyconProgram.h \
15981600
Source/NintendoSwitch/DevPrograms/TestProgramComputer.h \
15991601
Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h \
16001602
Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.h \

SerialPrograms/Source/Controllers/ControllerTypeStrings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const EnumStringMap<ControllerFeature> CONTROLLER_FEATURE_STRINGS{
3030
{ControllerFeature::QueryTickSize, "QueryTickSize"},
3131
{ControllerFeature::QueryCommandQueueSize, "QueryCommandQueueSize"},
3232
{ControllerFeature::NintendoSwitch_ProController, "NintendoSwitch_ProController"},
33+
{ControllerFeature::NintendoSwitch_LeftJoycon, "NintendoSwitch_LeftJoycon"},
34+
{ControllerFeature::NintendoSwitch_RightJoycon, "NintendoSwitch_RightJoycon"},
3335
{ControllerFeature::NintendoSwitch_DateSkip, "NintendoSwitch_DateSkip"},
3436
};
3537

SerialPrograms/Source/Controllers/ControllerTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ enum class ControllerFeature{
4040
QueryTickSize,
4141
QueryCommandQueueSize,
4242
NintendoSwitch_ProController,
43+
NintendoSwitch_LeftJoycon,
44+
NintendoSwitch_RightJoycon,
4345
NintendoSwitch_DateSkip,
4446
};
4547

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@ const std::map<
114114
{ControllerType::NintendoSwitch_LeftJoycon, {
115115
ControllerFeature::TickPrecise,
116116
ControllerFeature::QueryCommandQueueSize,
117+
ControllerFeature::NintendoSwitch_LeftJoycon,
117118
}},
118119
{ControllerType::NintendoSwitch_RightJoycon, {
119120
ControllerFeature::TickPrecise,
120121
ControllerFeature::QueryCommandQueueSize,
122+
ControllerFeature::NintendoSwitch_RightJoycon,
121123
}},
122124
}},
123125
}},

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,46 @@ int register_message_converters_push_button_framework(){
142142
return 0;
143143
}
144144
int init_PushButtonFramework = register_message_converters_push_button_framework();
145+
146+
147+
148+
149+
150+
151+
void pbf_wait(JoyconContext& context, Milliseconds duration){
152+
ssf_do_nothing(context, duration);
153+
}
154+
void pbf_press_button(JoyconContext& context, Button button, Milliseconds hold, Milliseconds release){
155+
ssf_press_button(context, button, hold + release, hold, 0ms);
156+
}
157+
void pbf_move_joystick(JoyconContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release){
158+
ssf_press_joystick(context, x, y, hold + release, hold, 0ms);
159+
}
160+
void pbf_mash_button(JoyconContext& context, Button button, Milliseconds duration){
161+
ssf_mash1_button(context, button, duration);
162+
}
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
179+
180+
181+
182+
183+
184+
145185

146186

147187

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define PokemonAutomation_NintendoSwitch_Commands_PushButtons_H
1919

2020
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
21+
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
2122

2223
namespace PokemonAutomation{
2324
namespace NintendoSwitch{
@@ -114,6 +115,15 @@ void pbf_controller_state(
114115

115116

116117

118+
119+
void pbf_wait (JoyconContext& context, Milliseconds duration);
120+
void pbf_press_button (JoyconContext& context, Button button, Milliseconds hold, Milliseconds release);
121+
void pbf_move_joystick (JoyconContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release);
122+
void pbf_mash_button (JoyconContext& context, Button button, Milliseconds duration);
123+
124+
125+
126+
117127
}
118128
}
119129
#endif

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ void ssf_issue_scroll(
136136

137137

138138

139+
void ssf_flush_pipeline(JoyconContext& context){
140+
context->issue_barrier(&context);
141+
}
142+
void ssf_do_nothing(JoyconContext& context, Milliseconds duration){
143+
context->issue_nop(&context, duration);
144+
}
145+
void ssf_press_button(
146+
JoyconContext& context,
147+
Button button,
148+
Milliseconds delay, Milliseconds hold, Milliseconds cool
149+
){
150+
context->issue_buttons(&context, button, delay, hold, cool);
151+
}
152+
void ssf_press_joystick(
153+
JoyconContext& context,
154+
uint8_t x, uint8_t y,
155+
Milliseconds delay, Milliseconds hold, Milliseconds cool
156+
){
157+
context->issue_joystick(&context, x, y, delay, hold, cool);
158+
}
159+
void ssf_mash1_button(JoyconContext& context, Button button, Milliseconds duration){
160+
context->issue_mash_button(&context, button, duration);
161+
}
139162

140163

141164

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define PokemonAutomation_NintendoSwitch_Commands_Superscalar_H
1717

1818
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
19-
19+
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
2020

2121
namespace PokemonAutomation{
2222
namespace NintendoSwitch{
@@ -215,6 +215,25 @@ inline void ssf_hold_joystick1(
215215

216216

217217

218+
void ssf_flush_pipeline (JoyconContext& context);
219+
void ssf_do_nothing (JoyconContext& context, Milliseconds duration);
220+
void ssf_press_button(
221+
JoyconContext& context,
222+
Button button,
223+
Milliseconds delay, Milliseconds hold = 3*15ms, Milliseconds cool = 2*15ms
224+
);
225+
void ssf_press_joystick(
226+
JoyconContext& context,
227+
uint8_t x, uint8_t y,
228+
Milliseconds delay, Milliseconds hold, Milliseconds cool = 0ms
229+
);
230+
void ssf_mash1_button (JoyconContext& context, Button button, Milliseconds duration);
231+
232+
233+
234+
235+
236+
218237
}
219238
}
220239
#endif
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Joycon Test Program
2+
*
3+
* From: https://github.com/PokemonAutomation/Arduino-Source
4+
*
5+
*/
6+
7+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
8+
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
9+
#include "JoyconProgram.h"
10+
11+
// REMOVE
12+
#include <iostream>
13+
using std::cout;
14+
using std::endl;
15+
16+
namespace PokemonAutomation{
17+
namespace NintendoSwitch{
18+
19+
20+
JoyconProgram_Descriptor::JoyconProgram_Descriptor()
21+
: SingleSwitchProgramDescriptor(
22+
"NintendoSwitch:JoyconProgram",
23+
"Nintendo Switch", "Joycon Program",
24+
"",
25+
"Template for a joycon program.",
26+
FeedbackType::NONE,
27+
AllowCommandsWhenRunning::DISABLE_COMMANDS,
28+
{ControllerFeature::NintendoSwitch_RightJoycon},
29+
FasterIfTickPrecise::NOT_FASTER
30+
)
31+
{}
32+
33+
34+
JoyconProgram::JoyconProgram(){}
35+
void JoyconProgram::program(SingleSwitchProgramEnvironment& env, CancellableScope& scope){
36+
JoyconContext context(scope, env.console.controller<JoyconController>());
37+
38+
//
39+
// Sample joycon program.
40+
//
41+
// This will start from the grip menu and enter the system settings.
42+
// Note that the joycon is horizontal.
43+
//
44+
// You can press any button, but if it doesn't exist, it won't do anything.
45+
//
46+
// No support for gyro yet. That's coming later.
47+
//
48+
49+
pbf_press_button(context, BUTTON_A, 200ms, 2000ms);
50+
pbf_press_button(context, BUTTON_HOME, 200ms, 2000ms);
51+
pbf_move_joystick(context, 128, 0, 100ms, 100ms);
52+
pbf_move_joystick(context, 128, 0, 100ms, 100ms);
53+
pbf_move_joystick(context, 255, 128, 100ms, 100ms);
54+
pbf_move_joystick(context, 128, 0, 100ms, 100ms);
55+
pbf_press_button(context, BUTTON_X, 200ms, 2000ms);
56+
57+
58+
}
59+
60+
61+
62+
63+
64+
65+
}
66+
}

0 commit comments

Comments
 (0)