Skip to content

Commit

Permalink
Migrate more SwSh programs to TimeDurationOption.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Feb 5, 2025
1 parent 5636633 commit 669e4d3
Show file tree
Hide file tree
Showing 46 changed files with 272 additions and 316 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "Common/Microcontroller/DeviceRoutines.h"
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
#include "ClientSource/Libraries/MessageConverter.h"
#include "ClientSource/Connection/SerialConnection.h"
//#include "ClientSource/Connection/SerialConnection.h"
//#include "ClientSource/Connection/BotBase.h"
#include "ClientSource/Connection/PABotBase.h"
#include "CommonFramework/Globals.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ void eggfetcher_loop(SwitchControllerContext& context){
ssf_press_left_joystick(context, 192, STICK_MIN, 120, 120);
ssf_press_left_joystick(context, STICK_MAX, STICK_MIN, 120, 120);
}
void move_while_mashing_B(SwitchControllerContext& context, uint16_t duration){
void move_while_mashing_B(SwitchControllerContext& context, Milliseconds duration){
// Hold the joystick to the right for the entire duration.
ssf_press_left_joystick(context, STICK_MAX, STICK_CENTER, 0, duration);
ssf_press_left_joystick(context, STICK_MAX, STICK_CENTER, 0ms, duration);

// While the above is running, spam B.
ssf_mash1_button(context, BUTTON_B, duration);
}
void spin_and_mash_A(SwitchControllerContext& context, uint16_t duration){
for (uint16_t c = 0; c < duration; c += 128){
void spin_and_mash_A(SwitchControllerContext& context, Milliseconds duration){
for (Milliseconds c = 0ms; c < duration; c += 1024ms){
ssf_press_left_joystick(context, STICK_CENTER, STICK_MAX, 0, 32);
ssf_press_button(context, BUTTON_A, 16);
ssf_press_button(context, BUTTON_A, 16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace NintendoSwitch{


void eggfetcher_loop (SwitchControllerContext& context);
void move_while_mashing_B (SwitchControllerContext& context, uint16_t duration);
void spin_and_mash_A (SwitchControllerContext& context, uint16_t duration);
void move_while_mashing_B (SwitchControllerContext& context, Milliseconds duration);
void spin_and_mash_A (SwitchControllerContext& context, Milliseconds duration);
void travel_to_spin_location(SwitchControllerContext& context);
void travel_back_to_lady (SwitchControllerContext& context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ BeamSetter::BeamSetter(ProgramEnvironment& /*env*/, VideoStream& stream, SwitchC

BeamSetter::Detection BeamSetter::run(
bool save_screenshot,
uint16_t timeout_ticks,
Milliseconds timeout,
double min_brightness,
double min_euclidean,
double min_delta_ratio,
Expand Down Expand Up @@ -77,10 +77,7 @@ BeamSetter::Detection BeamSetter::run(
trackers.emplace_back(std::chrono::milliseconds(1000));
}

InferenceThrottler throttler(
std::chrono::milliseconds((uint64_t)timeout_ticks * 1000 / TICKS_PER_SECOND),
std::chrono::milliseconds(50)
);
InferenceThrottler throttler(timeout, std::chrono::milliseconds(50));

VideoSnapshot last_screenshot = baseline_image;
do{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BeamSetter{

Detection run(
bool save_screenshot,
uint16_t timeout_ticks,
Milliseconds timeout,
double min_brightness,
double min_euclidean,
double min_delta_ratio,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@ LotoFarmer::LotoFarmer()
LockMode::LOCK_WHILE_RUNNING,
100000
)
, MASH_B_DURATION(
, MASH_B_DURATION0(
"<b>Mash B for this long to exit the dialog:</b><br>(Some languages like German need to increase this.)",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"9 * TICKS_PER_SECOND"
"9000 ms"
)
, NOTIFICATIONS({
&NOTIFICATION_PROGRAM_FINISH,
})
{
PA_ADD_OPTION(START_LOCATION);
PA_ADD_OPTION(SKIPS);
PA_ADD_OPTION(MASH_B_DURATION);
PA_ADD_OPTION(MASH_B_DURATION0);
PA_ADD_OPTION(NOTIFICATIONS);
}

Expand All @@ -73,7 +72,7 @@ void LotoFarmer::program(SingleSwitchProgramEnvironment& env, SwitchControllerCo
pbf_press_button(context, BUTTON_B, 10, 70);
pbf_press_dpad(context, DPAD_DOWN, 10, 5);
pbf_mash_button(context, BUTTON_ZL, 490);
pbf_mash_button(context, BUTTON_B, MASH_B_DURATION);
pbf_mash_button(context, BUTTON_B, MASH_B_DURATION0);

// Tap HOME and quickly spam B. The B spamming ensures that we don't
// accidentally update the system if the system update window pops up.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define PokemonAutomation_PokemonSwSh_LotoFarmer_H

#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "Common/Cpp/Options/TimeExpressionOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "NintendoSwitch/Options/NintendoSwitch_StartInGripMenuOption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
Expand All @@ -35,7 +35,7 @@ class LotoFarmer : public SingleSwitchProgramInstance{
StartInGripOrGameOption START_LOCATION;

SimpleIntegerOption<uint32_t> SKIPS;
TimeExpressionOption<uint16_t> MASH_B_DURATION;
MillisecondsOption MASH_B_DURATION0;

EventNotificationsOption NOTIFICATIONS;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ PokeJobsFarmer::PokeJobsFarmer()
, m_advanced_options(
"<font size=4><b>Advanced Options:</b> You should not need to touch anything below here.</font>"
)
, MASH_B_DURATION(
, MASH_B_DURATION0(
"<b>Mash B for this long upon completion of " + STRING_POKEJOB + ":</b>",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"8 * TICKS_PER_SECOND"
"8000 ms"
)
, NOTIFICATIONS({
&NOTIFICATION_PROGRAM_FINISH,
Expand All @@ -64,7 +63,7 @@ PokeJobsFarmer::PokeJobsFarmer()
PA_ADD_OPTION(CONCURRENCY);
PA_ADD_OPTION(MENU_INDEX);
PA_ADD_STATIC(m_advanced_options);
PA_ADD_OPTION(MASH_B_DURATION);
PA_ADD_OPTION(MASH_B_DURATION0);
PA_ADD_OPTION(NOTIFICATIONS);
}

Expand All @@ -84,7 +83,7 @@ void PokeJobsFarmer::program(SingleSwitchProgramEnvironment& env, SwitchControll
uint8_t year = MAX_YEAR;

// Play it safe in case some menu is open
pbf_mash_button(context, BUTTON_B, MASH_B_DURATION);
pbf_mash_button(context, BUTTON_B, MASH_B_DURATION0);

for (uint32_t c = 0; c < SKIPS; c++)
{
Expand All @@ -95,7 +94,7 @@ void PokeJobsFarmer::program(SingleSwitchProgramEnvironment& env, SwitchControll
pbf_press_button(context, BUTTON_B, 5, 5);
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY_FAST0);
home_roll_date_enter_game_autorollback(env.console, context, year);
pbf_mash_button(context, BUTTON_B, MASH_B_DURATION);
pbf_mash_button(context, BUTTON_B, MASH_B_DURATION0);

// Get rid of new jobs notification by entering Poke Jobs and leaving immediately
enter_jobs(context, MENU_INDEX);
Expand Down Expand Up @@ -161,7 +160,7 @@ void PokeJobsFarmer::program(SingleSwitchProgramEnvironment& env, SwitchControll

// Skip through wall of text and exit
env.log("#### Exit " + STRING_POKEJOB + "s");
pbf_mash_button(context, BUTTON_B, MASH_B_DURATION);
pbf_mash_button(context, BUTTON_B, MASH_B_DURATION0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "Common/Cpp/Options/TimeExpressionOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "NintendoSwitch/Options/NintendoSwitch_StartInGripMenuOption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
Expand Down Expand Up @@ -39,7 +39,7 @@ class PokeJobsFarmer : public SingleSwitchProgramInstance{

SectionDividerOption m_advanced_options;

TimeExpressionOption<uint16_t> MASH_B_DURATION;
MillisecondsOption MASH_B_DURATION0;

EventNotificationsOption NOTIFICATIONS;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ WattFarmer_Descriptor::WattFarmer_Descriptor()


WattFarmer::WattFarmer()
: GRIP_MENU_WAIT(
: GRIP_MENU_WAIT0(
"<b>Exit Grip Menu Delay:</b> "
"Wait this long after leaving the grip menu to allow for the Switch to reestablish local connection.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"5 * TICKS_PER_SECOND"
"5000 ms"
)
, EXIT_DEN_WAIT(
"<b>Exit Den Wait Time:</b> "
Expand Down Expand Up @@ -70,7 +69,7 @@ WattFarmer::WattFarmer()
void WattFarmer::program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){
if (START_LOCATION.start_in_grip_menu()){
grip_menu_connect_go_home(context);
pbf_wait(context, GRIP_MENU_WAIT);
pbf_wait(context, GRIP_MENU_WAIT0);
}else{
pbf_press_button(context, BUTTON_B, 5, 5);
pbf_press_button(context, BUTTON_HOME, 80ms, GameSettings::instance().GAME_TO_HOME_DELAY_FAST0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "Common/Cpp/Options/SimpleIntegerOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "Common/Cpp/Options/TimeExpressionOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "NintendoSwitch/Options/NintendoSwitch_StartInGripMenuOption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
Expand All @@ -34,7 +34,7 @@ class WattFarmer : public SingleSwitchProgramInstance{

private:
StartInGripOrGameOption START_LOCATION;
TimeExpressionOption<uint16_t> GRIP_MENU_WAIT;
MillisecondsOption GRIP_MENU_WAIT0;
MillisecondsOption EXIT_DEN_WAIT;

SimpleIntegerOption<uint32_t> SKIPS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ BeamReset_Descriptor::BeamReset_Descriptor()


BeamReset::BeamReset()
: DELAY_BEFORE_RESET(
: DELAY_BEFORE_RESET0(
"<b>Delay before Reset:</b>",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"5 * TICKS_PER_SECOND"
"5000 ms"
)
, EXTRA_LINE(
"<b>Extra Line:</b><br>(German has an extra line of text.)",
Expand All @@ -45,7 +44,7 @@ BeamReset::BeamReset()
)
{
PA_ADD_OPTION(START_LOCATION);
PA_ADD_OPTION(DELAY_BEFORE_RESET);
PA_ADD_OPTION(DELAY_BEFORE_RESET0);
PA_ADD_OPTION(EXTRA_LINE);
}

Expand Down Expand Up @@ -73,7 +72,7 @@ void BeamReset::program(SingleSwitchProgramEnvironment& env, SwitchControllerCon
pbf_press_button(context, BUTTON_HOME, 10, 10);
pbf_press_button(context, BUTTON_HOME, 10, 220);
}
pbf_wait(context, DELAY_BEFORE_RESET);
pbf_wait(context, DELAY_BEFORE_RESET0);

reset_game_from_home(env.console, context, ConsoleSettings::instance().TOLERATE_SYSTEM_UPDATE_MENU_SLOW);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define PokemonAutomation_PokemonSwSh_BeamReset_H

#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/TimeExpressionOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "NintendoSwitch/Options/NintendoSwitch_StartInGripMenuOption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"

Expand All @@ -33,7 +33,7 @@ class BeamReset : public SingleSwitchProgramInstance{
private:
StartInGripOrGameOption START_LOCATION;

TimeExpressionOption<uint16_t> DELAY_BEFORE_RESET;
MillisecondsOption DELAY_BEFORE_RESET0;
BooleanCheckBoxOption EXTRA_LINE;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ EventBeamFinder_Descriptor::EventBeamFinder_Descriptor()


EventBeamFinder::EventBeamFinder()
: WAIT_TIME_IN_DEN(
: WAIT_TIME_IN_DEN0(
"<b>Wait time in Den:</b>",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"5 * TICKS_PER_SECOND"
"5800 ms"
)
{
PA_ADD_OPTION(START_LOCATION);
PA_ADD_OPTION(WAIT_TIME_IN_DEN);
PA_ADD_OPTION(WAIT_TIME_IN_DEN0);
}


Expand All @@ -64,11 +63,11 @@ void EventBeamFinder::goto_far_den(SwitchControllerContext& context) const{
ssf_hold_joystick1(context, true, STICK_CENTER, STICK_MIN, 300);
}
void EventBeamFinder::drop_wishing_piece(SwitchControllerContext& context) const{
ssf_press_button2(context, BUTTON_A, 200, 10);
ssf_press_button2(context, BUTTON_A, 150, 10);
ssf_press_button1(context, BUTTON_A, 5);
ssf_press_button(context, BUTTON_A, 200, 10);
ssf_press_button(context, BUTTON_A, 150, 10);
ssf_press_button(context, BUTTON_A, 5);
pbf_mash_button(context, BUTTON_B, 500);
ssf_press_button2(context, BUTTON_A, WAIT_TIME_IN_DEN + 100, 10);
ssf_press_button(context, BUTTON_A, WAIT_TIME_IN_DEN0, 80ms);
pbf_mash_button(context, BUTTON_B, 600);
}
void EventBeamFinder::program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef PokemonAutomation_PokemonSwSh_EventBeamFinder_H
#define PokemonAutomation_PokemonSwSh_EventBeamFinder_H

#include "Common/Cpp/Options/TimeExpressionOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "NintendoSwitch/Options/NintendoSwitch_StartInGripMenuOption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"

Expand Down Expand Up @@ -36,7 +36,7 @@ class EventBeamFinder : public SingleSwitchProgramInstance{
private:
StartInGripOrGameOption START_LOCATION;

TimeExpressionOption<uint16_t> WAIT_TIME_IN_DEN;
MillisecondsOption WAIT_TIME_IN_DEN0;
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ PurpleBeamFinder::PurpleBeamFinder()
LockMode::LOCK_WHILE_RUNNING,
false
)
, TIMEOUT_DELAY(
, TIMEOUT_DELAY0(
"<b>Timeout Delay:</b><br>Reset if no beam is detected after this long.",
LockMode::LOCK_WHILE_RUNNING,
TICKS_PER_SECOND,
"2 * TICKS_PER_SECOND"
"2000 ms"
)
// , MAX_STDDEV(
// "<b>Maximum Standard Deviation:</b><br>Range: 0 - 768",
Expand Down Expand Up @@ -121,7 +120,7 @@ PurpleBeamFinder::PurpleBeamFinder()
PA_ADD_OPTION(NOTIFICATIONS);
if (PreloadSettings::instance().DEVELOPER_MODE){
PA_ADD_STATIC(m_advanced_options);
PA_ADD_OPTION(TIMEOUT_DELAY);
PA_ADD_OPTION(TIMEOUT_DELAY0);
PA_ADD_OPTION(MIN_BRIGHTNESS);
PA_ADD_OPTION(MIN_EUCLIDEAN);
PA_ADD_OPTION(MIN_DELTA_STDDEV_RATIO);
Expand Down Expand Up @@ -173,7 +172,7 @@ bool PurpleBeamFinder::run(SingleSwitchProgramEnvironment& env, SwitchController
BeamSetter setter(env, env.console, context);
detection = setter.run(
SAVE_SCREENSHOT,
TIMEOUT_DELAY,
TIMEOUT_DELAY0,
MIN_BRIGHTNESS,
MIN_EUCLIDEAN,
MIN_DELTA_STDDEV_RATIO,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "Common/Cpp/Options/StaticTextOption.h"
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
#include "Common/Cpp/Options/FloatingPointOption.h"
#include "Common/Cpp/Options/TimeExpressionOption.h"
#include "Common/Cpp/Options/TimeDurationOption.h"
#include "CommonFramework/Notifications/EventNotificationsTable.h"
#include "NintendoSwitch/Options/NintendoSwitch_StartInGripMenuOption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
Expand Down Expand Up @@ -47,7 +47,7 @@ class PurpleBeamFinder : public SingleSwitchProgramInstance{

SectionDividerOption m_advanced_options;
BooleanCheckBoxOption SAVE_SCREENSHOT;
TimeExpressionOption<uint16_t> TIMEOUT_DELAY;
MillisecondsOption TIMEOUT_DELAY0;
// FloatingPoint MAX_STDDEV;
FloatingPointOption MIN_BRIGHTNESS;
FloatingPointOption MIN_EUCLIDEAN;
Expand Down
Loading

0 comments on commit 669e4d3

Please sign in to comment.