Skip to content

Commit 46942f7

Browse files
committed
Allow mashing timing parameters to be specified.
1 parent 5f44ba2 commit 46942f7

10 files changed

+42
-18
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ class JoyconController : public AbstractController{
160160
// Mash a button as quickly as possible.
161161
virtual void issue_mash_button(
162162
Cancellable* cancellable,
163-
Button button, Milliseconds duration
163+
Button button,
164+
Milliseconds duration,
165+
Milliseconds delay = Milliseconds(64),
166+
Milliseconds hold = Milliseconds(40),
167+
Milliseconds cooldown = Milliseconds(24)
164168
) = 0;
165169

166170

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,18 @@ void ControllerWithScheduler::issue_full_controller_state(
268268
void ControllerWithScheduler::issue_mash_button(
269269
Cancellable* cancellable,
270270
Milliseconds duration,
271-
Button button
271+
Button button,
272+
Milliseconds delay,
273+
Milliseconds hold,
274+
Milliseconds cooldown
272275
){
273276
if (cancellable){
274277
cancellable->throw_if_cancelled();
275278
}
276279
ThrottleScope scope(m_logging_throttler);
277280
bool log = true;
278281
while (duration > Milliseconds::zero()){
279-
issue_buttons(cancellable, 8*8ms, 5*8ms, 3*8ms, button);
282+
issue_buttons(cancellable, delay, hold, cooldown, button);
280283

281284
// We never log before the first issue to avoid delaying the critical path.
282285
// But we do want to log before the mash spam. So we log after the first
@@ -290,8 +293,9 @@ void ControllerWithScheduler::issue_mash_button(
290293
}
291294
log = false;
292295

293-
duration = duration >= 8*8ms
294-
? duration - 8*8ms
296+
Milliseconds elapsed = std::max(delay, hold + cooldown);
297+
duration = duration >= elapsed
298+
? duration - elapsed
295299
: Milliseconds::zero();
296300
}
297301
}

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ class ControllerWithScheduler : public PokemonAutomation::ControllerWithSchedule
264264
void issue_mash_button(
265265
Cancellable* cancellable,
266266
Milliseconds duration,
267-
Button button
267+
Button button,
268+
Milliseconds delay,
269+
Milliseconds hold,
270+
Milliseconds cooldown
268271
);
269272
void issue_mash_button(
270273
Cancellable* cancellable,

SerialPrograms/Source/NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ class ProController : public AbstractController{
182182
virtual void issue_mash_button(
183183
Cancellable* cancellable,
184184
Milliseconds duration,
185-
Button button
185+
Button button,
186+
Milliseconds delay = Milliseconds(64),
187+
Milliseconds hold = Milliseconds(40),
188+
Milliseconds cooldown = Milliseconds(24)
186189
) = 0;
187190

188191
// Alternate pressing "button0" and "button1" as quickly as possible.

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Joycon.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ void SerialPABotBase_Joycon<JoyconType>::issue_full_controller_state(
147147
template <typename JoyconType>
148148
void SerialPABotBase_Joycon<JoyconType>::issue_mash_button(
149149
Cancellable* cancellable,
150-
Button button, Milliseconds duration
150+
Button button, Milliseconds duration,
151+
Milliseconds delay,
152+
Milliseconds hold,
153+
Milliseconds cooldown
151154
){
152155
button &= m_valid_buttons;
153-
ControllerWithScheduler::issue_mash_button(cancellable, duration, button);
156+
ControllerWithScheduler::issue_mash_button(cancellable, duration, button, delay, hold, cooldown);
154157
}
155158

156159

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_Joycon.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ class SerialPABotBase_Joycon :
154154

155155
virtual void issue_mash_button(
156156
Cancellable* cancellable,
157-
Button button, Milliseconds duration
157+
Button button, Milliseconds duration,
158+
Milliseconds delay,
159+
Milliseconds hold,
160+
Milliseconds cooldown
158161
) override;
159162

160163

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_ProController.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ class SerialPABotBase_ProController final :
182182
virtual void issue_mash_button(
183183
Cancellable* cancellable,
184184
Milliseconds duration,
185-
Button button
185+
Button button,
186+
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
186187
) override{
187-
ControllerWithScheduler::issue_mash_button(cancellable, duration, button);
188+
ControllerWithScheduler::issue_mash_button(cancellable, duration, button, delay, hold, cooldown);
188189
}
189190
virtual void issue_mash_button(
190191
Cancellable* cancellable,

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WiredController.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ class SerialPABotBase_WiredController final :
188188
virtual void issue_mash_button(
189189
Cancellable* cancellable,
190190
Milliseconds duration,
191-
Button button
191+
Button button,
192+
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
192193
) override{
193194
button &= VALID_PRO_CONTROLLER_BUTTONS;
194-
ControllerWithScheduler::issue_mash_button(cancellable, duration, button);
195+
ControllerWithScheduler::issue_mash_button(cancellable, duration, button, delay, hold, cooldown);
195196
}
196197
virtual void issue_mash_button(
197198
Cancellable* cancellable,

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase3_ProController.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ class ProController_SysbotBase3 final :
176176
virtual void issue_mash_button(
177177
Cancellable* cancellable,
178178
Milliseconds duration,
179-
Button button
179+
Button button,
180+
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
180181
) override{
181-
ControllerWithScheduler::issue_mash_button(cancellable, duration, button);
182+
ControllerWithScheduler::issue_mash_button(cancellable, duration, button, delay, hold, cooldown);
182183
}
183184
virtual void issue_mash_button(
184185
Cancellable* cancellable,

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_ProController.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ class ProController_SysbotBase final :
192192
virtual void issue_mash_button(
193193
Cancellable* cancellable,
194194
Milliseconds duration,
195-
Button button
195+
Button button,
196+
Milliseconds delay, Milliseconds hold, Milliseconds cooldown
196197
) override{
197-
ControllerWithScheduler::issue_mash_button(cancellable, duration, button);
198+
ControllerWithScheduler::issue_mash_button(cancellable, duration, button, delay, hold, cooldown);
198199
}
199200
virtual void issue_mash_button(
200201
Cancellable* cancellable,

0 commit comments

Comments
 (0)