Skip to content

Commit 21511a4

Browse files
committed
Add float joysticks to pbf and ssf.
1 parent 6e09d45 commit 21511a4

File tree

9 files changed

+164
-144
lines changed

9 files changed

+164
-144
lines changed

SerialPrograms/Source/Integrations/ProgramTracker.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "CommonFramework/Logging/Logger.h"
88
#include "CommonFramework/ImageTypes/ImageRGB32.h"
99
#include "CommonFramework/VideoPipeline/VideoFeed.h"
10+
#include "Controllers/JoystickTools.h"
1011
#include "Controllers/ControllerSession.h"
1112
#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h"
1213
#include "ProgramTracker.h"
@@ -185,7 +186,13 @@ std::string ProgramTracker::nsw_press_left_joystick(uint64_t console_id, uint8_t
185186
try{
186187
err = iter->second.first->controller().try_run<ProController>(
187188
[=](ProController& controller){
188-
controller.issue_left_joystick(nullptr, duration, duration, 0ms, x, y);
189+
controller.issue_left_joystick(
190+
nullptr, duration, duration, 0ms,
191+
{
192+
JoystickTools::linear_u8_to_float(x),
193+
-JoystickTools::linear_u8_to_float(y)
194+
}
195+
);
189196
}
190197
);
191198
}catch (Exception& e){
@@ -215,7 +222,13 @@ std::string ProgramTracker::nsw_press_right_joystick(uint64_t console_id, uint8_
215222
try{
216223
err = iter->second.first->controller().try_run<ProController>(
217224
[=](ProController& controller){
218-
controller.issue_right_joystick(nullptr, duration, duration, 0ms, x, y);
225+
controller.issue_right_joystick(
226+
nullptr, duration, duration, 0ms,
227+
{
228+
JoystickTools::linear_u8_to_float(x),
229+
-JoystickTools::linear_u8_to_float(y)
230+
}
231+
);
219232
}
220233
);
221234
}catch (Exception& e){

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.cpp

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

7+
#include "Controllers/JoystickTools.h"
78
#include "NintendoSwitch/NintendoSwitch_Settings.h"
89
#include "NintendoSwitch_Commands_PushButtons.h"
910
#include "NintendoSwitch_Commands_Superscalar.h"
@@ -42,6 +43,9 @@ void pbf_move_left_joystick(ProControllerContext& context, uint8_t x, uint8_t y,
4243
void pbf_move_left_joystick (ProControllerContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release){
4344
ssf_press_left_joystick(context, x, y, hold + release, hold, 0ms);
4445
}
46+
void pbf_move_left_joystick(ProControllerContext& context, const JoystickPosition& position, Milliseconds hold, Milliseconds release){
47+
ssf_press_left_joystick(context, position, hold + release, hold, 0ms);
48+
}
4549
void pbf_move_right_joystick(ProControllerContext& context, uint8_t x, uint8_t y, uint16_t hold_ticks, uint16_t release_ticks){
4650
uint32_t delay = (uint32_t)hold_ticks + release_ticks;
4751
if ((uint16_t)delay == delay){
@@ -54,6 +58,9 @@ void pbf_move_right_joystick(ProControllerContext& context, uint8_t x, uint8_t y
5458
void pbf_move_right_joystick (ProControllerContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release){
5559
ssf_press_right_joystick(context, x, y, hold + release, hold, 0ms);
5660
}
61+
void pbf_move_right_joystick(ProControllerContext& context, const JoystickPosition& position, Milliseconds hold, Milliseconds release){
62+
ssf_press_right_joystick(context, position, hold + release, hold, 0ms);
63+
}
5764
void pbf_mash_button(ProControllerContext& context, Button button, uint16_t ticks){
5865
ssf_mash1_button(context, button, ticks);
5966
}
@@ -81,8 +88,14 @@ void pbf_controller_state(
8188
true,
8289
ticks*8ms,
8390
button, position,
84-
left_x, left_y,
85-
right_x, right_y
91+
{
92+
JoystickTools::linear_u8_to_float(left_x),
93+
-JoystickTools::linear_u8_to_float(left_y)
94+
},
95+
{
96+
JoystickTools::linear_u8_to_float(right_x),
97+
-JoystickTools::linear_u8_to_float(right_y)
98+
}
8699
);
87100
}
88101
void pbf_controller_state(
@@ -98,8 +111,31 @@ void pbf_controller_state(
98111
true,
99112
duration,
100113
button, position,
101-
left_x, left_y,
102-
right_x, right_y
114+
{
115+
JoystickTools::linear_u8_to_float(left_x),
116+
-JoystickTools::linear_u8_to_float(left_y)
117+
},
118+
{
119+
JoystickTools::linear_u8_to_float(right_x),
120+
-JoystickTools::linear_u8_to_float(right_y)
121+
}
122+
);
123+
}
124+
void pbf_controller_state(
125+
ProControllerContext& context,
126+
Button button,
127+
DpadPosition position,
128+
const JoystickPosition& left_joystick,
129+
const JoystickPosition& right_joystick,
130+
Milliseconds duration
131+
){
132+
context->issue_full_controller_state(
133+
&context,
134+
true,
135+
duration,
136+
button, position,
137+
left_joystick,
138+
right_joystick
103139
);
104140
}
105141

@@ -115,6 +151,9 @@ void pbf_press_button(JoyconContext& context, Button button, Milliseconds hold,
115151
void pbf_move_joystick(JoyconContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release){
116152
ssf_press_joystick(context, x, y, hold + release, hold, 0ms);
117153
}
154+
void pbf_move_joystick(JoyconContext& context, const JoystickPosition& position, Milliseconds hold, Milliseconds release){
155+
ssf_press_joystick(context, position, hold + release, hold, 0ms);
156+
}
118157
void pbf_mash_button(JoyconContext& context, Button button, Milliseconds duration){
119158
ssf_mash1_button(context, button, duration);
120159
}
@@ -130,10 +169,26 @@ void pbf_controller_state(
130169
true,
131170
duration,
132171
button,
133-
x, y
172+
{
173+
JoystickTools::linear_u8_to_float(x),
174+
-JoystickTools::linear_u8_to_float(y)
175+
}
176+
);
177+
}
178+
void pbf_controller_state(
179+
JoyconContext& context,
180+
Button button,
181+
const JoystickPosition& joystick,
182+
Milliseconds duration
183+
){
184+
context->issue_full_controller_state(
185+
&context,
186+
true,
187+
duration,
188+
button,
189+
joystick
134190
);
135191
}
136-
137192

138193

139194

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void pbf_press_dpad (ProControllerContext& context, DpadPosition position, M
5555
// move the joystick upper-right: (x, y) = (255, 0)
5656
void pbf_move_left_joystick (ProControllerContext& context, uint8_t x, uint8_t y, uint16_t hold_ticks, uint16_t release_ticks);
5757
void pbf_move_left_joystick (ProControllerContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release);
58+
void pbf_move_left_joystick (ProControllerContext& context, const JoystickPosition& position, Milliseconds hold, Milliseconds release);
5859

5960
// Move right joystick towards a 2D direction. Hold the direction for `hold_ticks`, then release it for `release_ticks`.
6061
// The direction is specified by (x, y):
@@ -66,8 +67,9 @@ void pbf_move_left_joystick (ProControllerContext& context, uint8_t x, uint8_t y
6667
// y = 255 : down
6768
// Example: move the joystick fully left: (x, y) = (0, 128)
6869
// move the joystick upper-right: (x, y) = (255, 0)
69-
void pbf_move_right_joystick (ProControllerContext& context, uint8_t x, uint8_t y, uint16_t hold_ticks, uint16_t release_ticks);
70-
void pbf_move_right_joystick (ProControllerContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release);
70+
void pbf_move_right_joystick(ProControllerContext& context, uint8_t x, uint8_t y, uint16_t hold_ticks, uint16_t release_ticks);
71+
void pbf_move_right_joystick(ProControllerContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release);
72+
void pbf_move_right_joystick(ProControllerContext& context, const JoystickPosition& position, Milliseconds hold, Milliseconds release);
7173

7274
// Mash a Switch controller button (excluding D-Pad) repeatedly for `ticks` ticks.
7375
// The buttons are defined in Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h. Examples include BUTTON_A, BUTTON_ZL.
@@ -112,19 +114,28 @@ void pbf_controller_state(
112114
uint8_t right_x, uint8_t right_y,
113115
Milliseconds duration
114116
);
117+
void pbf_controller_state(
118+
ProControllerContext& context,
119+
Button button,
120+
DpadPosition position,
121+
const JoystickPosition& left_joystick,
122+
const JoystickPosition& right_joystick,
123+
Milliseconds duration
124+
);
115125

116126

117127

118128

119129
void pbf_wait (JoyconContext& context, Milliseconds duration);
120130
void pbf_press_button (JoyconContext& context, Button button, Milliseconds hold, Milliseconds release);
121131
void pbf_move_joystick (JoyconContext& context, uint8_t x, uint8_t y, Milliseconds hold, Milliseconds release);
132+
void pbf_move_joystick (JoyconContext& context, const JoystickPosition& position, Milliseconds hold, Milliseconds release);
122133
void pbf_mash_button (JoyconContext& context, Button button, Milliseconds duration);
123134

124135
void pbf_controller_state(
125136
JoyconContext& context,
126137
Button button,
127-
uint8_t x, uint8_t y,
138+
const JoystickPosition& joystick,
128139
Milliseconds duration
129140
);
130141

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.cpp

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

7+
#include "Controllers/JoystickTools.h"
78
#include "NintendoSwitch_Commands_Superscalar.h"
89
//#include "NintendoSwitch_Messages_Superscalar.h"
910

@@ -68,15 +69,31 @@ void ssf_press_left_joystick(
6869
context->issue_left_joystick(
6970
&context,
7071
delay*8ms, hold*8ms, cool*8ms,
71-
x, y
72+
{
73+
JoystickTools::linear_u8_to_float(x),
74+
-JoystickTools::linear_u8_to_float(y)
75+
}
7276
);
7377
}
7478
void ssf_press_left_joystick(
7579
ProControllerContext& context,
7680
uint8_t x, uint8_t y,
7781
Milliseconds delay, Milliseconds hold, Milliseconds cool
7882
){
79-
context->issue_left_joystick(&context, delay, hold, cool, x, y);
83+
context->issue_left_joystick(
84+
&context, delay, hold, cool,
85+
{
86+
JoystickTools::linear_u8_to_float(x),
87+
-JoystickTools::linear_u8_to_float(y)
88+
}
89+
);
90+
}
91+
void ssf_press_left_joystick(
92+
ProControllerContext& context,
93+
const JoystickPosition& position,
94+
Milliseconds delay, Milliseconds hold, Milliseconds cool
95+
){
96+
context->issue_left_joystick(&context, delay, hold, cool, position);
8097
}
8198
void ssf_press_right_joystick(
8299
ProControllerContext& context,
@@ -86,15 +103,31 @@ void ssf_press_right_joystick(
86103
context->issue_right_joystick(
87104
&context,
88105
delay*8ms, hold*8ms, cool*8ms,
89-
x, y
106+
{
107+
JoystickTools::linear_u8_to_float(x),
108+
-JoystickTools::linear_u8_to_float(y)
109+
}
90110
);
91111
}
92112
void ssf_press_right_joystick(
93113
ProControllerContext& context,
94114
uint8_t x, uint8_t y,
95115
Milliseconds delay, Milliseconds hold, Milliseconds cool
96116
){
97-
context->issue_right_joystick(&context, delay, hold, cool, x, y);
117+
context->issue_right_joystick(
118+
&context, delay, hold, cool,
119+
{
120+
JoystickTools::linear_u8_to_float(x),
121+
-JoystickTools::linear_u8_to_float(y)
122+
}
123+
);
124+
}
125+
void ssf_press_right_joystick(
126+
ProControllerContext& context,
127+
const JoystickPosition& position,
128+
Milliseconds delay, Milliseconds hold, Milliseconds cool
129+
){
130+
context->issue_right_joystick(&context, delay, hold, cool, position);
98131
}
99132

100133

@@ -164,7 +197,20 @@ void ssf_press_joystick(
164197
uint8_t x, uint8_t y,
165198
Milliseconds delay, Milliseconds hold, Milliseconds cool
166199
){
167-
context->issue_joystick(&context, delay, hold, cool, x, y);
200+
context->issue_joystick(
201+
&context, delay, hold, cool,
202+
{
203+
JoystickTools::linear_u8_to_float(x),
204+
-JoystickTools::linear_u8_to_float(y)
205+
}
206+
);
207+
}
208+
void ssf_press_joystick(
209+
JoyconContext& context,
210+
const JoystickPosition& position,
211+
Milliseconds delay, Milliseconds hold, Milliseconds cool
212+
){
213+
context->issue_joystick(&context, delay, hold, cool, position);
168214
}
169215
void ssf_mash1_button(JoyconContext& context, Button button, Milliseconds duration){
170216
context->issue_mash_button(&context, button, duration);
@@ -183,28 +229,28 @@ void ssf_issue_scroll(
183229
){
184230
switch (direction){
185231
case DpadPosition::DPAD_UP:
186-
ssf_press_joystick(context, 128, 0, delay, hold, cool);
232+
ssf_press_joystick(context, {0, +1}, delay, hold, cool);
187233
break;
188234
case DpadPosition::DPAD_UP_RIGHT:
189-
ssf_press_joystick(context, 255, 0, delay, hold, cool);
235+
ssf_press_joystick(context, {+1, +1}, delay, hold, cool);
190236
break;
191237
case DpadPosition::DPAD_RIGHT:
192-
ssf_press_joystick(context, 255, 128, delay, hold, cool);
238+
ssf_press_joystick(context, {+1, 0}, delay, hold, cool);
193239
break;
194240
case DpadPosition::DPAD_DOWN_RIGHT:
195-
ssf_press_joystick(context, 255, 255, delay, hold, cool);
241+
ssf_press_joystick(context, {+1, -1}, delay, hold, cool);
196242
break;
197243
case DpadPosition::DPAD_DOWN:
198-
ssf_press_joystick(context, 128, 255, delay, hold, cool);
244+
ssf_press_joystick(context, {0, -1}, delay, hold, cool);
199245
break;
200246
case DpadPosition::DPAD_DOWN_LEFT:
201-
ssf_press_joystick(context, 0, 255, delay, hold, cool);
247+
ssf_press_joystick(context, {-1, -1}, delay, hold, cool);
202248
break;
203249
case DpadPosition::DPAD_LEFT:
204-
ssf_press_joystick(context, 0, 128, delay, hold, cool);
250+
ssf_press_joystick(context, {-1, 0}, delay, hold, cool);
205251
break;
206252
case DpadPosition::DPAD_UP_LEFT:
207-
ssf_press_joystick(context, 0, 0, delay, hold, cool);
253+
ssf_press_joystick(context, {-1, +1}, delay, hold, cool);
208254
break;
209255
default:;
210256
}

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ void ssf_press_left_joystick(
5151
uint8_t x, uint8_t y,
5252
Milliseconds delay, Milliseconds hold, Milliseconds cool = 0ms
5353
);
54+
void ssf_press_left_joystick(
55+
ProControllerContext& context,
56+
const JoystickPosition& position,
57+
Milliseconds delay, Milliseconds hold, Milliseconds cool = 0ms
58+
);
5459
void ssf_press_right_joystick(
5560
ProControllerContext& context,
5661
uint8_t x, uint8_t y,
@@ -61,6 +66,11 @@ void ssf_press_right_joystick(
6166
uint8_t x, uint8_t y,
6267
Milliseconds delay, Milliseconds hold, Milliseconds cool = 0ms
6368
);
69+
void ssf_press_right_joystick(
70+
ProControllerContext& context,
71+
const JoystickPosition& position,
72+
Milliseconds delay, Milliseconds hold, Milliseconds cool = 0ms
73+
);
6474

6575

6676
void ssf_mash1_button (ProControllerContext& context, Button button, uint16_t ticks);
@@ -184,6 +194,11 @@ void ssf_press_joystick(
184194
uint8_t x, uint8_t y,
185195
Milliseconds delay, Milliseconds hold, Milliseconds cool = 0ms
186196
);
197+
void ssf_press_joystick(
198+
JoyconContext& context,
199+
const JoystickPosition& position,
200+
Milliseconds delay, Milliseconds hold, Milliseconds cool = 0ms
201+
);
187202
void ssf_mash1_button (JoyconContext& context, Button button, Milliseconds duration);
188203
void ssf_issue_scroll(
189204
JoyconContext& context,

0 commit comments

Comments
 (0)