Skip to content

Commit 29f4119

Browse files
committed
Migrate the rest of the codebase off the old controller state API.
1 parent 4ad79dc commit 29f4119

File tree

6 files changed

+53
-53
lines changed

6 files changed

+53
-53
lines changed

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ void pbf_controller_state(
107107
uint8_t right_x, uint8_t right_y,
108108
uint16_t ticks
109109
);
110-
#endif
111110
void pbf_controller_state(
112111
ProControllerContext& context,
113112
Button button,
@@ -116,6 +115,7 @@ void pbf_controller_state(
116115
uint8_t right_x, uint8_t right_y,
117116
Milliseconds duration
118117
);
118+
#endif
119119
void pbf_controller_state(
120120
ProControllerContext& context,
121121
Button button,

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_PushJoySticks.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ PushJoySticks::PushJoySticks()
4343
LockMode::LOCK_WHILE_RUNNING,
4444
0
4545
)
46-
, LEFT_X(
47-
"<b>Left Joy Stick X direction:</b><br>Range: 0-255. 0: left, 128: neutral, 255: right.",
46+
, LEFT_X0(
47+
"<b>Left Joy Stick X direction:</b><br>Range: [-1.0, 1.0.] -1: left, 0: neutral, +1: right.",
4848
LockMode::LOCK_WHILE_RUNNING,
49-
128, 0, 255
49+
0, -1, 1
5050
)
51-
, LEFT_Y(
52-
"<b>Left Joy Stick Y direction:</b><br>Range: 0-255. 0: up, 128: neutral, 255: down.",
51+
, LEFT_Y0(
52+
"<b>Left Joy Stick Y direction:</b><br>Range: [-1.0, 1.0.]. +1: up, 0: neutral, -1: down.",
5353
LockMode::LOCK_WHILE_RUNNING,
54-
128, 0, 255
54+
0, -1, 1
5555
)
56-
, RIGHT_X(
57-
"<b>Right Joy Stick X direction:</b><br>Range: 0-255. 0: left, 128: neutral, 255: right.",
56+
, RIGHT_X0(
57+
"<b>Right Joy Stick X direction:</b><br>Range: [-1.0, 1.0.] -1: left, 0: neutral, +1: right.",
5858
LockMode::LOCK_WHILE_RUNNING,
59-
128, 0, 255
59+
0, -1, 1
6060
)
61-
, RIGHT_Y(
62-
"<b>Right Joy Stick Y direction:</b><br>Range: 0-255. 0: up, 128: neutral, 255: down.",
61+
, RIGHT_Y0(
62+
"<b>Right Joy Stick Y direction:</b><br>Range: [-1.0, 1.0.]. +1: up, 0: neutral, -1: down.",
6363
LockMode::LOCK_WHILE_RUNNING,
64-
128, 0, 255
64+
0, -1, 1
6565
)
6666
, PRESS_DURATION(
6767
"<b>Press Duration:</b><br>Hold the joysticks down for this long.",
@@ -75,10 +75,10 @@ PushJoySticks::PushJoySticks()
7575
)
7676
{
7777
PA_ADD_OPTION(JOYCON_CLICK);
78-
PA_ADD_OPTION(LEFT_X);
79-
PA_ADD_OPTION(LEFT_Y);
80-
PA_ADD_OPTION(RIGHT_X);
81-
PA_ADD_OPTION(RIGHT_Y);
78+
PA_ADD_OPTION(LEFT_X0);
79+
PA_ADD_OPTION(LEFT_Y0);
80+
PA_ADD_OPTION(RIGHT_X0);
81+
PA_ADD_OPTION(RIGHT_Y0);
8282
PA_ADD_OPTION(PRESS_DURATION);
8383
PA_ADD_OPTION(RELEASE_DURATION);
8484
}
@@ -102,8 +102,12 @@ void PushJoySticks::program(SingleSwitchProgramEnvironment& env, ProControllerCo
102102
}
103103

104104
while(true){
105-
pbf_controller_state(context, button, DPAD_NONE,
106-
LEFT_X, LEFT_Y, RIGHT_X, RIGHT_Y, PRESS_DURATION);
105+
pbf_controller_state(
106+
context, button, DPAD_NONE,
107+
{LEFT_X0, LEFT_Y0},
108+
{RIGHT_X0, RIGHT_Y0},
109+
PRESS_DURATION
110+
);
107111
if (RELEASE_DURATION.get() > std::chrono::milliseconds(0)){
108112
pbf_wait(context, RELEASE_DURATION);
109113
}

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_PushJoySticks.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#ifndef PokemonAutomation_NintendoSwitch_PushJoySticks_H
88
#define PokemonAutomation_NintendoSwitch_PushJoySticks_H
99

10+
#include "Common/Cpp/Options/FloatingPointOption.h"
1011
#include "Common/Cpp/Options/EnumDropdownOption.h"
11-
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1212
#include "Common/Cpp/Options/TimeDurationOption.h"
1313
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1414

@@ -30,10 +30,10 @@ class PushJoySticks : public SingleSwitchProgramInstance{
3030

3131
private:
3232
IntegerEnumDropdownOption JOYCON_CLICK;
33-
SimpleIntegerOption<uint8_t> LEFT_X;
34-
SimpleIntegerOption<uint8_t> LEFT_Y;
35-
SimpleIntegerOption<uint8_t> RIGHT_X;
36-
SimpleIntegerOption<uint8_t> RIGHT_Y;
33+
FloatingPointOption LEFT_X0;
34+
FloatingPointOption LEFT_Y0;
35+
FloatingPointOption RIGHT_X0;
36+
FloatingPointOption RIGHT_Y0;
3737
MillisecondsOption PRESS_DURATION;
3838
MillisecondsOption RELEASE_DURATION;
3939
};

SerialPrograms/Source/PokemonLA/Programs/ShinyHunting/PokemonLA_GalladeFinder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,22 @@ void GalladeFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProContro
118118
env.console, context,
119119
[&](ProControllerContext& context){
120120
// forward portion
121-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, 6800ms); // forward while running until stairs, mash y a few times down the stairs
121+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, {0, +1}, {0, 0}, 6800ms); // forward while running until stairs, mash y a few times down the stairs
122122
pbf_mash_button(context, BUTTON_Y, 2800ms); // roll down the stairs, recover stamina
123-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, 4000ms); // forward while sprinting again
123+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, {0, +1}, {0, 0}, 4000ms); // forward while sprinting again
124124
pbf_mash_button(context, BUTTON_Y, 2000ms); // two mashes and then one y
125-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, 3800ms); // forward while sprinting again
125+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, {0, +1}, {0, 0}, 3800ms); // forward while sprinting again
126126
// basic map layout is walk forward for a while, move right, run back, then align camera, then walk left then forward to Gallade
127127

128128
// right portion
129129
pbf_move_left_joystick(context, 255, 128, 500ms, 0ms); // right alone
130-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 255, 128, 128, 128, 2400ms); // forward while running until stairs
130+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, {+1, 0}, {0, 0}, 2400ms); // forward while running until stairs
131131
pbf_mash_button(context, BUTTON_Y, 1800ms); // roll down the stairs, recover stamina
132132
pbf_move_left_joystick(context, 255, 128, 1800ms, 160ms); // right alone
133133

134134
// down portion
135135
// pbf_move_left_joystick(context, 128, 255, (uint16_t)(1.9 * TICKS_PER_SECOND), 20); // OLD down
136-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 255, 128, 128, 1800ms);
136+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, {0, -1}, {0, 0}, 1800ms);
137137

138138
// camera align
139139
pbf_press_button(context, BUTTON_ZL, 20, 0); // camera align
@@ -149,7 +149,7 @@ void GalladeFinder::run_iteration(SingleSwitchProgramEnvironment& env, ProContro
149149
pbf_move_left_joystick(context, 0, 0, 1100ms, 0ms);
150150

151151
//pbf_move_left_joystick(context, 128, 0, 3.9 * TICKS_PER_SECOND, 0); // OLD forward
152-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, 3500ms); // forward while sprinting until stairs, mash y a few times down the stairs
152+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, {0, +1}, {0, 0}, 3500ms); // forward while sprinting until stairs, mash y a few times down the stairs
153153
// we should easily be in range of gallade at this point, so if there's no shiny we're done
154154
},
155155
{{shiny_detector}}

SerialPrograms/Source/PokemonLA/Programs/ShinyHunting/PokemonLA_PostMMOSpawnReset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void PostMMOSpawnReset::run_iteration(SingleSwitchProgramEnvironment& env, ProCo
120120
pbf_move_right_joystick(context, 0, 128, -TURN_DURATION0.get(), 0ms);
121121
}
122122

123-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, FORWARD_DURATION0);
123+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, {0, +1}, {0, 0}, FORWARD_DURATION0);
124124

125125
pbf_wait(context, WAIT_DURATION0);
126126

SerialPrograms/Source/PokemonLA/Programs/ShinyHunting/PokemonLA_ShinyHunt-CustomPath.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ void ShinyHuntCustomPath::do_non_listen_action(
117117
){
118118
stream.log("Execute action " + row.action.current_display());
119119
switch(row.action){
120-
case PathAction::CHANGE_MOUNT:
121-
{
120+
case PathAction::CHANGE_MOUNT:{
122121
MountState mountState = MountState::NOTHING;
123122
switch(row.parameters.mount){
124123
case PathMount::WYRDEER:
@@ -148,27 +147,25 @@ void ShinyHuntCustomPath::do_non_listen_action(
148147
break;
149148
}
150149
#if 0
151-
case PathAction::ROTATE_CAMERA:
152-
{
150+
case PathAction::ROTATE_CAMERA:{
153151
if (row.camera_turn_ticks > 0){
154-
pbf_move_right_joystick(context, 255, 128, uint16_t(row.camera_turn_ticks), 0);
152+
pbf_move_right_joystick(context, {+1, 0}, uint16_t(row.camera_turn_ticks), 0);
155153
}else if (row.camera_turn_ticks < 0){
156-
pbf_move_right_joystick(context, 0, 128, uint16_t(-row.camera_turn_ticks), 0);
154+
pbf_move_right_joystick(context, {-1, 0}, uint16_t(-row.camera_turn_ticks), 0);
157155
}
158156
break;
159157
}
160158
#endif
161-
case PathAction::MOVE_FORWARD:
162-
{
159+
case PathAction::MOVE_FORWARD:{
163160
switch(row.parameters.move_speed){
164161
case PathSpeed::NORMAL_SPEED:
165-
pbf_move_left_joystick(context, 128, 0, row.parameters.move_forward, 0ms);
162+
pbf_move_left_joystick(context, {0, +1}, row.parameters.move_forward, 0ms);
166163
break;
167164
case PathSpeed::SLOW_SPEED:
168-
pbf_move_left_joystick(context, 128, 64, row.parameters.move_forward, 0ms);
165+
pbf_move_left_joystick(context, {0, +0.5}, row.parameters.move_forward, 0ms);
169166
break;
170167
case PathSpeed::RUN:
171-
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, 128, 0, 128, 128, row.parameters.move_forward);
168+
pbf_controller_state(context, BUTTON_LCLICK, DPAD_NONE, {0, +1}, {0, 0}, row.parameters.move_forward);
172169
break;
173170
case PathSpeed::DASH:
174171
pbf_press_button(context, BUTTON_B, row.parameters.move_forward, 0ms);
@@ -182,25 +179,24 @@ void ShinyHuntCustomPath::do_non_listen_action(
182179
}
183180
break;
184181
}
185-
case PathAction::MOVE_IN_DIRECTION:
186-
{
187-
uint8_t x = (uint8_t)((row.parameters.left_x + 1.0) * 127.5 + 0.5);
188-
uint8_t y = (uint8_t)((-row.parameters.left_y + 1.0) * 127.5 + 0.5);
189-
pbf_move_left_joystick(context, x, y, row.parameters.move_forward, 0ms);
182+
case PathAction::MOVE_IN_DIRECTION:{
183+
pbf_move_left_joystick(
184+
context,
185+
{row.parameters.left_x, row.parameters.left_y},
186+
row.parameters.move_forward,
187+
0ms
188+
);
190189
break;
191190
}
192-
case PathAction::CENTER_CAMERA:
193-
{
191+
case PathAction::CENTER_CAMERA:{
194192
pbf_mash_button(context, BUTTON_ZL, 200);
195193
break;
196194
}
197-
case PathAction::JUMP:
198-
{
195+
case PathAction::JUMP:{
199196
pbf_press_button(context, BUTTON_Y, 80ms, row.parameters.jump_wait);
200197
break;
201198
}
202-
case PathAction::WAIT:
203-
{
199+
case PathAction::WAIT:{
204200
pbf_wait(context, row.parameters.wait);
205201
break;
206202
}

0 commit comments

Comments
 (0)