Skip to content

Commit 4439cb8

Browse files
committed
Move controllers into their own folders.
1 parent 3380ec5 commit 4439cb8

File tree

164 files changed

+995
-870
lines changed

Some content is hidden

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

164 files changed

+995
-870
lines changed

SerialPrograms/Source/Integrations/ProgramTracker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "CommonFramework/ImageTypes/ImageRGB32.h"
99
#include "CommonFramework/VideoPipeline/VideoFeed.h"
1010
#include "Controllers/ControllerSession.h"
11-
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
11+
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
1212
#include "ProgramTracker.h"
1313

1414
//#include <iostream>

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#ifndef PokemonAutomation_NintendoSwitch_Commands_PushButtons_H
1818
#define PokemonAutomation_NintendoSwitch_Commands_PushButtons_H
1919

20-
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
21-
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
20+
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
21+
#include "NintendoSwitch/Controllers/Joycon/NintendoSwitch_Joycon.h"
2222

2323
namespace PokemonAutomation{
2424
namespace NintendoSwitch{

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#ifndef PokemonAutomation_NintendoSwitch_Commands_Superscalar_H
1616
#define PokemonAutomation_NintendoSwitch_Commands_Superscalar_H
1717

18-
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
19-
#include "NintendoSwitch/Controllers/NintendoSwitch_Joycon.h"
18+
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
19+
#include "NintendoSwitch/Controllers/Joycon/NintendoSwitch_Joycon.h"
2020

2121
namespace PokemonAutomation{
2222
namespace NintendoSwitch{

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_Joycon.cpp renamed to SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_Joycon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "Controllers/ControllerTypes.h"
1111
#include "Controllers/KeyboardInput/KeyboardInput.h"
1212
#include "NintendoSwitch/NintendoSwitch_Settings.h"
13-
#include "NintendoSwitch_VirtualControllerState.h"
13+
#include "NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h"
1414
#include "NintendoSwitch_JoyconState.h"
1515
#include "NintendoSwitch_Joycon.h"
1616

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_Joycon.h renamed to SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_Joycon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define PokemonAutomation_NintendoSwitch_Joycon_H
99

1010
#include "Common/Cpp/Containers/Pimpl.h"
11-
#include "NintendoSwitch_ControllerButtons.h"
11+
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h"
1212
#include "Controllers/ControllerTypes.h"
1313
#include "Controllers/Controller.h"
1414

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/* Nintendo Switch Joycon State
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "Common/Cpp/Json/JsonObject.h"
8+
#include "NintendoSwitch_Joycon.h"
9+
#include "NintendoSwitch_JoyconState.h"
10+
11+
namespace PokemonAutomation{
12+
namespace NintendoSwitch{
13+
14+
15+
16+
17+
18+
void JoyconState::clear(){
19+
buttons = BUTTON_NONE;
20+
joystick_x = 128;
21+
joystick_y = 128;
22+
}
23+
bool JoyconState::operator==(const ControllerState& x) const{
24+
if (typeid(*this) != typeid(x)){
25+
return false;
26+
}
27+
28+
const JoyconState& r = static_cast<const JoyconState&>(x);
29+
30+
if (buttons != r.buttons){
31+
return false;
32+
}
33+
if (joystick_x != r.joystick_x){
34+
return false;
35+
}
36+
if (joystick_y != r.joystick_y){
37+
return false;
38+
}
39+
return true;
40+
}
41+
bool JoyconState::is_neutral() const{
42+
return buttons == 0
43+
&& joystick_x == 128
44+
&& joystick_y == 128;
45+
}
46+
47+
void JoyconState::load_json(const JsonObject& json){
48+
clear();
49+
50+
// Backwards compatibility.
51+
if (json.get_boolean_default("is_neutral", false)){
52+
return;
53+
}
54+
55+
{
56+
std::string buttons_string;
57+
json.read_string(buttons_string, "buttons");
58+
buttons = string_to_button(buttons_string);
59+
}
60+
61+
// Backwards compatibility.
62+
json.read_integer(joystick_x, "joystick_x", 0, 255);
63+
json.read_integer(joystick_y, "joystick_y", 0, 255);
64+
65+
json.read_integer(joystick_x, "jx", 0, 255);
66+
json.read_integer(joystick_y, "jy", 0, 255);
67+
}
68+
JsonObject JoyconState::to_json() const{
69+
JsonObject obj;
70+
if (buttons != BUTTON_NONE){
71+
obj["buttons"] = button_to_string(buttons);
72+
}
73+
if (joystick_x != STICK_CENTER || joystick_y != STICK_CENTER){
74+
obj["jx"] = joystick_x;
75+
obj["jy"] = joystick_y;
76+
}
77+
return obj;
78+
}
79+
void JoyconState::execute(
80+
CancellableScope& scope,
81+
AbstractController& controller,
82+
Milliseconds duration
83+
) const{
84+
static_cast<JoyconController&>(controller).issue_full_controller_state(
85+
&scope,
86+
true,
87+
duration,
88+
buttons,
89+
joystick_x, joystick_y
90+
);
91+
}
92+
std::string JoyconState::to_cpp(Milliseconds hold, Milliseconds release) const{
93+
uint8_t non_neutral_field = 0;
94+
size_t non_neutral_fields = 0;
95+
do{
96+
if (buttons != BUTTON_NONE){
97+
non_neutral_field = 0;
98+
non_neutral_fields++;
99+
}
100+
if (joystick_x != STICK_CENTER || joystick_y != STICK_CENTER){
101+
non_neutral_field = 1;
102+
non_neutral_fields++;
103+
}
104+
}while (false);
105+
106+
if (non_neutral_fields == 0){
107+
return "pbf_wait(context, " + std::to_string((hold + release).count()) + ");\n";
108+
}
109+
110+
std::string hold_str = std::to_string(hold.count()) + "ms";
111+
std::string release_str = std::to_string(release.count()) + "ms";
112+
113+
if (non_neutral_fields > 1){
114+
std::string ret;
115+
ret += "pbf_controller_state(context, "
116+
+ button_to_code_string(buttons) + ", "
117+
+ std::to_string(joystick_x) + ", " + std::to_string(joystick_y) + ", "
118+
+ hold_str +");\n";
119+
if (release != Milliseconds(0)){
120+
ret += "pbf_wait(context, " + release_str + ");\n";
121+
}
122+
return ret;
123+
}
124+
switch (non_neutral_field){
125+
case 0:
126+
return "pbf_press_button(context, "
127+
+ button_to_code_string(buttons) + ", "
128+
+ hold_str + ", " + release_str + ");\n";
129+
case 1:
130+
return "pbf_move_joystick(context, "
131+
+ std::to_string(joystick_x) + ", " + std::to_string(joystick_y) + ", "
132+
+ hold_str + ", " + release_str + ");\n";
133+
}
134+
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Impossible state.");
135+
}
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
150+
151+
}
152+
}
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
169+

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_JoyconState.h renamed to SerialPrograms/Source/NintendoSwitch/Controllers/Joycon/NintendoSwitch_JoyconState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define PokemonAutomation_NintendoSwitch_JoyconState_H
99

1010
#include "Controllers/ControllerState.h"
11-
#include "NintendoSwitch_ControllerButtons.h"
11+
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h"
1212

1313
namespace PokemonAutomation{
1414
namespace NintendoSwitch{

0 commit comments

Comments
 (0)